8

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

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

2 Answers 2

1

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

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

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

enter image description here

Hope this helps!

Thanks again to Christian Hupfer.

2
  • This will turn off the interline skip for the entire document!
    – cfr
    Commented Aug 11, 2016 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
    Commented Aug 11, 2016 at 22:23

You must log in to answer this question.

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