Ceci est une ancienne révision du document !
In our last issue, we looked at adding some basic images to a document. Just like in sections and subsections, we can have sub images, (or tables or diagrams), such as figure 1 followed by figure 1.1, and be able to reference that. These also require the graphicx pre-processor as well as a new one, subcaption.
Let us start by adding that to our file from last time. Just below: \usepackage{graphicx} add another line: \usepackage{subcaption}
Since we have told the computer which package we wish to use, we can now go ahead and use it. The catch with this subcaption is that you need to specify the space you want to take up, beforehand. You also need to remember that it is a nested command. This means that the new image / subfigure is encapsulated by a figure. What does this look like? My file is named “you.png” in my “Figures” folder (code shown top right).
Now build and view. What went wrong? In our last bout, we added square brackets after \begin{figure}[p], to specify placement, but, in subfigures, we use curly braces to specify the size.
Change that first line to:
\begin{subfigure}{0.25\textwidth}
Build and view.
Hey! Look at you, already going at it like a pro! (F5)
Again, you have to remember that if you have no text, using textwidth or textheight will net you a big fat zero on a contract and your image will not scale. Let’s see how that works?
OK, before we do that, I want to introduce you to a package called lipsum. All it does is create lorem ipsum dummy text. It just saves me from typing it all out to demonstrate something that is related to text. Nothing funny. See: https://blog.chapagain.com.np/latex-generate-dummy-text-lorem-ipsum-in-your-document/
As this is becoming a lot of code, clear it all up to the pre-processor part (this is for simplicity’s sake, nothing else).
So our code will look like that shown on the previous page, bottom right.
You will notice I added the lipsum package and added my dummy text. Press F5 and your output should look like this: Now we can demonstrate figures that relate to the size of the text.
Now for your challenge: add a figure after the last /lipsum.
Did you manage? Great! If you didn’t, go back to the previous issue and redo the lesson, practise makes perfect!
Now, let’s wrangle our image down to size. How do we do that? The dropdown in TeXstudio gives you this: \includegraphics[keyvals]{imagefile}
Your attention should be on those “keyvals” key values. Clear it out and type a “w” and width will be one of the options, choose that. To make your image nestle in perfectly, set your width to your line width. (It should pop up in the IDE)
Now compile it and look at your output. Here is mine:
Does your line match mine?
\includegraphics[width=\linewidth]{Figures/you}
Well Done! At any time, hover your mouse over different words in that line, if you use TeXstudio, you should see a tooltip. In the case of the image file, you should see the image. As you can see, my image aligns perfectly with my column. Sometimes, you don’t need all that, or your space may be limited. You can specify the width and height as per issue 3 of our tutorial, last month. Try it now. This whole series is a hands-on affair. If you don’t do it, you will not remember it by the time the next issue hits your inbox.
No seriously, I want you to try, as there is nothing as good as understanding, because then you don’t have to learn anything. Do something fun. Stretch the image vertically and have a laugh at how terrible it looks. If your image is a rectangle, change it to a square and vice-versa. Ever wonder how those angled warning signs are put down in some technical books? Wonder no more! You can specify the angle at which your image is presented on the paper. With the keyword, “angle”. Try angle=25 or angle=-75 and see what you have created. Again, the little modifier after \begin{figure} is valid. Do you remember what it was? No, read part three again. I kept the parts short for just this reference purpose. Remember, you can add labels and captions in this layout as well. So what happens if we need our figure to span both columns? Simply add a ‘*’ after the word figure. Then it will look like this:
\begin{figure*}
\includegraphics[width=\linewidth]{Figures/you}
\end{figure*}
Baby steps, this is not the easiest thing to learn, but now you know a little more and every bit counts! Did you notice that I slipped something else into this tutorial, without explaining it (it is self-explanatory). See if you can find it.
So now you know something more about graphics and their placement. Next issue we will touch on other types of graphics before moving on.
Did I make a mistake? Do you have any questions? E-mail us at: misc@fullcirclemagazine.org