TikZ-Trees – Fixing Error Drawing Trees Using TikZ

tikz-pgftikz-trees

I'm trying to draw a tree with tikz

I've tried this:

\documentclass{report}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[nodes={draw, circle}]
\path
(0, 0)          node        (1a)        {5};
(-2, -1)        node        (2a)        {12};

\draw
(1a)--(2a)
\end{tikzpicture}
\end{document}

I get ! Package pgf Error: No shape named `2a' is known. How can I fix it?

I would also like to tweak the links.

If I omit the \draw part, only the first node is drawn. How can I draw 2 nodes without any link?

Is there any way to draw with a thicker line?

Best Answer

You are terminating the \path with a semicolon after making the 1a node but not starting a new path, so the second node invocation does nothing.

If you check the log the error is preceded by

Missing character: There is no ( in font nullfont!
Missing character: There is no - in font nullfont!
Missing character: There is no 2 in font nullfont!
Missing character: There is no , in font nullfont!
Missing character: There is no - in font nullfont!
Missing character: There is no 1 in font nullfont!
Missing character: There is no ) in font nullfont!
Missing character: There is no n in font nullfont!
Missing character: There is no o in font nullfont!
Missing character: There is no d in font nullfont!
Missing character: There is no e in font nullfont!
Missing character: There is no ( in font nullfont!
Missing character: There is no 2 in font nullfont!
Missing character: There is no a in font nullfont!
Missing character: There is no ) in font nullfont!
Missing character: There is no 1 in font nullfont!
Missing character: There is no 2 in font nullfont!
Missing character: There is no ; in font nullfont!

! Package pgf Error: No shape named `2a' is known.

indicating the (-2, -1) node (2a) {12}; line is trying to be printed rather than parsed.

You also need a semicolon to terminate the \draw command.

\documentclass{report}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[nodes={draw, circle}]
\path
(0, 0)          node        (1a)        {5}
(-2, -1)        node        (2a)        {12};

\draw
(1a)--(2a);
\end{tikzpicture}
\end{document}

Depending on your use case though

\documentclass{report}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[nodes={draw, circle}]
\node (1a) at (0, 0) {5};
\node (2a) at (-2, -1) {12};

\draw (1a)--(2a);
\end{tikzpicture}
\end{document}

might be easier to write.