Vertical alignment of graphics

If graphics or graphics and text had to be set side-by-side they would often be placed inside minipage environments. This usually works fine if the minipages should be bottom-aligned. A frequently asked question is how to get top alignment, like here on mrunix.de and here on matheplanet.com. A first approach could be to use t as optional positioning argument of the minipage environment. Here’s a compilable example, showing that graphics would stay bottom-aligned that way, used for a fix:

\documentclass{article}
\usepackage[demo]{graphicx}
\begin{document}
\begin{figure}[ht]
  \fbox{\begin{minipage}[t]{150pt}
    \includegraphics[height=100pt,width=150pt]{test}
  \end{minipage}}
  \hfill
  \fbox{\begin{minipage}[t]{150pt}
    \includegraphics[height=60pt,width=150pt]{test}
  \end{minipage}}
\end{figure}
\end{document}

I’ve used \fbox additionally to visualize the minipages. You may notice that it’s compilable even without the image file, that’s achieved by using demo as option for graphicx.

The reason is that \includegraphics sets the baseline to the bottom. A quick fix is just to insert \vspace{0pt} right before each \includegraphics command, this way the reference point will be the top and both images will be placed top-aligned now.

You could use the same approach if you want to place graphics inside \parbox or inside table cells top-aligned.

18. October 2008 by stefan
Categories: Graphics | 6 comments

Comments (6)

  1. Thanks for the useful tips. For tricky alignment problems I sometimes resort to TikZ since I’m familiar with its many alignment options. Good to know how to achieve the same without loading additional packages.

  2. This was very helpful. Thank you for sharing.

  3. Thanks Stefan for sharing the tip on vspace{0pt}, that’s exactly what I needed!

  4. If I include a \vspace{0pt} before \includegraphics, both graphics are aligned with their bottom sides, when they were aligned at their center before … :(

  5. Thanks! This \vspace{0pt} before \includegraphics in combination with [t] solves also the (original) top alignment problem with subfigure, thus without using the minipages

Leave a Reply to hubie Cancel reply

Required fields are marked *