2

I'm writing a document that has a lot of figures, and as a result is quickly growing in size. I want to bring the page count down if possible, and I'd like to do it by placing the figures side by side.

I know I can do it manually by using two minipages inside a figure, but I want latex to place them for me, since I don't really care what figures are placed side by side.

Setting width=0.45\textwidth made it smaller, but it didn't get the figures to go side by side, even without centering them.

Is there any way to set this up by default?

The environment I'm using:

\documentclass{article}

\usepackage{graphicx}

\begin{document}
    \begin{figure}[htbp]
        \includegraphics[width=0.45\textwidth]{example-image-a}
    \end{figure
\end{document}

I don't want someone to write code for me, I just need a starting point for where to look.

9
  • I don't understand how I can give a mwe for this, it's a conceptual question (as are a lot of the questions I ask and people ask for a mwe). If you really want one, then no I haven't tried anything because I don't know where to start. Commented Oct 15, 2017 at 16:29
  • You can use the subfigure environment from the subcaption package, if the figures side by side are to be considered as subfigures of a main figure. If they're supposed to be independent figures, there's the floatrow package.
    – Bernard
    Commented Oct 15, 2017 at 16:36
  • You mentioned in your question "Setting width=0.45\textwidth made it smaller, but it didn't get the figures to go side by side, even without centering them.". Can you create an MWE that reproduces this (ie. what you tried)? At the very least, give us a compilable document with example-images so it saves us some work.
    – Troy
    Commented Oct 15, 2017 at 16:36
  • I've added an example, however I don't want someone to go write code for me, I just wanted an idea where to start. I'm looking into floatrow now. Thank you Commented Oct 15, 2017 at 16:45
  • It seems that the question is about how merge two figure's environments in one (side by side).
    – touhami
    Commented Oct 15, 2017 at 16:45

1 Answer 1

2

Something like this, i.e., a macro named \twofigures?

enter image description here

\documentclass{article}
\usepackage{graphicx} % for "\includegraphics" macro
\usepackage{caption}

\newcommand\twofigures[6]{%
\begin{figure}[htbp]
\captionsetup{skip=0.5\baselineskip}
   \begin{minipage}{0.45\textwidth}
     \includegraphics[width=\textwidth]{#1}
     \caption{#2}\label{#3}
   \end{minipage}\hfill
   \begin{minipage}{0.45\textwidth}
     \includegraphics[width=\textwidth]{#4}
     \caption{#5}\label{#6}
   \end{minipage}
\end{figure}}

\begin{document}
\twofigures%
     {example-image-a}       % name of image file
     {Left-hand-side figure} % caption
     {fig:left}              % argument for "\label"
     {example-image-b}
     {Right-hand-side figure} 
     {fig:right}
\end{document}
3
  • This is nice, but I don't know if it's what I want (I don't think what I want is possible). The issue is that I still have to tell the macro which two figures I want. What I would like is to be able to place all my figures and just tell float that it's okay to place them side by side (kinda like an additional option to [htbp] Commented Oct 15, 2017 at 17:13
  • @BrydonGibson - I don't think that what you describe is possible, at least not without some very serious hacking of LaTeX's float-placement algorithm. For instance, the float-placement algorithm is designed to be "greedy", i.e., to always try to output the accumulated list of floats (which may contain just 1 float) as soon as it can, without looking ahead in the document to check if there's another float waiting to join the list. To begin with, then, one would have to provide a workable alternative to the "greedy" setup -- easier said than done, right?!
    – Mico
    Commented Oct 15, 2017 at 17:19
  • I didn't even think of that, and it's good point, so I guess without some serious work it can't be done, and it's not worth it for the application. Thanks for trying! Commented Oct 15, 2017 at 17:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .