6

In the example below, how can I set the height of the 2nd minipage so that it matches the one of the 1st one, such that the images "C" are uniformly distributed vertically to match the composite height of the images "A" and "B"?

Please note:

1) the dissimilar widths of the minipages is an important constraint, and

2) I'm looking for a solution that literally does what the question says; I know the same behavior can be achieved using tabular or other means, but I'm really interested in learning how to determine float sizes and reuse them to size others.

Thanks, Jorge.

Example:

\documentclass{article}
\usepackage{graphicx}
\usepackage{subfig}

\begin{document}
\begin{figure*}[!t]
    \fbox{\noindent
    \begin{minipage}[b]{0.6\linewidth}
        \subfloat[]{\includegraphics[width=1.0\linewidth]{example-image-a}}
        \vfill
        \subfloat[]{\includegraphics[width=1.0\linewidth]{example-image-b}}
    \end{minipage}}
    \hfill
    \fbox{\noindent
    \begin{minipage}[b]{0.3\linewidth}
        \subfloat[]{\includegraphics[width=1.0\linewidth]{example-image-c}}
        \vfill
        \subfloat[]{\includegraphics[width=1.0\linewidth]{example-image-c}}
        \vfill
        \subfloat[]{\includegraphics[width=1.0\linewidth]{example-image-c}}
    \end{minipage}}
\end{figure*}
\end{document}

Output: enter image description here

2
  • 1
    Would you accept a solution that uses the TeX primitive \valign?
    – GuM
    Jul 4, 2018 at 18:50
  • Not really sure, as I'm not familiar with it :O I guess my actual goal is learning to determine float sizes and using them to resize others.
    – dontpanic
    Jul 4, 2018 at 18:57

3 Answers 3

11

Measure the left box and force the right minipage to have the same height.

\documentclass{article}
\usepackage{graphicx}
\usepackage{subfig}

\newsavebox{\dontpanicbox}
\newlength{\dontpanicht}

\begin{document}

\begin{figure}[!htp]
\centering

\sbox{\dontpanicbox}{%
  \begin{minipage}[b]{0.6\linewidth}
  \subfloat[]{\includegraphics[width=1.0\linewidth]{example-image-a}}

  \subfloat[]{\includegraphics[width=1.0\linewidth]{example-image-b}}
  \end{minipage}%
}

\setlength{\dontpanicht}{\ht\dontpanicbox}

\usebox{\dontpanicbox}\hfill
\begin{minipage}[b][\dontpanicht][s]{0.3\linewidth}
  \subfloat[]{\includegraphics[width=1.0\linewidth]{example-image-c}}

  \vfill

  \subfloat[]{\includegraphics[width=1.0\linewidth]{example-image-c}}

  \vfill

  \subfloat[]{\includegraphics[width=1.0\linewidth]{example-image-c}}
\end{minipage}

\end{figure}

\end{document}

enter image description here

“Much simpler” with \valign. 😉

\documentclass{article}
\usepackage{graphicx}
\usepackage{subfig}

\begin{document}

\begin{figure}[!htp]
\centering

\valign{#\cr
  \hsize=0.6\textwidth
  \subfloat[]{\includegraphics[width=\hsize]{example-image-a}}\vfill
  \subfloat[]{\includegraphics[width=\hsize]{example-image-b}}\cr
  \noalign{\hfill}
  \hsize=0.3\textwidth
  \subfloat[]{\includegraphics[width=\hsize]{example-image-c}}\vfill
  \subfloat[]{\includegraphics[width=\hsize]{example-image-c}}\vfill
  \subfloat[]{\includegraphics[width=\hsize]{example-image-c}}\cr
}

\end{figure}

\end{document}

Where's the advantage? In that you don't need to know which column is higher. For instance, if the proportions are set to 0.55 and 0.35 instead of 0.6 and 0.3, the right column would become higher, but the same code as above, with just the change in the two parameters

\valign{#\cr
  \hsize=0.55\textwidth
  \subfloat[]{\includegraphics[width=\hsize]{example-image-a}}\vfill
  \subfloat[]{\includegraphics[width=\hsize]{example-image-b}}\cr
  \noalign{\hfill}
  \hsize=0.35\textwidth
  \subfloat[]{\includegraphics[width=\hsize]{example-image-c}}\vfill
  \subfloat[]{\includegraphics[width=\hsize]{example-image-c}}\vfill
  \subfloat[]{\includegraphics[width=\hsize]{example-image-c}}\cr
}

would produce

enter image description here

8
  • 1
    @dontpanic I added a “simpler” solution.
    – egreg
    Jul 4, 2018 at 19:50
  • Wow, much simpler indeed! thanks again egreg! :)
    – dontpanic
    Jul 4, 2018 at 19:53
  • 2
    @dontpanic I also added a reason for using it. On the other hand, it's for cognoscenti and initiated. ;-)
    – egreg
    Jul 4, 2018 at 19:55
  • Awesome! this situation happens very often in my documents; now I know an easier way to deal with it!!! Muchas gracias! :)
    – dontpanic
    Jul 4, 2018 at 20:19
  • 1
    @dontpanic And you can even have more than two columns!
    – egreg
    Jul 4, 2018 at 20:22
5

like this?

enter image description here

instead of minipage i suggest to use tabular* environment:

\documentclass[twocolumn]{article}
\usepackage{graphicx}
\usepackage{subfig}
\usepackage{array, hhline}

%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}
    \begin{figure*}
    \centering
\setkeys{Gin}{width=\linewidth}
\begin{tabular*}{\linewidth}{|m{\dimexpr0.6\linewidth-2\tabcolsep-1.5\arrayrulewidth}|
                              p{\dimexpr0.1\linewidth-2\tabcolsep}
                             |m{\dimexpr0.3\linewidth-2\tabcolsep-1.5\arrayrulewidth}|
                             }
    \hhline{|-|~|-|}
\subfloat[]{\includegraphics{example-image-a}}

\bigskip
\subfloat[]{\includegraphics{example-image-b}}
\medskip
&&
\subfloat[]{\includegraphics{example-image-duck}}

\vspace{4ex} % <-- determined experimentaly, depends of images heights
\subfloat[]{\includegraphics{example-image-duck}}

\vspace{4ex} % <-- determined experimentaly, depends of images heights
\subfloat[]{\includegraphics{example-image-duck}}   \\
    \hhline{|-|~|-|}
    \end{tabular*}
\end{figure*}
\end{document}
3
  • Thank you so much, Zarko. I forgot to mention that I'm looking for a solution using minipage :)
    – dontpanic
    Jul 4, 2018 at 19:27
  • 1
    @dontpanic, you clearly stated, that you looking solution with minipage, however, meanwhile you wait on it, you can use this. solution with minipage will not be so simple :-) (to my opinion of course) and i don't see any reason, why not use table.
    – Zarko
    Jul 4, 2018 at 19:30
  • Yes, thanks! BTW nice ducks, didn't know about them! :D
    – dontpanic
    Jul 4, 2018 at 19:39
4

This uses a savebox to measure the height. One could also use \settoheight, but I suspect that it uses a savebox internally.

BTW, the [s] option stands for stretch. Of course, with \vfill one would get the same results using [t]. [b] or [c]. OTOH, the \vfill in the first minipage does nothing.

\documentclass{article}
\usepackage{graphicx}
\usepackage{subfig}

\begin{document}
\begin{figure*}[!t]
  \sbox0{\begin{minipage}[b]{0.6\linewidth}% measure height
        \subfloat[]{\includegraphics[width=1.0\linewidth]{example-image-a}}
        \vfill
        \subfloat[]{\includegraphics[width=1.0\linewidth]{example-image-b}}
    \end{minipage}}%
    \fbox{\usebox0}%
    \hfill
    \fbox{\begin{minipage}[b][\ht0][s]{0.3\linewidth}
        \subfloat[]{\includegraphics[width=1.0\linewidth]{example-image-c}}
        \vfill
        \subfloat[]{\includegraphics[width=1.0\linewidth]{example-image-c}}
        \vfill
        \subfloat[]{\includegraphics[width=1.0\linewidth]{example-image-c}}
    \end{minipage}}
\end{figure*}
\end{document}

demo

0

You must log in to answer this question.

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