DEV Community

latexteada
latexteada

Posted on • Updated on • Originally published at builtin.com

LaTeX More in figures: Side-by-Side Figures

Hello hello, how are you? :)

These days I have been writing about images in LaTeX, this is an important thing because you can just put an image to decorate your file or, for example, if you are working with some investigation you can put images to show the results of the analysis you did.

In this post I teach you how to import a simple image, and in this I teach you how to do more things with your image, like adding a caption. I suggest you read these before you start with this post because I use some commands which I have talked about them there

Today I write about Side-by-Side images

Side-by-Side Images

This is a very useful tool because you can contrast the differences in the images which you are using. Or just because you want to add multiple images.

This task is so easy to do, we just need to add the images in different includegraphics command inside the figure environment

Do not forget that you need the graphicx package imported in the preamble

Before the example, I want to tell you

  • The total width of all the figures must not exceed the page width. Otherwise, the figures will be inserted one below other
  • There must not be any line breaks between the includegraphics command

An example is
code

Produces

Screenshot from 2021-03-15 10-13-21

We can use \hfill to separate the figures by the available horizontal space

code

Produces

Screenshot from 2021-03-15 10-21-49

Maybe the difference is not so big, but, you can try with different sizes of images and you will notice the difference

That is how you can put side-by-side images in LaTeX, but did you notice?

There is just one caption for all the images you have put

Sometimes it could be good, but sometimes it is not good because you want to explain each image, and of course, there is a way to do it :)

The minipage environment

minipage as its name suggests is like if you have a mini page inside the page, you can configure its width and the content it will have

\begin{minipage}[position]{width}
content
\end{minipage}
Enter fullscreen mode Exit fullscreen mode

Where position could be

  • c center
  • t at the top
  • b at the bottom

And width can be

  • An explicit measure, for example, 3cm, 8cm
  • A portion of the width of the page, we can do it with X\linewidth where X is the percentage of the page, 0<X<1, for example, `0.5\linewidth* is the 50% of the page's width

An example

code

Produces

Screenshot from 2021-03-16 10-41-59

Images and minipage

If you want to add multiple images with a different caption, you need to put those in the minipage environment

Remember that you need to have the graphicx package imported

  • You can add a general caption, just before the \end{figure} command

An example
code

Produces
Screenshot from 2021-03-16 10-55-15

Thanks, that was all, do not forget to follow me on Twitter @latexteada

Top comments (0)