tikz 图表的编译问题

tikz 图表的编译问题

正如我所说,我正在为学校编写数学书;其中一本是关于矩阵的,我对它遇到了几个问题。

这是一个很大的代码,所以我尝试总结一下:

  1. TikZ 矩阵的问题:当我尝试编译它时

    \draw [<->, yl] (A-2-4.north) to [bend left] node [arrow style mul] {$+$} (B-2-4.north);
    

    使用该tikz包和以下tikz库:

    \usepackage{tikz}
    \usetikzlibrary{decorations.pathmorphing}
    \usetikzlibrary{decorations.markings}
    \usetikzlibrary{shapes,snakes,calc,arrows}
    \usetikzlibrary{intersections,through,backgrounds}
    \usetikzlibrary{shapes.arrows,chains,positioning}
    \usetikzlibrary{matrix,decorations.pathmorphing}
    

    我明白了

    No shaped name A-2-4 is known. See the pgf package documentation for explanation
    
  2. 当我尝试编译它时(使用\include{filename}):

     \chapterimage{m2summary.pdf}
     \chapter{Respostas e soluções}
     \begin{multicols}{2}
     \section*{\textcolor{ocre}{1. Matrizes}}
     \subsection*{Exercícios de fixação}
     \begin{enumerate}[label=\arabic*.]
     \tiny{
     \item $\ds A=\begin{bmatrix} 0 & -1 & -2 \\ 1 & 0 & -1 \\ 2 & 1 & 0 \end{bmatrix}$
     }
     \end{enumerate}
     \end{multicols}
    

    表明:

    Missing $ inserted。怎么办?我尝试在没有文本的情况下进行编译,实际上,没有数学文本,但它一直显示缺少 $。我真的不知道该怎么办!

抱歉写了这么长的帖子,我只是尽量写得完整。我使用的是 WinEdt 8,MikTeX 2.9,是我这周(2014 年 2 月)安装的。

TIKZ 图片代码:

\begin{tikzpicture}
\matrix(A)[matrix of math nodes, nodes={node style ge}, left delimiter={[}, right delimiter={]}] at (0,0){
  a_{11}                         & a_{12}                         & \cdots & a_{1n}                         \\
  \node[node style sp] {a_{21}}; & \node[node style sp] {a_{22}}; & \cdots & \node[node style sp] {a_{2n}}; \\
  \vdots                         & \vdots                         & \ddots & \vdots                         \\
  a_{m1}                         & a_{m2}                         & \cdots & a_{mn}                         \\
};
\node [draw, above=10pt] at (A.north) {matriz $\color{ocre}A$};
\node [right=20pt] at (A.east) {$\color{ocre}+$};

\matrix(B)[matrix of math nodes, nodes={node style ge}, left delimiter={[}, right delimiter={]}] at (6,0){
  b_{11}                         & b_{12}                         & \cdots & b_{1n}                         \\
  \node[node style sp] {b_{21}}; & \node[node style sp] {b_{22}}; & \cdots & \node[node style sp] {b_{2n}}; \\
  \vdots                         & \vdots                         & \ddots & \vdots                         \\
  b_{m1}                         & b_{m2}                         & \cdots & b_{mn}                         \\
};
\node [draw, above=10pt] at (B.north) {matriz $\color{ocre}B$};

\matrix(C)[matrix of math nodes, nodes={node style ge}, left delimiter={[}, right delimiter={]}] at (6,-4.5){
  c_{11}                              & c_{12}                               & \cdots & c_{1n}                                \\
  \node[node style sp, ocre] {c_{21}}; & \node[node style sp, blue] {c_{22}}; & \cdots & \node[node style sp, yl] {c_{2n}}; \\
  \vdots                              & \vdots                               & \ddots & \vdots                                \\
  c_{m1}                              & c_{m2}                               & \cdots & c_{mn}                                \\
};
\node [draw, below=10pt] at (C.south) {matriz $\color{ocre}C=A+B$};

\node (a) [above=10pt] at (A-2-1.north) {};
\node (b) [above=10pt] at (C-2-1.north) {};

\draw [<->, yl] (A-2-4.north) to [bend left] node [arrow style mul] {$+$} (B-2-4.north);
\draw [->, yl] (B-2-4.south) to (C-2-4.north);

\draw [<->, blue] (A-2-2.north) to [bend left] node [arrow style mul] {$+$} (B-2-2.north);
\draw [->, blue] (B-2-2.south) to (C-2-2.north);

