Icon for parent category 'Writing'

Figures & Images

We’ve already seen the table environment. It does nothing more than contain a table and any metadata, such as a caption or reference.

Its (very) similar ally is the figure environment. It signals LaTeX that any type of figure is to come—an image, mathematical graphic, even a table if you want. In many ways, it’s like tables where the younger sister, and figures are the mother of all things that aren’t just paragraphs of text 👨‍👩‍👧

The syntax is

1\begin{figure}[position]
2    % ... your figure ...
3    \caption{theCaption} 
4\end{figure}

Images

Again, TeX shows its age. It was created mainly for typesetting text, way before computer images were a big deal, so they aren’t supported by default. To use them, include the graphicx package.

Then, including any graphics is exactly as you’d expect:

1\includegraphics[parameters]{linkToFile}

Links can be relative (someFile.jpg), which searches for other images within the same folder as the TeX document.

They can also be absolute (C:\Users\John\someFile.jpg), which search from the root of your device.

There are four supported image types: .png, .jpg, .pdf, .eps. The parameters can be used to scale and/or crop the image. Try these properties:

SpecifierDescription
widthSpecifies the width
heightSpecifies the height
scaleSpecifies the scale with a factor, default is 1.0.

For example, 0.5 means half the original size.
angleSpecify the amount of degrees to rotate the image
trimTakes four values, which represent the length to trim from the left, bottom, right and top side, respectively.
clipNeeds to be set to true for the trim option to work
pageIf your graphic is a pdf file, you can specify which page to display.
 1\usepackage{graphicx}
 2
 3\begin{document} Lorem ipsum Uno
 4    \begin{figure}
 5        \includegraphics[width=0.25\textwidth]{ProfPanda.png}
 6    \end{figure}
 7    
 8    Lorem ipsum Duo
 9    \begin{figure}[h]
10        \includegraphics[width=0.25\textwidth]{ProfPanda.png}
11    \end{figure}
12\end{document}
Code left > output right
Code left > output right
Remark

If you only specify a width or height, the other dimension scales accordingly to keep the aspect ratio the same.

Wrapping Text around Figures

The regular figure environment adds line breaks before and after the graphic. If you want text (and other environments) to nicely wrap around it, include the wrapfig package.

Use a special environment:

1\begin{wrapfigure}[lineHeight]{position}{width}

The width is, obviously, the width of the figure. The position has eight possible values:

Specifier ISpecifier IIDescription
rRRight side of the text
lLLeft side of the text
iIInside edge (in a twosided document)
oOOutside edge (in a twosided document)

The uppercase versions allow LaTeX to float the figure to the best place—they are merely suggestions. The lowercase versions force it to follow whatever you specified.

The optional lineHeight argument accepts any positive integer. It will set the figure’s height relative to your font size. For example, lineHeight 2 means it’s the same length as the height of two lines of text.

 1\usepackage{graphicx}
 2\usepackage{wrapfig}
 3
 4\begin{document} 
 5Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi non arcu pulvinar, mattis diam sed, tempus velit. Proin et faucibus sapien, eu vehicula lorem. Fusce consequat diam ac urna ullamcorper, sodales pharetra eros accumsan. 
 6
 7\begin{wrapfigure}{r}{220pt}
 8    \caption{What?! I don't see anything!?}
 9\end{wrapfigure} 
10
11Maecenas accumsan tellus eu erat molestie, eget sollicitudin sem volutpat. Morbi vel nisi vel magna consectetur pellentesque. Pellentesque in orci id urna luctus ornare. Praesent nisi nulla, congue et molestie vel, molestie in est.
12\end{document}
Code above > output below
Code above > output below

Side Caption

So far, captions could be placed either above or below the figure. If you want them to the side of the graphic, include the sidecap package and the SCfigure environment.

 1\usepackage{graphicx}
 2\usepackage{sidecap}
 3
 4\begin{document} 
 5Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi non arcu pulvinar, mattis diam sed, tempus velit. Proin et faucibus sapien, eu vehicula lorem. Fusce consequat diam ac urna ullamcorper, sodales pharetra eros accumsan. 
 6
 7\begin{SCfigure}
 8    \includegraphics[scale=0.25]{ProfPanda.png}
 9    \caption{Oh noes, a wild panda! Did you know, that pandas don't even like bamboo, but just eat it anyway?}
10\end{SCfigure} 
11
12Maecenas accumsan tellus eu erat molestie, eget sollicitudin sem volutpat. Morbi vel nisi vel magna consectetur pellentesque. Pellentesque in orci id urna luctus ornare. Praesent nisi nulla, congue et molestie vel, molestie in est.
13\end{document}
Code above > output below
Code above > output below

Minipage

Minipages are environments that, unsurprisingly, contain a “mini page”. These are completely separated from the overall document. Like a small page from another book that you just inserted here.

This is useful for creating complex layouts, such as lots of images next to each other, without breakig the overall flow of your document. This is possible, because minipages scale to the size of whatever’s inside, and don’t insert any white space or line breaks around it.

To create one, use

1\begin{minipage}[position]{width}
2    % ... whatever you want inside ...
3\end{minipage}
 1\begin{minipage}[t]{0.5\textwidth}
 2    \centering
 3    \includegraphics[width=0.5\textwidth]{ProfPanda.png}\
 4    Panda Uno
 5\end{minipage}
 6
 7\begin{minipage}[t]{0.5\textwidth}
 8    \centering
 9    \includegraphics[width=0.5\textwidth]{ProfPanda.png}\
10    Panda Duo
11\end{minipage}
Code left > output right
Code left > output right
Remark

It might be a fun exercise to recreate the wrapfigure and sidecaption environments using minipages. Or that might sound like the most frightening task ever, in which case, forget it and continue!

Continue with this course
Support me and this website!

Want to support me?

Buy one of my projects. You get something nice, I get something nice.

Donate through a popular platform using the link below.

Simply giving feedback or spreading the word is also worth a lot.