0

This latex compiles for me perfectly:

\documentclass[12pt,a4paper]{book}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[level/.style={sibling distance = 5cm/#1,text width=1cm, level distance = 1.2cm}] 
\node[text width=2.5cm]  {A} 
      child{ node  {A} 
      child{ node  {A} }
  }
; 
\end{tikzpicture}
\end{document}

It produces this:

enter image description here

However this latex:

\documentclass[12pt,a4paper]{book}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[level/.style={sibling distance = 5cm/#1,text width=1cm, level distance = 1.2cm}] 
\node[text width=2.5cm]  {A} 
      child{ node  {A} 
      child{ node  {A} 

}
  }
; 
\end{tikzpicture}
\end{document}

Gives me:

Runaway argument?
{ node {A} child{ node {A} 
! Paragraph ended before \tikz@collect@child@code was complete.
<to be read again> 
                   \par 
l.10 
     
? 

What's going on? Does tikx have meaningful whitespace (the only thing that has changed is the addition of new carriage returns before one of the } characters)? My googling is just giving me ways of putting whitespace in the pdf...

  • In general no, but in your particular case (in tree structure) has. – Zarko Jul 20 at 14:22
  • 2
    BTW, the \par is how TeX interprets blank lines. This is before any extraneous text is dumped into a bit box. – John Kormylo Jul 20 at 14:25
  • Spaces are mostly ignored in TikZ, with due exception for textual parts. However it doesn't allow blank lines in certain arguments; technically because the macros are not declared \long. At the outer level a blank line is not a problem, because \par tokens are ignored in what is eventually an \hbox; there may be good reasons not to allow blank lines in that situation (or it is just that the developers didn't think to users putting blank lines in that position). – egreg Jul 20 at 17:04
  • @egreg thank you! :) – Joe Jul 21 at 4:48
1

the error is caused due to the extra blank line after the second child node in your code --remove it and things will be normal

\begin{tikzpicture}[level/.style={sibling distance = 5cm/#1,text width=1cm, level distance = 1.2cm}] 
\node[text width=2.5cm]  {A} 
child{ node  {A} 
    child{ node  {A} 
                }%<---------------------------removed blank line
}
; 
\end{tikzpicture}
| improve this answer | |

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.