1

Let's say I have 2 nodes. Node 1 is placed anywhere and node 2 is placed right of node 1. Does tikz solve a set of constraints to solve this problem? Clearly it is underdefined as any position on the y axis would satisfy the constraint.

However, if I have 5 nodes

Node 1 is placed at the top. Node 2 is places below and left of 1. Node 3 is placed below 2. Node 4 is placed below and right of 1. Node 5 is placed right of node 3 and left of node 4.

Where on the y axis is node 5 placed? And could I get both node 4 and 5 to be placed at the same y level as node 3?

Code with ??? for unknown parameters.

\node (1) {1};
\node[below left of=1] (2) {2};
\node[below of=2] (3) {3};
\node[below right of 1, ??? and right of 3 ???] (4) {4};
\node[??? right of (3) and left of (4) ???] (5) {5};

Also, does tikz know to increase the x spacing between nodes 2 and 4 because I am placing node 5 in between them?

Sven Voigt
  • 43
  • 4
  • The first node will be placed at (0,0) by default. You can not specify two left, right, above or below options, but you can use at (1 |- 2) for example. (Assuming the parser doesn't balk at using numbers for names.) – John Kormylo Jul 25 '23 at 02:34
  • 1
    First of all, the … of = … keys are deprecated (for over 10 years) and the positioning library's … = of … should be used. TikZ uses the value of node distance or whatever'S written before the of, i.e. below=2cm of 2. There's no “inbetween” for TikZ. If you need smarter placement, you will need to use the forest package or one of the graphdrawing libraries. – Qrrbrbirlbel Jul 25 '23 at 09:14

1 Answers1

1

I'm not sure about the position specification but this can be done with positioning library

\documentclass[tikz, border=1mm]{standalone}
\usetikzlibrary{positioning}

\begin{document} \begin{tikzpicture} \node[draw] (1) {1}; \node[draw, below left= of 1] (2) {2}; \node[draw, below=of 2] (3) {3}; \node[draw, below right= of 1] (4) {4}; \node[draw, right=of 3] (5) {5}; \end{tikzpicture} \end{document}

enter image description here

Ignasi
  • 136,588