在枚舉環境中使用對齊時出現問題

在枚舉環境中使用對齊時出現問題

我正在創建一個枚舉正數和負數的列表,並且希望這些數字彼此對齊,即全部位於同一列中。我還有第二個包含小數的列表,我想將小數點排列起來。我嘗試在枚舉列表中使用 \begin{align} ,如下所示

\begin{enumerate}
\begin{align*}[t]
\item $-&2$
\item $3$
\item $-18$
\item $83.2$
\item $-112.2$
\end{align*}
\end{enumerate}

但它給了我錯誤 \begin{aligned} 僅允許在數學模式下。我已經加載了 amsmath 包,並且正在使用 xelatex 進行編譯。

編輯:即使我已經註解掉了問題區域,xelatex 現在也會給我這個錯誤。

答案1

\item您不能在數學模式下使用,因此您的構造:

\begin{enumerate}
\begin{align*}[t]
\item $-&2$
\item $3$
...
\end{enumerate}

會產生錯誤。

為了獲得所需的排列(具有枚舉行的類似表格的材料以及某些列在小數分隔符處的對齊方式),您可以使用一個tabular環境;對齊可以使用以下方式實現siunitx包裹:

\documentclass{article}
\usepackage{siunitx}

\newcounter{tmp}

\begin{document}

\noindent\begin{tabular}{>{\stepcounter{tmp}\thetmp}lSS[table-format = 3.4]}
& 6 & 2.3456 \\
& -7 & 34.2345 \\
& 20 & -6.7835 \\
& -12 & 90.473 \\
\end{tabular}

\end{document}

在此輸入影像描述

這裡還有另外兩種選擇:一種是僅使用align(從amsmath包中),另一種是使用標準tabular

\documentclass{article}
\usepackage{amsmath}
\usepackage{array}

\newcounter{tmp}

\begin{document}

\noindent Using \texttt{align*}:
\begin{align*}
1 && 6 && 2.3456 \\
2 && -7 && 34.2345 \\
3 && 20 && -6.7835 \\
4 && -12 && 90.473\phantom{0} \\
5 && 10 && 3.4\phantom{000} 
\end{align*}

\noindent Using \texttt{tabular}:

\setcounter{tmp}{0}
\noindent\begin{tabular}{@{}>{\stepcounter{tmp}\thetmp}lrr@{.}l}
& 6 & 2 &3456 \\
& -7 & 34 & 2345 \\
& 20 & -6 & 7835 \\
& -12 & 90 & 473 \\
& 10 & 3 & 4 
\end{tabular}
\end{document}

在此輸入影像描述

請注意,第一個解決方案(使用siunitx)意味著更少的工作。

相關內容