
我是 TikZ 的新手,我正在嘗試使用align
環境來對齊一些文本,然後使用一些 TikZ 線在其上繪製一些內容。
alignment
但問題是,每當我嘗試將環境放入 TikZ 圖片中時,pdfLaTeX 都會產生錯誤。
這是我的程式碼:
\begin{figure}
\centering
\begin{tikzpicture}
\begin{align}
\notag &a_1,\ &b_1,\ &c_1,\ &d_1,\ &e_1\ \mbox{etc.}\\
\notag &a_2,\ &b_2,\ &c_2,\ &d_2,\ &e_2\ \mbox{etc.}
\end{align}
%% draw some stuff using tikz on the the aligned text.
\end{tikzpicture}
\end{figure}
但我總是收到這個錯誤:
! Missing \endgroup inserted.
<inserted text>
\endgroup
l.358 \end{align}
PS 如果我將align
TikZ 環境置於外部,則一切正常。
答案1
這不僅僅是一個問題,align
幾乎所有其他非tikz
建築都存在這個問題。您需要進入tikz
一種需要普通 LaTeX 命令的情況。其中之一是節點的標籤。現在,為了進一步防止 的tikz
解析,您可以將材料包含在 a 中,minipage
如下所示。例如,非 AMS 也會出現類似的問題displaymath
。
\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node at (0,0) {
\begin{minipage}{0.9\linewidth}
\begin{align}
\notag &a_1,\ &b_1,\ &c_1,\ &d_1,\ &e_1\ \mbox{etc.}\\
\notag &a_2,\ &b_2,\ &c_2,\ &d_2,\ &e_2\ \mbox{etc.}
\end{align}
\end{minipage}
};
%% draw some stuff using tikz on the the aligned text.
\end{tikzpicture}
\end{document}
答案2
在裡面tikzpicture
你應該說tikz
語言。這可以放在 anode
和 a minipage
。
\documentclass{article}
\usepackage{amsmath,tikz}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\node at (0,0) {%
\begin{minipage}{5cm}%adjust width here
\begin{align}
\notag &a_1,\ &b_1,\ &c_1,\ &d_1,\ &e_1\ \mbox{etc.}\\
\notag &a_2,\ &b_2,\ &c_2,\ &d_2,\ &e_2\ \mbox{etc.}
\end{align}
\end{minipage}
};
%% draw some stuff using tikz on the the aligned text.
\end{tikzpicture}
\end{figure}
\end{document}