编辑:

编辑:

在我教授的暑期课程开始之前,我决定试着整理一下我的笔记,我已经有 4-5 个月没有以任何方式、形式或风格来整理了。然而,在这段时间里,随着新更新的上线,我更新了 latex 软件包(使用 miktex 2.9)。我有大量包含 tikzpictures 的讲座,其一般形式如下(所有这些讲座都曾经编译得很完美):

  \documentclass{article}

   \usepackage{tikz}
      \usetikzlibrary{snakes,shapes,arrows,matrix,positioning}

      \begin{document}

  \begin{figure}[h]
  \centering
  \rule[-1.25cm]{0pt}{3.25cm}
    \begin{tikzpicture}[>=stealth,->,shorten >=1.5pt,line width=0.75pt]
   \matrix (a) [matrix of nodes,row sep=0.5em, column sep=3em]
   { \node[circle,draw,font=\small,minimum width=1cm] {\sffamily{1}};  &   \node[circle,draw,font=\small,minimum width=1cm]{\sffamily{2}}; &  \node[circle,draw,font=\small,minimum width=1cm]    {\sffamily{3}}; \\};
 \path[>=stealth,font=\small] (a-1-1) edge node[below] {$S_o$} (a-1-2);
 \path[>=stealth,font=\small] (a-1-2) edge node[below] {$S_1$} (a-1-3);
 \path[>=stealth,->,font=\small] (a-1-2) edge [bend right=50] node [above,near start] {$S_1F_2$} (a-1-1) ;
 \path[>=stealth,->,font=\small] (a-1-3) edge [bend right=55] node [above,near start] {$S_2F_3$} (a-1-1) ;
    \end{tikzpicture}
  \end{figure}

\end{document}

当我尝试编译前面的 MWE 时,我收到各种错误消息,例如“不知道名为 a-1-1 的形状......”等等。

我觉得这很奇怪,因为很明显,当它之前编译完美时,所述形状是已知的。我猜有些东西已经改变了。

任何显而易见的见解/指示都深受欢迎。

答案1

v3之后情况发生了变化tikz

  \documentclass{article}

   \usepackage{tikz}
      \usetikzlibrary{snakes,shapes,arrows,matrix,positioning}
   \tikzset{mynode/.style={circle,draw,font=\small,minimum width=1cm,font=\sffamily}
   }
      \begin{document}

  \begin{figure}[h]
  \centering
  \rule[-1.25cm]{0pt}{3.25cm}
    \begin{tikzpicture}[>=stealth,->,shorten >=1.5pt,line width=0.75pt]
   \matrix (a) [matrix of nodes,row sep=0.5em, column sep=3em]
    {|[mynode]|1  &   |[mynode]|2 &  |[mynode]|3 \\};
 \path[>=stealth,font=\small] (a-1-1) edge node[below] {$S_o$} (a-1-2);
 \path[>=stealth,font=\small] (a-1-2) edge node[below] {$S_1$} (a-1-3);
 \path[>=stealth,->,font=\small] (a-1-2) edge [bend right=50] node [above,near start] {$S_1F_2$} (a-1-1) ;
 \path[>=stealth,->,font=\small] (a-1-3) edge [bend right=55] node [above,near start] {$S_2F_3$} (a-1-1) ;
    \end{tikzpicture}
  \end{figure}

\end{document}

enter image description here

顺便说一句,\sffamily{1}这是错误的,因为\sffamily这是一个开关。font=\sffamily而是用作节点的选项。

编辑:

您可以通过将属性放入 来自定义每个节点\tikzset。这样,您就可以更好地控制各个节点。

  \documentclass{article}

   \usepackage{tikz}
      \usetikzlibrary{snakes,shapes,arrows,matrix,positioning}
   \tikzset{mynode/.style={circle,draw,font=\small,minimum width=1cm,font=\sffamily},
            every node/.style={minimum width=1cm},
            firstnode/.style={ellipse,draw,font=\small\sffamily,fill=red!10}, 
            secondnode/.style={ellipse,draw,font=\small\sffamily,fill=green!10},
            thirdnode/.style={ellipse,draw,font=\small\sffamily,fill=brown!10},
            fourthnode/.style={ellipse,draw,font=\small\sffamily,fill=black!10}
   }
      \begin{document}

  \begin{figure}[h]
  \centering
  \rule[-1.25cm]{0pt}{3.25cm}
    \begin{tikzpicture}[>=stealth,->,shorten >=1.5pt,line width=0.75pt]
   \matrix (a) [matrix of nodes,row sep=0.5em, column sep=3em]
    {|[firstnode]|1  &   |[secondnode]|2 &  |[thirdnode]|3 \\};
 \path[>=stealth,font=\small] (a-1-1) edge node[below] {$S_o$} (a-1-2);
 \path[>=stealth,font=\small] (a-1-2) edge node[below] {$S_1$} (a-1-3);
 \path[>=stealth,->,font=\small] (a-1-2) edge [bend right=50] node [above,near start] {$S_1F_2$} (a-1-1) ;
 \path[>=stealth,->,font=\small] (a-1-3) edge [bend right=55] node [above,near start] {$S_2F_3$} (a-1-1) ;
    \end{tikzpicture}
  \end{figure}

\end{document}

enter image description here

这样,这些样式就可以在所有地方使用tikzpictures

相关内容