1

I'm trying to top-align figure panels using minipage. It works fine if both minipages have the same width, but if they don't, it doesn't work: the figure panel in the smaller minipage appears below its desired position. I don't understand what is the problem, since minipage width should not matter. Here is my code:

\begin{figure}[h]
  \begin{minipage}[t]{0.7\textwidth}  
    \centerline {
      \includegraphics[width=\textwidth]{example-image-a.png}}\vfill
    \centerline {
      \includegraphics[width=\textwidth]{example-image-b.png}}
  \end{minipage}\hfill
  \begin{minipage}[t]{0.3\textwidth}    
    \centerline {
      \includegraphics[width=\textwidth]{example-image-c.png}}
  \end{minipage}
\end{figure}

Among other things, I tried

\begin{minipage}[t][][t]{0.3\textwidth}    

as suggested here, as well as \strut and \raisebox as suggested here, with no luck so far.

fbaroni
  • 13
  • 1
    Welcome to TSE. Please post a Minimal Working Example, instead of a code snippet. – José Carlos Santos Aug 26 '23 at 15:11
  • \centerline { \includegraphics[width=\textwidth]{example-image-a.png}} will force the image off centre as it has a space to the left – David Carlisle Aug 26 '23 at 15:26
  • [t] aligns the first baseline, which is at the bottom of the image. You can use \usepackage[export]{adjustbox} to add [valign=T] to \includegraphics. or jsut use \raisebox{-\height}{...}/ – John Kormylo Aug 27 '23 at 20:31
  • @DavidCarlisle thanks for your comment. I try to be mindful about avoiding extra spaces, but they still appear every now and then. For example, auto-indent might add spaces. What would you recommend as a workflow for avoiding spurious spaces while maintaining source files' readability? (sorry for asking in a comment) – fbaroni Aug 28 '23 at 14:38
  • spaces at the beginning of a line are not a problem (tex strips them) so indentation isn't a problem, just don't add spaces.\fbox{ a } is not the same as \fbox{a} – David Carlisle Aug 28 '23 at 15:27

1 Answers1

0

The problem is that the \includegraphics extend upward from the "top-aligned" baseline. Differing image sizes will leave them misaligned at top.

Here, I use the \belowbaseline macro from stackengine package to achieve top alignment.

\documentclass{article}
\usepackage{graphicx,stackengine}
\begin{document}

\begin{figure}[h] \belowbaseline[0pt]{\begin{minipage}[t]{0.7\textwidth}
\centerline { \includegraphics[width=\textwidth]{example-image-a.png}}\vfill \centerline { \includegraphics[width=\textwidth]{example-image-b.png}} \end{minipage}}\hfill \belowbaseline[0pt]{\begin{minipage}[t]{0.3\textwidth}
\centerline { \includegraphics[width=\textwidth]{example-image-c.png}} \end{minipage}} \end{figure}

\end{document}

enter image description here