0

I am very new to Tikz and am trying to draw a diagram with 5 nodes. My code is as follows:

\usepackage{tikz}
\usetikzlibrary{automata, arrows, positioning}

\begin{document}

\begin{center}
\begin{tikzpicture}
\tikzset{node distance = 3 cm, every state/.style = {semithick}, every edge/.style = {draw, ->, > = stealth', semithick}}

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

\end{tikzpicture}
\end{center}

\end{document}

The problem here is that I would like node 1 to be exactly below and in the middle nodes 2 and 3, so I am trying to code something like \node[state, below right = of 2 and below left = of 3] (1) {1}. However, this does not work.

How can I amend my code to achieve this?

2
  • 1
    Why don't you change the drawing order? First node 1 and then nodes 2 and 3 from it.
    – Ignasi
    Sep 16, 2021 at 17:59
  • @Ignasi Brilliant!! I never even thought of that...
    – Ethan Mark
    Sep 17, 2021 at 1:27

1 Answer 1

3

using calc library define a point between 3 and 2 called a

enter image description here

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{automata, arrows, positioning, calc}

\begin{document}

\begin{center}
\begin{tikzpicture}
\tikzset{node distance = 3 cm, every state/.style = {semithick}, every edge/.style = {draw, ->, > = stealth', semithick}}

\node[state] (2) {2};
\node[state, right = of 2] (3) {3};
\coordinate(a) at ($(2)!0.5!(3)$);
\node[state, below= of a] (1) {1};
\node[state, below left = of 1] (4) {4};
\node[state, below right = of 1] (5) {5};

\end{tikzpicture}
\end{center}

\end{document}

You must log in to answer this question.

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