# No vertical spacing between TikZ Pictures

I would like to have absolutely no vertical space between the two TikZ Pictures. I could use for example \\[-1pt] but I don't know if 1pt is really the exact value... (so I removed it from the code)!

Where does this vertical space come from? I would like the two boxes to have contact!

\documentclass{article}
\usepackage{tikz}

\setlength{\parindent}{0pt}
\setlength\textwidth{5cm}

\begin{document}

\begin{tikzpicture}[every node/.style={inner sep=2,outer sep=0}]
\node[draw,text width=\textwidth] {A};
\end{tikzpicture} %\\[-1pt]
\begin{tikzpicture}[every node/.style={inner sep=2,outer sep=0}]
\node[draw,text width=\textwidth] {B};
\end{tikzpicture}

\end{document}

• There is an extra vertical spacing called \lineskip between lines – user31729 Jun 28 '16 at 15:40
• ok, then i have to use \\[-\lineskip], thx! – micmic Jun 28 '16 at 15:54
• See also the explanations in the answers to a question of mine here: tex.stackexchange.com/questions/194427/… – user31729 Jun 28 '16 at 16:00
• is there a way to use after=\par\nointerlineskip with TikZ ? – micmic Jun 28 '16 at 16:30
• I had to set both \lineskip=0pt and \baselineskip=0pt, or at least \baselineskip<11.2pt (the height of the tikzpicture). – John Kormylo Jun 29 '16 at 0:49

Although using \offinterlineskip, as heather suggests, will work in some sense, turning off the interline skip for the entire document is probably not what you want:

Instead, you probably want to turn it off just for this particular case. In that case, you either need to limit the scope of \offinterlineskip and ensure the vertical spacing comes out correctly, or use something more like a nut cracker than a sledge hammer.

In this case, \nointerlineskip works well, provided you note that the paragraph break between the two pictures is required. Without it, you'll get a compilation error. There are other ways to avoid this, but the paragraph break does no harm here and seems an easy solution.

\documentclass{article}
\usepackage{tikz}
\usepackage{kantlipsum}
\setlength{\parindent}{0pt}
\setlength\textwidth{5cm}
\begin{document}
\kant[1]

\begin{tikzpicture}[every node/.style={inner sep=2,outer sep=0}]
\node[draw,text width=\textwidth] {A};
\end{tikzpicture}

\nointerlineskip
\begin{tikzpicture}[every node/.style={inner sep=2,outer sep=0}]
\node[draw,text width=\textwidth] {B};
\end{tikzpicture}

\kant[2]
\end{document}

• @heather Testing helps ;). – cfr Aug 11 '16 at 23:07
• I only tested it with the boxes, not with other text. Oops. =) – heather Aug 11 '16 at 23:08

Thanks to Christian Hupfer for his comments.

You need the code

\documentclass{article}
\usepackage{tikz}

\setlength{\parindent}{0pt}
\setlength\textwidth{5cm}
\offinterlineskip

\begin{document}
\centerline{
\begin{tikzpicture}[every node/.style={inner sep=2,outer sep=0}]
\node[draw,text width=\textwidth] {A};
\end{tikzpicture}}

\begin{tikzpicture}[every node/.style={inner sep=2,outer sep=0}]
\node[draw,text width=\textwidth] {B};
\end{tikzpicture}

\end{document}

Specifically, the line \offinterlineskip. This gives

Hope this helps!

Thanks again to Christian Hupfer.

• This will turn off the interline skip for the entire document! – cfr Aug 11 '16 at 22:20
• Also, why are you using \centerline? I don't see the why at all here but, in any case, it should hardly ever be used in LaTeX and almost never in user documents, as I understand it. At least, that's what I've read. – cfr Aug 11 '16 at 22:23