9

I'm using a quite satisfying solution for side by side independent caption figures, a solution by which images are sized automatically to same height and to text width, see MWE below.

\documentclass{article}
\usepackage{mwe}
\usepackage{floatrow}

\begin{document}
\blindtext

\begin{figure*}
\CommonHeightRow{\begin{floatrow}
\ffigbox[\FBwidth]{\includegraphics[height=\CommonHeight]{example-image-16x10}}{\caption{A caption.}\label{fig:01}}
\ffigbox[\FBwidth]{\includegraphics[height=\CommonHeight]{example-image-10x16}}{\caption{Another caption.}\label{fig:02}}
\end{floatrow}}
\end{figure*}

\blindtext
\end{document}

enter image description here

However sometimes I would like to limit the overall width of the two figures to something less (say 80%) than text width (retaining the uniform height), but I couldn't find a way to achieve it. (For some reason the naive solution of adding a scalar prefix to \CommonHeight, such as 0.8\CommonHeight, gives an error.)

Thanks in advance for any clue.

Solutions using a package other than floatrow are welcomed, as long as they automatically size images height and overall width by a given percentage of text width, as required.

1 Answer 1

4

The floatrow package has two macros, \FRleftmargin and \FRrightmargin which are, by default, \hfill. You can redefine each of them to be \hspace{0.1\textwidth} so the space left for the figures will be 0.8\textwidth.

enter image description here

(rule for scale :)

The definition must be before \begin{floatrow}. If you put it inside \begin{figure} it will be valid for the current figure only, otherwise it will take effect until you redefine it.

I made a little command that will take as argument the desired width of the figures. The command will then balance it and pass to \FRleftmargin and \FRrightmargin. Just call \ThisWidth{0.8\textwidth} after \begin{figure} (or \begin{figure*}, of course :)

\documentclass{article}
\usepackage{mwe}
\usepackage{floatrow}

\makeatletter
\def\ThisWidth#1{%
  \@tempdima\dimexpr(\textwidth-#1)/2\relax
  \edef\FRleftmargin{\noexpand\hspace*{\the\@tempdima}}%
  \edef\FRrightmargin{\noexpand\hspace*{\the\@tempdima}}%
  \ignorespaces}
\makeatother

\begin{document}
\pagenumbering{gobble}
\blindtext

\begin{figure*}
\ThisWidth{0.8\textwidth}
\CommonHeightRow{\begin{floatrow}
\ffigbox[\FBwidth]{\includegraphics[height=\CommonHeight]{example-image-16x10}}{\caption{A caption.}\label{fig:01}}
\ffigbox[\FBwidth]{\includegraphics[height=\CommonHeight]{example-image-10x16}}{\caption{Another caption.}\label{fig:02}}
\end{floatrow}}
\rule{0.8\textwidth}{2pt}
\end{figure*}

\blindtext
\end{document}
4
  • 1
    Great job, thanks! Maybe you are able to make your solution work (I couldn't) also on this other figure with side by side automatically scaled images with subcaptions (needs subcaption package); \begin{figure*} \ffigbox{}{\CommonHeightRow{\begin{subfloatrow}[2] \ffigbox[\FBwidth]{\includegraphics[height=\CommonHeight]{example-image-10x16}}{\caption{A subcaption.}\label{fig:01a}} \ffigbox[\FBwidth]{\includegraphics[height=\CommonHeight]{example-image-16x10}}{\caption{Another subcaption.}\label{fig:01b}} \end{subfloatrow}} \caption{The figure caption.}\label{fig:01a+01b}} \end{figure*}
    – mmj
    May 25, 2018 at 9:57
  • If you think it's better to start another question I'll be glad to do it, otherwise (if your solution fits both cases) I will update this question.
    – mmj
    May 25, 2018 at 10:09
  • @mmj I looked at your example code... My solution will not work for subfloatrow because it makes \FRleftmargin and \FRrightmargin empty and uses another scheme to place the figures, so simply redefining the environment doesn't work :/ I think your best bet is to ask a new question, so more people will see it. Add a link to this question to give a start :) May 25, 2018 at 16:48
  • I started a new question about the similar problem: tex.stackexchange.com/q/433408/28685
    – mmj
    May 25, 2018 at 17:26

You must log in to answer this question.

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