\begin{tikzpicture}
\node[state] (x11) {$X_1^1$};
\node[state, right of=x11] (x12) {$X^2_1$};
\node[state, right of=x12] (x13) {$X^3_1$};
\node[state, right of=x13] (x14) {$X^4_1$};
\node[state, right of=x14] (x15) {$X^5_1$};
\node[state, below of=x11,label=left:$s\leq 3$] (x21) {$X^1_2$};
\node[state, below of=x12] (x22) {$X^2_2$};
\node[state, below of=x13] (x23) {$X^3_2$};
\node[state, below of=x14] (x24) {$X^4_2$};
\node[state, below of=x15] (x25) {$X^5_2$};
\node[state, below of=x21] (x31) {$X^1_3$};
\node[state, below of=x22] (x32) {$X^2_3$};
\node[state, below of=x23] (x33) {$X^3_3$};
\node[state, below of=x24] (x34) {$X^4_3$};
\node[state, below of=x25] (x35) {$X^5_3$};
\draw
(x11) edge[above] node{} (x21)
(x11) edge[above] node{} (x22)
(x13) edge[above] node{} (x24)
(x13) edge[above] node{} (x25)
(x15) edge[above] node{} (x23)
(x22) edge[above] node{} (x33)
(x22) edge[above] node{} (x31)
(x23) edge[above] node{} (x32)
(x25) edge[above] node{} (x34)
(x25) edge[above] node{} (x35)
;
\end{tikzpicture}
如果我改成,怎么label=left:$s\leq 3$
就不label=left:$s=3$
能再编译代码了......
我明白了! Extra }, or forgotten $
。
答案1
@ferahfeza 评论给出了您的问题的解决方案。注意,符号=
用于定位节点标签。如果有两个,解析器就会丢失。因此,=
方程中的必须“隐藏”,即必须用花括号括起来。好的做法是将完整的方程括在花括号中,因为这样方程中的间距就会保留。
tikz
因此,我建议使用库进行一些题外的改进chains
,positioning
并且quotes
:
\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{automata,
chains,
positioning,
quotes}
\begin{document}
\begin{tikzpicture}[
node distance = 4mm and 4mm,
start chain = going right,
state/.append style = {inner sep=0pt, on chain}
]
\node[state] (x11) {$X_1^1$};
\node[state] (x12) {$X^2_1$};
\node[state] (x13) {$X^3_1$};
\node[state] (x14) {$X^4_1$};
\node[state] (x15) {$X^5_1$};
%
\node[state, below= of x11,
label=left:{$s=3$}] % <---
(x21) {$X^1_2$};
\node[state] (x22) {$X^2_2$};
\node[state] (x23) {$X^3_2$};
\node[state] (x24) {$X^4_2$};
\node[state] (x25) {$X^5_2$};
%
\node[state, below= of x21] (x31) {$X^1_3$};
\node[state] (x32) {$X^2_3$};
\node[state] (x33) {$X^3_3$};
\node[state] (x34) {$X^4_3$};
\node[state] (x35) {$X^5_3$};
\draw (x11) edge ["?"] (x21)
(x11) edge (x22)
(x13) edge (x24)
(x13) edge (x25)
(x15) edge (x23)
(x22) edge (x33)
(x22) edge (x31)
(x23) edge (x32)
(x25) edge (x34)
(x25) edge (x35)
;
\end{tikzpicture}
\end{document}