好的,我正在用 tikz 做我的项目,其中有状态和节点。当我想生成我的节点时,它显示错误消息:Package tikz 错误:(、+、坐标、pic 或节点预期。
我的代码:
\documentclass{article}
\usepackage{pgf}
\usepackage{tikz}
\usetikzlibrary{arrows,automata}
\usepackage{iftex}
\ifPDFTeX
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\else
\ifXeTeX
\usepackage{xltxtra}
\else
\usepackage{luatextra}
\fi
\defaultfontfeatures{Ligatures=TeX}
\fi
\usetikzlibrary{positioning}
\tikzset{
state/.style={
rectangle,
rectangle split,
rectangle split parts=2,
rectangle split part fill={red!30,blue!20},
rounded corners,
draw=black, very thick,
minimum height=4em,
inner sep=3pt,
text width=2cm,
text centered,
},
}
\begin{document}
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=4cm,
semithick]
\node[state] (A) {text\\txet \nodepart{two} blue background \\ here};
\node[state] (B) [right of =A]{text\\txet \nodepart{two} blue background \\ here};
\node[state] (C) [right of=B] {text\\txet \nodepart{two} blue background \\ here};
\node[state] (D) [below right of=A] {$q_c$};
\node[state] (E) [right of=D] {$q_e$};
\node[state] (F) [right of= E] {$q_f$};
\path (A) edge node (C)
(B) edge node {OK} (E)
\end{tikzpicture}
\end{document}
我做错了什么?
答案1
嗯,请注意
错误的是:right of =A
正确的是:right=of A
问题:\node[state] (B) [A 的右侧上方,标签=左侧:$v_2$] {$5$};
没问题 \node (B) [在 A 的右侧上方,标签=左侧:$v_2$] {$5$};
\path 之后必须有 ;。
现在你的代码可以编译了。
下面你的代码进行了调整
\documentclass{article}
\usepackage{pgf}
\usepackage{tikz}
\usetikzlibrary{arrows,automata}
\usepackage{iftex}
\ifPDFTeX
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\else
\ifXeTeX
\usepackage{xltxtra}
\else
\usepackage{luatextra}
\fi
\defaultfontfeatures{Ligatures=TeX}
\fi
\usetikzlibrary{positioning}
\tikzset{
state/.style={
rectangle,
rectangle split,
rectangle split parts=2,
rectangle split part fill={red!30,blue!20},
rounded corners,
draw=black, very thick,
minimum height=4em,
inner sep=3pt,
text width=2cm,
text centered,
},
}
\begin{document}
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=4cm,
semithick]
\node (A) {text\\txet \nodepart{two} blue background \\ here};
\node (B) [right= of A]{text\\txet \nodepart{two} blue background \\ here};
\node (C) [right= of B] {text\\txet \nodepart{two} blue background \\ here};
\node (D) [below right= of A] {$q_c$};
\node (E) [right= of D] {$q_e$};
\node (F) [right= of E] {$q_f$};
\path (A) edge node {} (C)
(B) edge node {OK} (E);
\end{tikzpicture}
\结束{文档}