2

I have the following MWE which I would like to produce one top node and then 2 chains of children nodes, roughly like:

     top

a1 b1

a2 b2

a3 b3

but instead, I get more something like this:

     top

a1 b1 a2
a3 b2

       b3

PDF produced

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document} \begin{tikzpicture}[ every node/.style={ text width=.2\linewidth, draw, }, ] \node(top){top};

\node(a1)[below left=of top]{a1};
\node(a2)[below of=a1]{a2};
\node(a3)[below of=a2]{a3};

\node(b1)[below right=of top]{b1};
\node(b2)[below=of b1]{b2};
\node(b3)[below=of b2]{b3};

\end{tikzpicture}

\end{document}

Is that correct and I am just missing something in my understanding, or is it a problem in TikZ? Is there a workaround? I am using TexLive as packaged in Ubuntu 22.04 (version 2021.20220204-1).

eudoxos
  • 2,973
  • 2
    In your example you mixe syntax of pure TikZ and of positioning library. Use just one of them, since they are differ on way of node positioning, i.e.: between center of nodes at [below of=a1 and between nodes' borders at below=of b17 ). – Zarko Oct 06 '22 at 07:10
  • Oh, cool! I typed it twice and thought I typed the same. Making it all below of= makes the layout consistent now. Can you write that as an answer so that I can accept it? I appreciate that you helped me so swiftly. – eudoxos Oct 06 '22 at 07:34
  • 3
    right of is considered deprecated and right=of should be used. The option on grid can be used to place the nodes in relation their centers again (instead of the borders which is the default of positioning). – Qrrbrbirlbel Oct 06 '22 at 08:07

1 Answers1

3

Let me extend my comment to an answer ...

  • In your example you mix syntax for determining nodes position of pure TikZ (below of=a1) and of positioning library (below=of b1).
  • The first is deprecated and determine distance between center of nodes, the second determine distance between borderders of nodes.
  • In cases when you for some reasons like to position nodes in respect to their centers, than you should use option on grid (as noted @Qrrbrbirlbel in his comment) in the image preamble.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document} \begin{tikzpicture}[ node distance =7mm and 3mm, every node/.style={draw, text width=0.2\linewidth}, ] \node(top){top};

\node(a1)[below left=of top] {a1}; \node(a2)[below=of a1] {a2}; \node(a3)[below=of a2] {a3};

\node(b1)[below right=of top] {b1}; \node(b2)[below=of b1] {b2}; \node(b3)[below=of b2] {b3}; \end{tikzpicture}

\vskip 7ex \begin{tikzpicture}[ node distance = 0.1\linewidth and 0.25\linewidth, % <--- observe that nodes distance is changed on grid, % <--- every node/.style={draw=red, text width=0.2\linewidth}, ] \node(top){wirh option \verb+on grid+};

\node(a1)[below left=of top] {a1}; \node(a2)[below=of a1] {a2}; \node(a3)[below=of a2] {a3};

\node(b1)[below right=of top] {b1}; \node(b2)[below=of b1] {b2}; \node(b3)[below=of b2] {b3}; \end{tikzpicture}

\end{document}

enter image description here

Zarko
  • 296,517