2

(The question does not concern figures, captions, ...)

It's easy to put two graphics gra1 and gra2 side by side so that they touch each other along their right and left vertical sides of the bounding box, being

\includegraphics{gra1}\includegraphics{gra2}

enough to accomplish the goal (the two graphics will be arranged as G1G2 with no space in between them).

What if one wants to put them one above the other so that they touch each other along the horizontal sides? They should be arranged like this

G1
G2

with no space in between them. Is there any way I can do this which is as clear, simple (no package required) as the previous is?

I know that a new line is not the solution for two reasons:

  1. when the two graphics are small enough, a space will appear in between the two graphics, since they belong to different lines;
  2. I don't want the pair of graphics to be however related to the lines, since I just want to use the pair as it was a whole.

I'm not looking for the TikZ solution.

EDIT The reson for the point 2. is that I'm going to use this pack of two graphics as optional argument of \item in a itemize environment. So I'd like to put something like

\newcommand{\horzcat}{\includegraphics{gra1}\includegraphics{gra2}}
\newcommand{\vertcat}{<the solution I'm looking for>}

in the preamble, so that I can have a list like the following,

\begin{itemize}
    \item[\horzcat] ...
    \item[\vertcat] ...
    ...
\end{itemize}
  • 2
    Where should the baseline/bottom be of the two pictures? – Ulrike Fischer Feb 17 '17 at 21:26
  • The two pictures should be one above the other with no space between them, so the only baseline which makes sense is the one of the lower picture. I'd like it to coincide with its lower edge. – Enrico Maria De Angelis Feb 17 '17 at 21:29
3

Example, where \vertcat is implemented by stacking the images in a \vbox with the base line at the bottom of the lower image (see OP's comment).

The images are left-aligned, the overall width is the width of the wider image. \offinterlineskip removes the space between the image, regardless whether \baselineskip or \lineskip would be used otherwise.

The solution for placing the images does not need any further packages. In contrary, it is implemented with commands and macros that are already available in plain TeX.

\documentclass{article}
\usepackage{graphicx}

\newcommand*{\gra}[1]{%
  \includegraphics[width=10pt]{example-image-#1}%
}

\newcommand*{\horzcat}{\gra{a}\gra{b}}
\newcommand*{\vertcat}{%
  \leavevmode
  \vbox{% baseline is at the bottom
    \offinterlineskip % disable line skip
    \hbox{\gra{a}}%
    \hbox{\gra{b}}%
  }%
}

\begin{document}
\begin{itemize}
  \item[\horzcat] side by side
  \item[\vertcat] one above the other
\end{itemize}
\end{document}

Result

4

This is simple:

enter image description here

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\centering
\includegraphics[width=0.5\linewidth]{example-image-a}\\% <-- force next image in new line
\includegraphics[width=0.5\linewidth]{example-image-b}
\end{document}

Hopefully I understood question correctly :-)

Addendum: Unfortunately I didn't understood question correctly and meanwhile you receive two good answers. Anyway, consider David Carlisle comment below, I can adopt my answer to:

\documentclass{article}
\usepackage{graphicx}

\begin{document}
\centering
\parbox{0.5\linewidth}{\setlength\lineskip{0pt}
\includegraphics[width=\linewidth]{example-image-a}
\includegraphics[width=\linewidth]{example-image-b}
                        }
\end{document}

Now between images is no vertical space nor needed to use \\ to force image into new line :-)

  • Please, read the edited question :) – Enrico Maria De Angelis Feb 17 '17 at 20:54
  • I would guess they have \lineskip separation between them. – David Carlisle Feb 17 '17 at 20:57
  • @DavidCarlisle, yes \setlength\lineskip{0pt} eliminate tiny vertical space between image. – Zarko Feb 17 '17 at 21:42
  • @EnricoMariaDeAngelis, now you question i slightly more clear to me. I add new solution to my answer, not much different from other answers you receive meanwhile. – Zarko Feb 17 '17 at 21:45
3

Assuming the height of the figures is no less than a \baselineskip, setting the \lineskip to zero would solve the problem (as also suggested by @DavidCarlisle):

\documentclass{article}
\usepackage{graphicx}
\begin{document}

Resetting lineskip to zero:

\parbox{1cm}{%
\setlength\lineskip{0pt}
\includegraphics[width=1cm]{example-image-a}\\
\includegraphics[width=1cm]{example-image-b}
}

\bigskip

And with normal lineskip

\parbox{1cm}{%
%\setlength\lineskip{0pt}
\includegraphics[width=1cm]{example-image-a}\\
\includegraphics[width=1cm]{example-image-b}
}

\end{document}

enter image description here

3

Assuming that it should work with small graphics too:

\documentclass{article}
\usepackage{graphicx}
\begin{document}
 \makebox[0pt][l]{\includegraphics[height=5pt]{example-image}}%
 \raisebox{-\height}{\includegraphics[height=5pt]{example-image}} blblbl

\bigskip
 \raisebox{\depth}{\makebox[0pt][l]{\includegraphics[height=5pt]{example-image}}%
 \raisebox{\height}{\includegraphics[height=5pt]{example-image}}} blblbl

\end{document}

enter image description here

3

You can use a tabular environment with \arraystretch set to zero. This also works for tiny elements. The optional argument of the command \vstack below controls whether the elements will be centered, left- or right-aligned; the elements are separated by \\.

\newcommand\vstack[2][c]%
  {{\renewcommand\arraystretch{0}%
    \begin{tabular}[b]{@{}#1@{}}#2\end{tabular}%
  }}

enter image description here

\documentclass{article}
\usepackage{graphicx}
\newcommand\vstack[2][c]%
  {{\renewcommand\arraystretch{0}%
    \begin{tabular}[b]{@{}#1@{}}#2\end{tabular}%
  }}
\begin{document}

\vstack[l]%
  {\includegraphics[height=3pt]{example-image-a}\\
   \includegraphics[height=5pt]{example-image-b}
  }
a
\vstack
  {\includegraphics[height=3pt]{example-image-a}\\
   \includegraphics[height=5pt]{example-image-b}
  }
b
\vstack[r]%
  {\includegraphics[height=3pt]{example-image-a}\\
   \includegraphics[height=5pt]{example-image-b}
  }

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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