TeXblog

 Typography with TeX and LaTeX

Vertical alignment of graphics

18 October 2008 by Stefan Kottwitz

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.

This entry was posted on 18 October 2008 at 6:45 PM and is filed under Graphics. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

1 response about “Vertical alignment of graphics”

  1. Kjell Magne Fauske said:

    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.

Leave a Reply