4

How would I place two images below each other so that their left sides are aligned and the whole construction is centered?

I tried like this:

\makebox[120]{}\includegraphics[width=210]{images/img001_1.png}
\\
\makebox[120]{}\includegraphics[width=160]{images/img001_2.png}

But that deems me a crude method. LaTeX doesn't like it either:

Illegal unit of measure (pt inserted) \makebox[120]{}

Illegal unit ofmeasure (pt inserted) ...egraphics[width=210]{images/img001_1.png}

Illegal unit of measure (pt inserted) \makebox[120]{}

Illegal unit of measure (pt inserted) ...egraphics[width=160]{images/img001_2.png}

Illegal unit of measure (pt inserted) ...egraphics[width=160]{images/img001_2.png}

I'd appreciate the help.

3 Answers 3

4

You can use two \makeboxes with l(eft) alignment and both having a width equal to the width of the widest figure:

\documentclass{article}
\usepackage{graphicx}
\usepackage{showframe}% just for visualization purposes in the example

\begin{document}


\begin{figure}
\centering
\makebox[7cm][l]{\includegraphics[width=2cm]{example-image-a}}\\
\makebox[7cm][l]{\includegraphics[width=7cm,height=3cm]{example-image-b}}
\caption{Two images  below each other; their left sides are aligned and the whole construction is centered}
\end{figure}

\begin{figure}
\centering
\makebox[3cm][l]{\includegraphics[width=1cm]{example-image-a}}\\
\makebox[3cm][l]{\includegraphics[width=3cm]{example-image-b}}
\caption{Two images  below each other; their left sides are aligned and the whole construction is centered}
\end{figure}

\noindent  X\dotfill X % just for visualization

\end{document}

enter image description here

Of course, if no flotation is desired, instead of figure you can simply use a center (or a minipage environment with \centering) and \captionof (from the caption package) to provide an eventual caption.

1
  • Good answer. Can also be written shorter with \usepackage[export]{adjustbox}: Then just add e.g. left=7cm to the option list: \includegraphics[width=2cm,left=7cm,center]{example-image-a} \includegraphics[width=7cm,height=3cm,left=7cm,center]{example-image-b}. The center option replaces the \centering and the need for \\. Mar 14, 2018 at 6:30
4

The \makebox[<length>]{<content>} carries a length not just an integer; thus, the error

Illegal unit of measure (pt inserted) \makebox[120]{}

Something like 120em instead of 120 will help. For more information read the following extract I got from LaTeX Spaces and Boxes. Here is another useful link on the \makeboxcommand.

\makebox[width][position]{text}

The \makebox command creates a box to contain the text specified. The width of the box is specified by the optional width argument. The position of the text within the box is determined by the optional position argument described below:

  • c - centered (default)
  • l - flushleft
  • r - flushright
  • s - spread
2

Azetina's answer tells you the exact syntax. This answer tries to provide an illustration:

\documentclass{article}
\usepackage{graphicx,showframe}  %% showframe just for demo
\begin{document}
  \begin{center}
  %% syntax \makebox[<width with units>][<position - l/c/r/s>]{<content>}
  \makebox[4cm][r]{\includegraphics[width=5cm]{example-image-a}}
  \makebox[4cm][c]{\includegraphics[width=6cm]{example-image-b}}
  \end{center}      

  \begin{center}
  \makebox[4cm][l]{\includegraphics[width=5cm]{example-image-a}}
  \makebox[4cm][c]{\includegraphics[width=6cm]{example-image-b}}
  \end{center}

  \noindent 
  X\dotfill X
\end{document}

enter image description here

3
  • You forgot the s
    – azetina
    Jan 20, 2014 at 0:14
  • \noindent is not needed inside center (nor before it). Jan 20, 2014 at 1:08
  • @GonzaloMedina Uh. Remnants of previous code. Thanks.
    – user11232
    Jan 20, 2014 at 1:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .