我对 Tikz 非常陌生,正在尝试绘制一个包含 5 个节点的图表。我的代码如下:
\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}
这里的问题是,我希望节点 1 正好位于节点 2 和 3 的正下方和中间,因此我尝试编写类似 的代码\node[state, below right = of 2 and below left = of 3] (1) {1}
。但是,这不起作用。
我该如何修改我的代码来实现这一点?
答案1
使用库在和calc
之间定义一个点,称为3
2
a
\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}