Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to position three graphics next to each other, so that they are aligned at the top line. I used \begin{minipage}, but that does't work like I want it to...

\begin{figure}
\begin{minipage}[t]
\includegraphics[width=2cm,angle=90]{test1}
\end{minipage}
\begin{minipage}[t]
\includegraphics[width=2.5cm,angle=90]{test2}
\end{minipage}
\begin{minipage}[t]
\includegraphics[width=2cm]{test3}
\end{minipage}
\end{figure}

Could somebody help me?

share|improve this question

2 Answers 2

\begin{minipage}[t] sets the first line/top element to the base line. In your case its the image. However the images have different heights. An invisible top element helps, e.g. \vspace{0pt}:

\begin{figure}
\begin{minipage}[t]{2cm}
  \vspace{0pt}
  \includegraphics[width=2cm,angle=90]{test1}
\end{minipage}
\begin{minipage}[t]{2.5cm}
  \vspace{0pt}
  \includegraphics[width=2.5cm,angle=90]{test2}
\end{minipage}
\begin{minipage}[t]{2cm}
  \vspace{0pt}
  \includegraphics[width=2cm]{test3}
\end{minipage}
\end{figure}

The width is specified twice, as argument for minipage and for the image. This redundancy can be removed by environment varwidth of package varwidth, for instance:

\begin{varwidth}{\linewidth}
  \vspace{0pt}
  \includegraphics[width=2cm,angle=90]{test1}
\end{varwidth}

An alternative is \raisebox. It can be used to move the top of the image to the base line:

\raisebox{-\height}{%
  \includegraphics[width=2cm,angle=90]{test1}%
}

(Don't forget to comment the line ends, otherwise they are adding spaces in horizontal mode.)

Full example with rules instead of images:

\documentclass[a5paper]{article}
\usepackage{varwidth}

\begin{document}

\begin{figure}
  \begin{minipage}[t]{2cm}
    \vspace{0pt}   
    \rule{2cm}{1cm}
  \end{minipage}
  \begin{minipage}[t]{2.5cm}
    \vspace{0pt}
    \rule{2.5cm}{3cm}  
  \end{minipage}
  \begin{minipage}[t]{2cm}
    \vspace{0pt}
    \rule{2cm}{2cm}    
  \end{minipage}
\end{figure}

\begin{figure}
  \begin{varwidth}[t]{\linewidth}
    \vspace{0pt}
    \rule{2cm}{1cm}
  \end{varwidth}
  \begin{varwidth}[t]{\linewidth}
    \vspace{0pt}
    \rule{2.5cm}{3cm}
  \end{varwidth}
  \begin{varwidth}[t]{\linewidth}
    \vspace{0pt}
    \rule{2cm}{2cm}
  \end{varwidth}
\end{figure}

\begin{figure}
  \raisebox{-\height}{%
    \rule{2cm}{1cm}%
  }
  \raisebox{-\height}{%
    \rule{2.5cm}{3cm}%
  }
  \raisebox{-\height}{%
    \rule{2cm}{2cm}%
  }
\end{figure}

\end{document}

Result

And finally a macro \topalign follows. Its implementation is based on \halign (TeX primitive, which is used in environment tabular). The cell contents is put into a temporary box and lowered to the base line. The first optional parameter specifies the horizontal space between the aligned elements.

\documentclass[a5paper]{article}

\newcommand{\topalign}[2][0.5em]{%
  \leavevmode
  \vbox{%
    \setlength{\tabskip}{#1}%
    \halign{%
      &%
      \begin{lrbox}{0}%
        \ignorespaces##\unskip
      \end{lrbox}%
      \lower\ht0\copy0 %
      \cr
      #2%
      \crcr
    }%
  }%
}

\begin{document}

\begin{figure}
  \topalign{
    \rule{2cm}{1cm}
    &
    \rule{2.5cm}{3cm}
    &
    \rule{2cm}{2cm}
  }%
\end{figure}

\end{document}
share|improve this answer
    
That works, thank you :) –  Marie Jul 4 at 18:16

You can use the adjustbox package:

\documentclass{article}
\usepackage{graphicx}
\usepackage[export]{adjustbox}

\begin{document}

\begin{figure}
\includegraphics[width=2cm,angle=90,valign=T]{example-image.pdf}
\includegraphics[width=2.5cm,angle=90,valign=T]{example-image-a.pdf}
\includegraphics[width=2cm,valign=T]{example-image-b.pdf}
\end{figure}

\end{document}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.