對齊 TikZ 內的環境

對齊 TikZ 內的環境

我是 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 如果我將alignTikZ 環境置於外部,則一切正常。

答案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}

在此輸入影像描述

相關內容