[Tex/LaTex] No vertical spacing between TikZ Pictures

spacingtikz-pgf

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}

Two TikZ Pictures

Best Answer

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:

no interlineskip anywhere

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}

turning off interline skip for this case