\draw [<->, ocre] (A-2-1.north) to [bend left] node [arrow style mul] {$+$} (B-2-1.north);
\draw [->, ocre] (B-2-1.south) to (C-2-1.north);
\end{tikzpicture}

答案1

(这只回答了 TikZ 问题。对于其他问题,我建议将代码简化为最小工作示例(MWE)并就此提出一个新问题。)

您的问题是您有一个matrix of math nodes,但您\node {}在单元格中使用。默认情况下,当您有一个matrix of( math)时,TikZ 会在单元格内容前面nodes添加类似内容(并在其后添加结束符),但\node [name=A-1-2] {};不是当你\node在单元格中使用或类似内容时。引用手册:

从概念上讲,此键\node{在每个单元格的开头和};结尾添加,并将anchor节点的设置为base。此外,它还name为每个节点添加选项 option,其中名称设置为 矩阵名称-行号-列号。例如,如果矩阵的名称为my matrix,则左上角单元格中的节点将命名为 my matrix-1-1

[...]

如果您的单元格以\path命令或任何扩展为 的命令开头\path,其中包括\draw\node\fill其他命令,则 \node{启动代码和};代码将被抑制。

为了能够将选项/样式传递给节点,请写入例如

|[my node style]| content of matrix cell

即在包含选项的括号周围添加竖线,并将其放在单元格的开头。

下面是完整代码。您没有添加样式定义,因此我将它们定义为空样式。

在此处输入图片描述

\documentclass[11pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix}

\tikzset{
  node style ge/.style={},
  node style sp/.style={},
  yl/.style={},
  arrow style mul/.style={},
}
\definecolor{ocre}{RGB}{204, 119, 34}
\begin{document}

\begin{tikzpicture}
\matrix(A)[matrix of math nodes, nodes={node style ge}, left delimiter={[}, right delimiter={]}] at (0,0){
  a_{11}                         & a_{12}                         & \cdots & a_{1n}                         \\
 | [node style sp]| a_{21} & |[node style sp]| a_{22} & \cdots & |[node style sp]| a_{2n} \\
  \vdots                         & \vdots                         & \ddots & \vdots                         \\
  a_{m1}                         & a_{m2}                         & \cdots & a_{mn}                         \\
};
\node [draw, above=10pt,font=\color{ocre}] at (A.north) {matriz $A$};
\node [right=20pt,font=\color{ocre}] at (A.east) {$+$};

\matrix(B)[matrix of math nodes, nodes={node style ge}, left delimiter={[}, right delimiter={]}] at (6,0){
  b_{11}                         & b_{12}                         & \cdots & b_{1n}                         \\
  |[node style sp]| b_{21} & |[node style sp]| b_{22} & \cdots & |[node style sp]| b_{2n} \\
  \vdots                         & \vdots                         & \ddots & \vdots                         \\
  b_{m1}                         & b_{m2}                         & \cdots & b_{mn}                         \\
};
\node [draw, above=10pt,font=\color{ocre}] at (B.north) {matriz $B$};

\matrix(C)[matrix of math nodes, nodes={node style ge}, left delimiter={[}, right delimiter={]}] at (6,-4.5){
  c_{11}                              & c_{12}                               & \cdots & c_{1n}                                \\
  |[node style sp,ocre]| c_{21} & |[node style sp, blue]| c_{22} & \cdots & |[node style sp, yl]| c_{2n} \\
  \vdots                              & \vdots                               & \ddots & \vdots                                \\
  c_{m1}                              & c_{m2}                               & \cdots & c_{mn}                                \\
};
\node [draw, below=10pt,font=\color{ocre}] at (C.south) {matriz $C=A+B$};

\node (a) [above=10pt] at (A-2-1.north) {};
\node (b) [above=10pt] at (C-2-1.north) {};

\draw [<->, yl] (A-2-4.north) to [bend left] node [arrow style mul] {$+$} (B-2-4.north);
\draw [->, yl] (B-2-4.south) to (C-2-4.north);

\draw [<->, blue] (A-2-2.north) to [bend left] node [arrow style mul] {$+$} (B-2-2.north);
\draw [->, blue] (B-2-2.south) to (C-2-2.north);

\draw [<->] (A-2-1.north) to [bend left] node [arrow style mul] {$+$} (B-2-1.north);
\draw [->] (B-2-1.south) to (C-2-1.north);
\end{tikzpicture}
\end{document}

相关内容