5

I know how to horizontally join images together; for example:

\documentclass[12pt]{book}
\usepackage{graphicx}

\begin{document}
\thispagestyle{empty}   
\includegraphics[width=0.25\linewidth]{example-image-a}\includegraphics[width=0.25\linewidth]{example-image-b}\includegraphics[width=0.25\linewidth]{example-image-c}
\end{document}  

yields this:

enter image description here

How may I analogously produce a vertical joining of these three images?

5 Answers 5

8

Put them, e.g., in paragraphs on their own:

\documentclass[12pt]{book}
\usepackage{graphicx}

\begin{document}
\thispagestyle{empty}
\lineskip=0pt% allow vertical boxes to touch each other

\includegraphics[width=0.25\linewidth]{example-image-a}

\includegraphics[width=0.25\linewidth]{example-image-b}

\includegraphics[width=0.25\linewidth]{example-image-c}
\end{document} 

vertical stacked images A B C

Note: The default value of \lineskip, which is the minimum vertical distance of boxes, is 1pt with the standard classes, but can be different with other classes. And if your document contains not only the stacked images, you should limit the change of \lineskip using, e.g., an environment like center, flushleft, raggedright, minipage or a \parbox or \begingroup …\par\endgroup or { … \par}:

\documentclass[12pt]{book}
\usepackage{graphicx}

\begin{document}
\thispagestyle{empty}

\centering
\begin{minipage}{.25\linewidth}
\lineskip=0pt% allow vertical boxes to touch each other

\includegraphics[height=.25\textheight]{example-image-a}

\includegraphics[height=.25\textheight]{example-image-b}

\includegraphics[height=.25\textheight]{example-image-c}
\end{minipage}\hfill
\begin{minipage}{.25\linewidth}
\lineskip=0pt% allow vertical boxes to touch each other

\includegraphics[page=1,height=.25\textheight]{example-image-letter-numbered}

\includegraphics[page=2,height=.25\textheight]{example-image-letter-numbered}

\includegraphics[page=3,height=.25\textheight]{example-image-letter-numbered}
\end{minipage}
\end{document} 

two columns of vertical stacked image

Any other environment, i.e., a figure, would also limit the change to the group of that environment.

As an alternative to paragraphs, you can put them just or on lines on their own, e.g., in a center(or flushleft or flushright) environment (or inside a minipage or \parbox):

\documentclass[12pt]{book}
\usepackage{graphicx}

\begin{document}
\thispagestyle{empty}
\begin{center}
\includegraphics[width=0.25\linewidth]{example-image-a}\\[-\lineskip]
\includegraphics[width=0.25\linewidth]{example-image-b}\\[-\lineskip]
\includegraphics[width=0.25\linewidth]{example-image-c}
\end{center}
\end{document} 

(same result as shown above but horizontally centered in the text area).

In this example, the vertical distance is explicitly reduced by -\lineskip, so that the automatic inserted distance of \lineskip for the touching images, is compensated. You can use this also to do real overlapping:

\documentclass[12pt]{book}
\usepackage{graphicx}

\begin{document}
\thispagestyle{empty}
\begin{center}
\includegraphics[width=0.25\linewidth]{example-image-a}\\[-1ex]
\quad\includegraphics[width=0.25\linewidth]{example-image-b}\\[-1ex]
\qquad\includegraphics[width=0.25\linewidth]{example-image-c}
\end{center}
\end{document} 

overlapping vertical stacked images

Note: Just for better visualization of the overlapping I've added an additional horizontal offset to the second and third image.

You could alternatively also use a tikzpicture or picture to place the images wherever you want. But in this case, this would IMHO be an extravagant solution.

6
  • Would you perhaps know why no dark right-hand border appears with the images? This is also the case for the last image in the MWE.
    – Jethro
    Commented Aug 14 at 15:56
  • @Jethro Sorry, but I don't understand your question. Where should this dark right-hand border come from? Or do you mean, why is seems, that the right vertical line in the image in my example seems to be lighter then than left one? This depends on the resizing of the screenshot bitmap and therefore your browser. Similar can happen in the PDF viewer, but is usually a rendering artifacts.
    – cabohah
    Commented Aug 14 at 16:02
  • On each of the three images, there appears to be a darker border on the left-hand side. However, the right side seems to me (and the viewer I am using) to be not so dark. I was wondering what may be causing this.
    – Jethro
    Commented Aug 14 at 16:33
  • @Jethro No, the left an right lines have the same weight.
    – cabohah
    Commented Aug 14 at 16:49
  • @Jethro, the images have lighter edges for right and left sides. When they are stacked side by side, we are seeing a thicker line in the middle. Same for vertical stacking. The end images have lighter lines on the left and right.
    – mas
    Commented Aug 16 at 1:33
7

Can be achieved with \offinterlineskip within a \parbox. This also ensures that the scope of the line skip manipulation is kept local.

\documentclass[12pt]{book}
\usepackage{graphicx}

\begin{document}
\thispagestyle{empty}
\parbox{0.25\linewidth}{%
  \offinterlineskip%
  \includegraphics[width=\linewidth]{example-image-a}
  \includegraphics[width=\linewidth]{example-image-b}
  \includegraphics[width=\linewidth]{example-image-c}%
}
\end{document}
6

The joinbox package uses l3coffins to horizontally or vertically join boxes. (Scroll down in the pdf for English documentation.) The outlen option sets the final width. See the doc for more options like setting the alignment.

\documentclass{article}

\usepackage{joinbox}
\usepackage{duckuments} % for random ducks!

\begin{document}

\joinfigs[outlen=0.25\linewidth]{example-image-duck,example-image-duck,example-image-duck}

\end{document}

enter image description here

3
  • When I try to run your code, I get the following message in the log: texstudio_qrkSji.tex: error: 5: File joinbox.sty' not found. \usepackage`. Do you what the problem may be on my end?
    – Jethro
    Commented Aug 14 at 20:25
  • The package was added to CTAN in August 2023. Is your tex distribution older than that?
    – mbert
    Commented Aug 14 at 21:02
  • Ah! That explains it. My distribution came out near the beginning of 2023.
    – Jethro
    Commented Aug 14 at 21:08
2

Set \lineskip to zero.

\documentclass[12pt]{book}
\usepackage{graphicx}

\begin{document}

\begin{figure}[htp]
\centering

\includegraphics[width=0.25\linewidth]{example-image-a}%
\includegraphics[width=0.25\linewidth]{example-image-b}%
\includegraphics[width=0.25\linewidth]{example-image-c}

\caption{Three images in a row}

\end{figure}

\begin{figure}[!htp]
\centering
\setlength{\lineskip}{0pt}

\includegraphics[width=0.25\linewidth]{example-image-a}

\includegraphics[width=0.25\linewidth]{example-image-b}

\includegraphics[width=0.25\linewidth]{example-image-c}

\caption{Three stacked images}

\end{figure}

\end{document}

output

3
  • I've already shown an example using \lineskip=0pt (and explaining, that it is needed to allow the vertical boxes to touch each other) in my answer …
    – cabohah
    Commented Aug 15 at 15:20
  • @cabohah Your first code is obviously wrong, because the value of \lineskip is set at the outer level. The second code can be improved a lot, which I showed how.
    – egreg
    Commented Aug 15 at 15:30
  • There was only an outer level in the example code of the question. And if the user does not want to use a figure environment, which code would be wrong? The principle of setting \lineskip is shown correctly in any case. It is actually normal that this also works when setting images within floating environments or boxes within them. But if you think, that limitation of the scope of the setting of \lineskip is important for the correctness of the answer, you should maybe indicate this in the answer.
    – cabohah
    Commented Aug 15 at 15:40
1

You can rule out the placing of vertical \lineskip glue by placing horizontal rules of zero height, zero width and zero depth. Via \vskip-\parskip you can cancel out the insertion of vertical \parskip-glue.

This way images occurring on the same page are joined together but breaking the page between images is possible.

This way you don't need to (temporarily) change values of TeX-parameters like \lineskip.

This also works out in the edge case of height and depth of images being smaller than \baselineskip.

\documentclass[12pt]{book}
\usepackage{graphicx}

\parskip=1cm

\begin{document}

%Make sure TeX is in (internal) vertical mode.

%\null \vskip 12cm % when you uncomment this line while paper-format is a4paper
                   % you can see the behaviour regarding page-breaks between images.

\includegraphics[width=0.25\linewidth]{example-image-a}

\hrule height 0pt width 0pt depth 0pt \vskip-\parskip

\includegraphics[width=0.25\linewidth]{example-image-b}

\hrule height 0pt width 0pt depth 0pt \vskip-\parskip

\includegraphics[width=0.25\linewidth]{example-image-c}

\end{document}  

enter image description here

1
  • +1 Also an interesting suggestion.
    – cabohah
    Commented Aug 16 at 7:10

You must log in to answer this question.

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