1

Starting from comments to this answer to a similar question, I'm trying to fine tune the case of two beside no-floats figures with independent captions in a multicol document, working on the following MWE:

\documentclass{article}

\usepackage{multicol} \usepackage{graphicx} \usepackage[font=small]{caption} \usepackage{lipsum}

\title{Minimal working example of inline (float free) two beside figures in a two column document} \author{Pinco Pallino}

\captionsetup{aboveskip=1em} % set space between image and caption \newcommand{\picsgap}{0.5\columnsep}% this sets horizontal gap between images

\begin{document} \maketitle

\begin{multicols}{2} \section*{Introduction} \lipsum[3][1-4]

\begin{center} \begin{minipage}{0.85\columnwidth}% this sets the total width of the two figures \addtolength{\textwidth}{-\picsgap}% allowable width reduced so that \hfill becomes \picsgap long \begin{minipage}[t]{0.60\textwidth} \centering \includegraphics[width=\textwidth]{example-image-a}% \captionof{figure}{Short caption.} \end{minipage}\hfill \begin{minipage}[t]{0.40\textwidth} \centering \includegraphics[width=\textwidth]{example-image-b}% \captionof{figure}{\lipsum[3][4-6]} \end{minipage} \end{minipage} \end{center}

\lipsum[3-4] \end{multicols}

\end{document}

The above code allows to choose some parameters (overall width, hprizontal gap between images, vertical space above captions) but I'd like to be able to do (optionally) some more things, like:

  1. center vertically the two images (now images are vertically aligned to their bottom)
  2. center vertically the two image+caption blocks
  3. automatically resize images so that they have the same height
  4. automatically resize images so that they have the same area

Please let me know if I should separate the questions.

enter image description here

Follow up

Question 1 is solved in 2nd script of egreg's answer (delete the tabular environment to keep caption distances uniform).

Question 2, 3 and 4 are solved in my own answer.

mmj
  • 1,702

2 Answers2

1

You can measure the taller image and typeset an invisible rule with that height next to the shorter one.

\documentclass{article}

\usepackage{multicol} \usepackage{graphicx} \usepackage[font=small]{caption} \usepackage{lipsum}

\title{Minimal working example of inline (float free) two beside figures in a two column document} \author{Pinco Pallino}

\newsavebox{\imagebox}

\begin{document} \maketitle

\begin{multicols}{2}

\section*{Introduction}

\lipsum[3][1-4]

\begin{center} \captionsetup{aboveskip=1ex} % less space between image and caption % measure the highest image \sbox{\imagebox}{\includegraphics[width=0.51\columnwidth]{example-image-a}}

\hfill \begin{minipage}[t]{0.51\columnwidth} \centering

\includegraphics[width=\textwidth]{example-image-a}% \captionof{figure}{Short caption.}

\end{minipage}\quad \begin{minipage}[t]{0.34\columnwidth} \centering

\rule{0pt}{\ht\imagebox}% \includegraphics[width=\textwidth]{example-image-b}% \captionof{figure}{\lipsum[3][4-6]} \end{minipage}\hspace*{\fill}

\end{center}

\lipsum[3-4] \end{multicols}

\end{document}

enter image description here

How can you vertically center the images to each other?

\documentclass{article}

\usepackage{multicol} \usepackage{graphicx} \usepackage[export]{adjustbox} \usepackage[font=small]{caption} \usepackage{lipsum}

\title{Minimal working example of inline (float free) two beside figures in a two column document} \author{Pinco Pallino}

\newsavebox{\imagebox}

\begin{document} \maketitle

\begin{multicols}{2}

\section*{Introduction}

\lipsum[3][1-4]

\begin{center} \captionsetup{aboveskip=1ex} % measure the highest image \sbox{\imagebox}{\includegraphics[width=0.51\columnwidth]{example-image-a}}

\hfill \begin{minipage}[t]{0.51\columnwidth} \centering

\includegraphics[width=\textwidth,valign=c]{example-image-a} \captionof{figure}{Short caption.}

\end{minipage}\quad \begin{minipage}[t]{0.34\columnwidth} \centering

\begin{tabular}{@{}c@{}} \rule{0pt}{\ht\imagebox} \end{tabular}% \includegraphics[width=\textwidth,valign=c]{example-image-b}% \captionof{figure}{\lipsum[3][4-6]} \end{minipage}\hspace*{\fill}

\end{center}

\lipsum[3-4] \end{multicols}

\end{document}

enter image description here

egreg
  • 1,121,712
  • I guess your intention is to use the technique of the invisible rule to center vertically the two images (question 1), but I don't understand well how to apply it. With or without the rule, images are vertically aligned to their base. I also put an invisible rule below picture B hoping to move the picture up, but the result was to move the caption down instead. – mmj Jun 17 '21 at 09:15
  • @mmj Do you really want the two images to be vertically aligned at their centers with the caption of the smaller one very far away? – egreg Jun 17 '21 at 09:17
  • This is just one option, in case of very different length of captions (like in the example) I won't apply it of course. In the case of the example I would center vertically the whole blocks (question 2) by using the c option for the inner minipages (I just discovered it). – mmj Jun 17 '21 at 09:22
  • @mmj I added a solution. As I predicted without seeing it, it's really awful – egreg Jun 17 '21 at 09:30
  • In this example case as expected is awful, but in case of two short captions in my opinion vertically center pictures are better than bottom alignment. Moreover, I would avoid altogether the tabular block and use just the valign=c option of includegraphics, so that captions distance from pictures is uniform. Thanks! – mmj Jun 17 '21 at 09:42
0

Question 2 is solved simply by using the c option (instead of t) for the inner minipages.

Question 3 is solved with some math (to place before minipages):

\setbox0\hbox{\includegraphics{\imga}}%
\setbox1\hbox{\includegraphics{\imgb}}%
\edef\widratiox{\fpeval{1/(1+(\ht0*\wd1/(\ht1*\wd0)))}}%
\edef\widratioy{\fpeval{1-\widratiox}}%

and then use \widratiox\textwidth and \widratioy\textwidth as widths of inner minipages of images a and b respectively.

Question 4 is solved in the same way of question 3, but using a slightly different math:

\setbox0\hbox{\includegraphics{\imga}}%
\setbox1\hbox{\includegraphics{\imgb}}%
\edef\widratiox{\fpeval{1/(1+sqrt(\ht0*\wd1/(\ht1*\wd0)))}}%
\edef\widratioy{\fpeval{1-\widratiox}}%
mmj
  • 1,702