Ceci est une ancienne révision du document !
You may ask, “Why another Latex tutorial when there are so many Youtube videos?” And my answer would be, after watching countless outdated videos that were badly planned and badly executed and gave me no answers, THIS tutorial was born. I am no expert, this is what I wish the tutorials actually taught me. When it comes to typesetting, LaTeX is the undisputed champ. It outweighs its opponents in the sheer number of options alone. At first, LaTeX is a bit confusing and difficult to use. Not to scare you, but I suggest looking here: http://tug.ctan.org/info/symbols/comprehensive/symbols-a4.pdf
Last issue, we explored more basic concepts, one of them was tagging with labels. We can dive into the nuances of fonts and columns if there is interest, but for now, we soldier on. If you recall, we spoke about tagging your images with fig:2 or whatever, but instead of a figure, we tagged a section. The reason was that I wanted to further explore the issue of images and common mistakes in a totally separate tutorial. Place your cursor on a new line and this time go to the “wizards” menu item and choose: insert graphic. Follow the prompts to get your ‘code’ filled in for you. Compile (F6)… What went wrong? Should a wizard not just work? You are welcome to google/duckduckgo the error. I’ll wait… Now you would understand the reason for this tutorial first hand. I will also cover – let you do/make – more common mistakes newbies make.
Explanation: Latex is very “geeky”. It is like a programming language. You cannot use graphics (or other add-ons, we will get to those) without telling Latex that you will be using graphics. It has to be in the pre-processor space too, not anywhere else – that is where all the backslash stuff, written in red, is, before your “/begin{document}” is located at the top. Adding this line, after the documentclass: \usepackage[demo]{graphicx} will clear the error, but not solve the problem. The wizard will automatically use the picture’s name as a label, so you can save yourself a lot of time by changing the names of your pictures beforehand. However, I have no picture of snoopy displayed (I used a picture of snoopy). Instead I have a black block. This is the “demo”.
Go back, remove the “[demo]” from that line, and use the wizard again. When you compile your document, you will be greeted by a new error. TL;DR – you need to specify a path to a directory that has your images. The full path in the \includegraphics{} statement does not work. *(Even when they say so.) This also has to be added in the pre-processor space at the top. Here again, I was met with frustration, as the “beginners guide to Latex” does not even mention it in chapter Five (Inserting images). This just goes to show you that there are so many things you need to keep track of, that even the experts miss things. Even definitive sources, see here: https://www.latex-tutorial.com/tutorials/figures/. Copy that code and see if it will work (spoiler: It won’t). TIP: When using images in your Latex documents, I suggest you make a separate folder for them.
Check the type of image you are adding as currently it can be only a .png, a .jpg, or a .pdf file. Deep breath, we will get there. Sometimes one needs to make mistakes to understand your subject better. Now you can understand my frustration at other tutorials that just do not work. Open your file browser and navigate to the picture you would like to insert. Click and drag it into TeXstudio. You will now see this: \begin{figure} \includegraphics{Figures/me} \caption{} \label{fig:me} \end{figure} This is why I recommend making a “Figures” folder in your current working folder and dumping your pictures there. This used to trip me up when I was trying to get to grips with LaTeX. Now that you have made the mistake with me, hopefully this will stick.
Now, when you click on run, you should see “Process exited normally”, and the preview should contain your picture. In my case I just included a selfie, but you can add any image that pleases you. (Does the image make my feet look big?). Depending on the size of your image, if you do not supply any options, the image will be all over the place, even off the page. Now again, as we learned with the \documentclass example, the options go before the curly braces in square brackets. It is always a good idea to use a larger image than needed as it will show in the end product’s quality. We can restrain our image thus: Inside your square brackets, type “w” and the word “width=” should appear with two of the most common options. Choose “linewidth” and hit F5.
What happened to your image? We have no lines in our document yet, so our line width is 0. This is another common mistake you need to watch out for. Hover your mouse cursor over the word “linewidth” and read the tool tip carefully. So how would we wrangle our image to a more manageable size? We simply specify the height and width in centimetres. Add the following to the square brackets and press F5 again: height= 3cm,width=3cm Looking better already! Another popular option is angle. This can be a positive or negative integer. Since you are reading FCM, I have no doubt you know how angles work, so I will leave that to you to play with.
My image is currently at the top, what if I want it at the bottom? Right next to \begin{figure} simply add a [b] thus: \begin{figure}[b] \includegraphics[height= 3cm,width=3cm]{Figures/me} \caption{It's a ME!} \label{fig:me} \end{figure} This will put your image at the bottom of the page (NOT at the end of your text). If you want it at the end of the text, you need to use an [h]. If you want the image on its own page, you need to specify the [p] option. You may have noticed that I added a caption and a label. By default, if you drag the image in, it will use the name of the file in here, be sure to change it to something useful.
Add a section and copy the following code to reference your image (as you type /ref{ TeXstudio should fill in the image reference for you). \section A As you can see in the figure \ref{fig:me} that I have gained weight. Press F5 again to see your handy work. It is now easy to refer to any image by its label in this way. I hope you learned something not only by copying my code, but also by making mistakes. Join us in the next issue for more LaTeX, where we will tackle more n00b stumbling blocks. If you have any comments or queries, email us: misc@fullcirclemagazine.org