
我試圖在以下兩個方程中對齊等號和加/減運算子:
S = 1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6 + 1/7 - 1/8 + ...
S/2 = 1/2 - 1/4 + 1/6 - 1/8 + ...
我想將分數與相同的分母對齊,但似乎無法使其與alignat一起使用;這是我到目前為止所擁有的:
\begin{alignat*}{6}
S &= 1 &- \frac{1}{2} + \frac{1}{3} &- \frac{1}{4} + \frac{1}{5} &- \frac{1}{6} + \frac{1}{7} &- \frac{1}{8} + \frac{1}{9} &- \frac{1}{10} + \cdots\\
\frac{1}{2}S &= &+ \frac{1}{2} &- \frac{1}{4} &+ \frac{1}{6} &- \frac{1}{8} &+ \frac{1}{10}
\end{alignat*}
感謝您的任何幫助,您可以提供。
答案1
你必須明白,在align
和alignat
環境中,對於n
對齊點,需要2n – 1
使用&符號:第一個是引入一個訥列(從第二列開始),下一個用於其列內的對齊點。我還刪除了第二行中的首字母+
:第二個對齊點現在是分數,我必須在–
分數前面的每一側添加一對大括號,以便 LaTeX 將其視為二元運算子有自己的間距,而不是像一元運算子sign
。 (TeX 對二元和一元運算子有不同的間距規則,以符合良好的排版習慣。)
\documentclass{article}
\usepackage{mathtools}
\begin{document}
\begin{alignat*}{6}
S
& = 1 & {} - {}
& \frac{1}{2} + \frac{1}{3}
&& - \frac{1}{4} + \frac{1}{5}
&& - \frac{1}{6} + \frac{1}{7}
&& - \frac{1}{8} + \frac{1}{9}
&& - \frac{1}{10} + \cdots\\%
\frac{1}{2}S
& = &
& \frac{1}{2}
&& - \frac{1}{4}
&& + \frac{1}{6}
&& - \frac{1}{8}
&& + \frac{1}{10}
\end{alignat*}
\end{document}
答案2
您可能會發現以下僅使用該array
套件的解決方案具有指導意義。
此解決方案中使用的環境array
有 23 個獨立的列:12 個用於第一項和數字,11 個用於=
、+
和-
符號。乍一看,這似乎有很多列。從好的方面來說,請注意,沒有必要{}
在各個位置插入(“空數學原子”)只是為了告訴 LaTeX-
和+
符號是二進制運算符而不是一元運算符。另一個好處是您擁有完全的靈活性:例如,如果您需要添加第三行,並且某些列中的條目在第二列中保留為空白,則您根本不需要更改設定。
\documentclass{article}
\usepackage{array}
\newcolumntype{R}{>{\displaystyle}r} % automatically in display math style
\newcolumntype{O}{>{{}}c<{{}}} % "O" for "operator" ...
\begin{document}
\[
\setlength\arraycolsep{0pt} % no need for extra intercolumn whitespace
\begin{array}{*{11}{RO}R}
S &=& 1 &-& \frac{1}{2} &+& \frac{1}{3} &-& \frac{1}{4} &+& \frac{1}{5}
&-& \frac{1}{6} &+& \frac{1}{7} &-& \frac{1}{8} &+& \frac{1}{9}
&-& \frac{1}{10}&+& \cdots \\[2.5ex]
\frac{1}{2}S
&=& & & \frac{1}{2} & & &-& \frac{1}{4} & &
&+& \frac{1}{6} & & &-& \frac{1}{8} & &
&+& \frac{1}{10}
\end{array}
\]
\end{document}
答案3
您可以使用新的套件,並增加了從第二行第一項中autoaligne
刪除符號的技巧。+
該\f
巨集只是為了精簡輸入。如果空項也可以用間隔的操作符號來表示,那就更好了;唉,這似乎不起作用。儘管如此,對齊的輸入比這麼多&
符號要清晰得多。
\documentclass{article}
\usepackage{amsmath}
\usepackage{autoaligne}
%% A trick for an empty delimiter
\newcommand{\makeempty}[1]{%
\begingroup\lccode`~=`#1 \lowercase{\endgroup\def~}{\mathbin{\phantom{+}}}%
\mathcode`#1="8000
}
\begin{document}
\[
\newcommand{\f}[1]{\dfrac{1}{#1}}
\aavcoeff{2.5}
\makeempty{V}
\definirseparateurs{\\}{+||-||V||=}{}
\autoaligne{
S = 1 - \f{2} + \f{3} - \f{4} + \f{5} - \f{6} + \f{7} - \f{8} + \f{9} - \f{10} + \dotsb \\
\f{2}S = V \f{2} +- \f{4} ++ \f{6} +- \f{8} ++ \f{10} + \dotsb
}
\]
\end{document}
答案4
如果您遇到困難,可以使用\phantom
s「填補空白」:
\documentclass{article}
\begin{document}
\[
\renewcommand{\arraystretch}{2}
\begin{array}{l}
\phantom{\frac{1}{2}}S =
\displaystyle 1 - \frac{1}{2} + \frac{1}{3} - \frac{1}{4} + \frac{1}{5} - \frac{1}{6} + \frac{1}{7} - \frac{1}{8} + \frac{1}{9} - \frac{1}{10} + \cdots \\
\frac{1}{2}S =
\displaystyle \phantom{1-{}}\frac{1}{2} \phantom{{}+\frac{1}{3}} - \frac{1}{4} \phantom{{}+\frac{1}{5}}
+ \frac{1}{6} \phantom{{}+\frac{1}{7}} - \frac{1}{8} \phantom{{}+\frac{1}{9}} + \frac{1}{10} \cdots
\end{array}
\]
\end{document}