I would like to place two figures side by side (not subfigures) and what’s more, I’d like to let the figures spill into the outer margin (since they are too wide for the the text width. Like this:
(Black lines delimit the page borders. Full page [pdf])
The following actually works very nicely:
\begin{figure}[h]
\setcapwidth{0.6\textwidth}
\begin{flushright}
\hspace{-\marginfigwidth}%
\begin{minipage}[t]{0.6\textwidth}
\centering
\includegraphics{gfx-1}
\caption{Caption 1}
\end{minipage}%
\hspace{1cm}%
\begin{minipage}[t]{0.6\textwidth}
\centering
\includegraphics{gfx-2}
\caption{Caption 2}
\label{fig:free-lunch}
\end{minipage}
\end{flushright}
\end{figure}
Unfortunately, there’s a snag: this only works on the left hand page, since I force it into the margin via \hspace{-\marginfigwidth}
command (where \marginfigwidth
is defined as \marginparwidth + \marginparsep
).
I can’t wrap my head around how this must be changed to work on all pages. If I just remove the negative hspace
on a right-hand page, the page will automatically break. I can of course wrap the whole thing into yet another minipage
but this doesn’t work since it won’t respect the specified \hspace
between the figures and spill over the page border.
The wrapfigure
environment doesn’t help me either since that is designed to work with single pictures only.
How can I make this code work independent of the page (left/right) so that it always spills into the outer margin?
Best Answer
Use either the
ifoddpage
or thechangepage
package to check on which page the figure is. It needs twolatex
runs to determine the correct page number. If thechangepage
package is used it should be loaded with thestrict
option, because otherwise the used page number might not be correct in all cases (when TeX reads more material to look for a page break etc.). Alternatively the macro\strictpagecheck
can be placed before\checkoddpage
.The trick is to use
\makebox[\textwidth]
so that the box is officially only\textwidth
long which also avoids "Overfull hbox" errors. Then the second optional argument of\makebox
is used to align it either to the right or left:I have something like this as an example on my website. See also this TeX FAQ from where I got the idea.