此代码将在我的一个主文件中编译,但不会在另一个主文件中编译。我启动了所有涉及 tikz 的相同操作,所以我不知道有什么区别。提前致谢!
\documentclass[12pt]{report}
\usepackage {fancyhdr}
\usepackage{graphicx, amssymb, changepage}
\usepackage{rotating}
\usepackage{setspace}
%\usepackage{pgnumchapter_nums}
%\usepackage{titlepg}
\usepackage{indentfirst}
\usepackage{tikz}
\usetikzlibrary{matrix}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{decorations.pathreplacing}
\usetikzlibrary{calc, fit}
\tikzstyle{vertex}=[circle, draw, inner sep=0pt, minimum size=9pt]
\begin{document}
\begin{figure}[h] %F12
\[\begin{tikzpicture}
\vertex (u1) at (-4, 0) {};
\draw [dotted, very thick] (-3.5, 0) -- (-2.5, 0);
\vertex (u2) at (-2, 0) {};
\draw[decorate, decoration={brace, amplitude=5pt}] (-0.7,-0.2)--(-4.3,-0.2);
\draw (-2.5, -.6) node {$k+2$ nodes};
\vertex (u3) at (-1.5, 0) {$v_1$};
\vertex (u4) at (-1, 0) {};
\draw [dotted, very thick] (-0.5, 0) -- (.5, 0);
\vertex (v1) at (1, 0) {};
\draw [dotted, very thick] (1.5, 0) -- (2.5, 0);
\vertex (v2) at (3, 0) {};
\draw[decorate, decoration={brace, amplitude=5pt}] (4.2,-0.2)--(0.7,-0.2);
\draw (2.5, -.6) node {$k+2$ nodes};
\vertex (v3) at (3.5, 0) {$v_l$};
\vertex (v4) at (4, 0) {};
\vertex (r1) at (5, 0) {};
\draw [dotted, very thick] (5.5, 0) -- (6.5, 0);
\vertex (rn) at (7, 0) {};
\draw[decorate, decoration={brace, amplitude=5pt}] (7.2,-0.2)--(4.7,-0.2);
\draw (6, -.6) node {$r$ nodes};
\path
(u2) edge (u3)
(u3) edge (u4)
(v2) edge (v3)
(v3) edge (v4)
(v4) edge (r1)
;
\end{tikzpicture}\]
\caption{A minimum failure set of $P_n$}
\label{fig:tikzpicture}
\end{figure}
\end{document}
答案1
请注意,下面代码中所有不必要的部分都被注释掉了。始终应发布一个最小示例。
您需要使用\node[vertex]
而不是\vertex
。使用 时,\tikzstyle
它不会像 那样定义新命令\newcommand
。因此,在此示例中,您可以vertex
在其他命令中使用 (不带反斜杠) 作为键。但无论如何您都不应该使用。请注意下面代码中的 语法,这是当前在 tikz 中定义样式的最佳实践。\node
\tikzstyle
\tikzset
\documentclass[12pt]{report}
%\usepackage {fancyhdr}
%\usepackage{graphicx, amssymb, changepage}
%\usepackage{rotating}
%\usepackage{setspace}
%\usepackage{pgnumchapter_nums}
%\usepackage{titlepg}
%\usepackage{indentfirst}
\usepackage{tikz}
%\usetikzlibrary{matrix}
%\usetikzlibrary{decorations.markings}
\usetikzlibrary{decorations.pathreplacing}
%\usetikzlibrary{calc, fit}
\tikzset{vertex/.style={circle, draw, inner sep=0pt, minimum size=9pt}}
\begin{document}
\begin{tikzpicture}
\node[vertex] (u1) at (-4, 0) {};
\draw [dotted, very thick] (-3.5, 0) -- (-2.5, 0);
\node[vertex] (u2) at (-2, 0) {};
\draw[decorate, decoration={brace, amplitude=5pt}] (-0.7,-0.2)--(-4.3,-0.2);
\draw (-2.5, -.6) node {$k+2$ nodes};
\node[vertex] (u3) at (-1.5, 0) {$v_1$};
\node[vertex] (u4) at (-1, 0) {};
\draw [dotted, very thick] (-0.5, 0) -- (.5, 0);
\node[vertex] (v1) at (1, 0) {};
\draw [dotted, very thick] (1.5, 0) -- (2.5, 0);
\node[vertex] (v2) at (3, 0) {};
\draw[decorate, decoration={brace, amplitude=5pt}] (4.2,-0.2)--(0.7,-0.2);
\draw (2.5, -.6) node {$k+2$ nodes};
\node[vertex] (v3) at (3.5, 0) {$v_l$};
\node[vertex] (v4) at (4, 0) {};
\node[vertex] (r1) at (5, 0) {};
\draw [dotted, very thick] (5.5, 0) -- (6.5, 0);
\node[vertex] (rn) at (7, 0) {};
\draw[decorate, decoration={brace, amplitude=5pt}] (7.2,-0.2)--(4.7,-0.2);
\draw (6, -.6) node {$r$ nodes};
\path
(u2) edge (u3)
(u3) edge (u4)
(v2) edge (v3)
(v3) edge (v4)
(v4) edge (r1)
;
\end{tikzpicture}
\end{document}