
在使用align*
環境的過程中,如何讓具體的數字互相配合呢?
在下面的範例中,我希望頂部總和和底部總和的每一項彼此對齊:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
2S &= 1 &+ 2 &+ 3 &+ \ldots &+ (N-2) &+ (N-1) &+ N \\
&= N &+ (N-1) &+ (N-2) &+ \ldots &+ 3 &+ 2 &+ 1
\end{align*}
\end{document}
目前,這看起來很難看:
答案1
簡單的array
一些調整:
\documentclass{article}
\usepackage{amsmath,array}
\begin{document}
\[
\begin{array}{@{}r<{{}}@{}c*{6}{@{}>{{}}c<{{}}@{}c}@{}}
2S = & 1 & + & 2 & + & 3 & + & \cdots & + & (N-2) & + & (N-1) & + & N \\
{} + & N & + & (N-1) & + & (N-2) & + & \cdots & + & 3 & + & 2 & + & 1
\end{array}
\]
\end{document}
如果要將數字與減號對齊,請新增列。
\documentclass{article}
\usepackage{amsmath,array}
\begin{document}
\[
\begin{array}{@{}r<{{}}*{21}{@{}>{{}}c<{{}}}@{}}
2S = & 1 &+& & 2 & &+& & 3 & &+& \cdots &+& (N & - & 2) &+& (N & - & 1) &+& N \\
{} + & N &+& (N & - & 1) &+& (N & - & 2) &+& \cdots &+& & 3 & &+& & 2 & &+& 1
\end{array}
\]
\end{document}
我還修正了數學。
答案2
使用正在開發的tabstackengine
,介紹於根據最寬的列編寫具有等距列的表格(sty 檔案位於測量對準),過程很簡單:
\documentclass{article}
\usepackage{tabstackengine}
\stackMath
\renewcommand\stackalignment{l}
\begin{document}
\tabbedLongstack{%
2S &= 1 &+ 2 &+ 3 &+ \ldots &+ (N-2) &+ (N-1) &+ N \\
&= N &+ (N-1) &+ (N-2) &+ \ldots &+ 3 &+ 2 &+ 1}
\end{document}
或者,按照OP的要求,外觀略有不同:
\documentclass{article}
\usepackage{tabstackengine}
\stackMath
\begin{document}
\tabbedLongstack{%
2S &=& 1 &+& 2 &+& 3 &+& \ldots &+& (N-2) &+& (N-1) &+& N \\
&=& N &+& (N-1) &+& (N-2) &+& \ldots &+& 3 &+& 2 &+& 1}
\end{document}