TikZ 矩阵库编译错误“Missing } inserted”

TikZ 矩阵库编译错误“Missing } inserted”

我只是尝试一个非常简单的例子:

\documentclass[tikz]{standalone}
\usetikzlibrary{matrix}

\begin{document}
\begin{tikzpicture}
\matrix (m) [matrix of nodes] {a};
\end{tikzpicture}
\end{document}

然后,当我编译时,它会给出一长串错误列表,首先是以下几个错误:

! Missing } inserted.
<inserted text> 
                }
l.7 \end{tikzpicture}
                     
I've inserted something that you may have forgotten.
(See the <inserted text> above.)
With luck, this will get me unwedged. But if you
really didn't forget anything, try typing `2' now; then
my insertion and my current dilemma will both disappear.

然后以下错误重复多次

! Missing \cr inserted.
<inserted text> 
                \cr 
l.7 \end{tikzpicture}
                     
I'm guessing that you meant to end an alignment here.

! Misplaced \cr.
<inserted text> \cr 
                    
l.7 \end{tikzpicture}
                     
I can't figure out why you would want to use a tab mark
or \cr or \span just now. If something like a right brace
up above has ended a previous alignment prematurely,
you're probably due for more error messages, and you
might try typing `S' now just to see what is salvageable.

仅当我使用该\matrix命令时才会发生这种情况。 Tikz 在任何其他命令上编译都没有任何问题。 有人知道为什么会发生这种情况吗? 谢谢。

答案1

矩阵的每一行都需要以 - 终止,\\即使只有一行。

\documentclass[tikz]{standalone}
\usetikzlibrary{matrix}

\begin{document}
\begin{tikzpicture}
\matrix (m) [matrix of nodes] {a\\};
\end{tikzpicture}
\end{document}

相关内容