tikzpgfmanual 中的 x 颜色错误

tikzpgfmanual 中的 x 颜色错误

我想在 Latex 中创建流程图(sharelatex.com)。但为了尝试我需要做的事情,我首先从手册中创建一个副本。示例显示在tikzpgf手册.pdf。首先启动一个副本,我发现我缺少一些包和库。修复这些包后,我仍然在某些行上收到错误。基本上在每条路径上(我留下一条路径)。我收到的错误是

Missing \endcsname inserted.
<to be read again> \OT1\textquoteright 

Package xcolor Error: Undefined color `latex\OT1\textquoteright '.
See the xcolor package documentation for explanation.

到目前为止我的 tikz 脚本。

\documentclass{article}
%\documentclass[tikz,margin=3mm]{standalone}
\usepackage{xcolor}
\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\usepackage[utf8]{inputenc}

\begin{document}
    \begin{tikzpicture}[auto]
    \tikzstyle{decision} = [diamond, draw=blue, thick, fill=blue!20, text width=4.5em, text badly centered, inner sep=1pt]
    \tikzstyle{block} = [rectangle, draw=blue, thick, fill=blue!20,text width=5em, text centered, rounded corners, minimum height=4em]
    \tikzstyle{line} = [draw, thick, -latex’,shorten >=2pt];
    \tikzstyle{cloud} = [draw=red, thick, ellipse,fill=red!20, minimum height=2em];
    \matrix [column sep=5mm,row sep=7mm]
    {
    % row 1
    \node [cloud] (expert) {expert}; &
    \node [block] (init) {initialize model}; &
    \node [cloud] (system) {system}; \\
    % row 2
    & \node [block] (identify) {identify candidate model}; & \\
    % row 3
    \node [block] (update) {update model}; &
    \node [block] (evaluate) {evaluate candidate models}; & \\
    % row 4
    & \node [decision] (decide) {is best candidate}; & \\
    % row 5
    & \node [block] (stop) {stop}; & \\
    };
    \tikzstyle{every path}=[line]
    \path (init) -- (identify);
    %\path (identify) -- (evaluate);
    %\path (evaluate) -- (decide);
    %\path (update) |- (identify);
    %\path (decide) -| node [near start] {yes} (update);
    %\path (decide) -- node [midway] {no} (stop);
    %\path [dashed] (expert) -- (init);
    %\path [dashed] (system) -- (init);
    %\path [dashed] (system) |- (evaluate);
    \end{tikzpicture}
\end{document}

我感觉我缺少了某些包,但我不知道是哪个。如果我没有缺少包,有人能解释一下哪里出了问题吗?

答案1

有两个问题。首先,右引号不是 Ti 的一部分Z 语法,因此-latex’会出现错误。这大概就是箭头规范中想要的直引号-latex'

latex第二个问题是默认情况下未定义箭头类型。要使用它,您必须加载arrows库。但是,这已被弃用,因此最好使用它arrows.meta

\tikzstyle也已被弃用,因此最好也更新这个语法。

推荐代码:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,arrows.meta}
\usepackage[utf8]{inputenc}

\begin{document}
\begin{tikzpicture}
  [
    auto,
    decision/.style={diamond, draw=blue, thick, fill=blue!20, text width=4.5em, text badly centered, inner sep=1pt},
    block/.style={rectangle, draw=blue, thick, fill=blue!20,text width=5em, text centered, rounded corners, minimum height=4em},
    line/.style={draw, thick, -Latex,shorten >=2pt},
    cloud/.style={draw=red, thick, ellipse,fill=red!20, minimum height=2em},
  ]
  \matrix [column sep=5mm,row sep=7mm]
  {
    \node [cloud] (expert) {expert}; &
    \node [block] (init) {initialize model}; &
    \node [cloud] (system) {system}; \\
    & \node [block] (identify) {identify candidate model}; & \\
    \node [block] (update) {update model}; &
    \node [block] (evaluate) {evaluate candidate models}; & \\
    & \node [decision] (decide) {is best candidate}; & \\
    & \node [block] (stop) {stop}; & \\
  };
  \tikzset{every path/.style={line}}
  \path (init) -- (identify);
\end{tikzpicture}
\end{document}

编译输出

如果您由于某种原因不想使用上述建议,请对代码进行最少的修改:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,arrows}
\usepackage[utf8]{inputenc}

\begin{document}
\begin{tikzpicture}[auto]
  \tikzstyle{decision} = [diamond, draw=blue, thick, fill=blue!20, text width=4.5em, text badly centered, inner sep=1pt]
  \tikzstyle{block} = [rectangle, draw=blue, thick, fill=blue!20,text width=5em, text centered, rounded corners, minimum height=4em]
  \tikzstyle{line} = [draw, thick, -latex',shorten >=2pt];
  \tikzstyle{cloud} = [draw=red, thick, ellipse,fill=red!20, minimum height=2em];
  \matrix [column sep=5mm,row sep=7mm]
  {
    \node [cloud] (expert) {expert}; &
    \node [block] (init) {initialize model}; &
    \node [cloud] (system) {system}; \\
    & \node [block] (identify) {identify candidate model}; & \\
    \node [block] (update) {update model}; &
    \node [block] (evaluate) {evaluate candidate models}; & \\
    & \node [decision] (decide) {is best candidate}; & \\
    & \node [block] (stop) {stop}; & \\
  };
  \tikzstyle{every path}=[line]
  \path (init) -- (identify);
\end{tikzpicture}
\end{document}

相关内容