
我有一個關於對齊方程內的文本的問題。我對方程式的對齊方式很滿意,我想讓一些文字不變成斜體。在程式碼中,我希望將“where”統一化。另外,我想將第二個等號彼此對齊,但我稍後會解決這個問題。
(MWE 提供者:塞巴斯蒂亞諾)
\documentclass[a4paper]{article}
\usepackage{mathtools}
\begin{document}
Aligning equal signs. Example.
\begin{equation}
\begin{split}
y_{destr} & = nL\lambda/2d, \text{where}\,\, n= \pm 1, \pm 3, \pm 5, \ldots \\
y_{constr} & = nL\lambda/d, \text{where}\,\, n = 0, \pm1, \pm2, \pm3, \ldots\\
\end{split}
\end{equation}
\end{document}
答案1
如前所述,\text
宏是實現此目的的工具。我想您還想使用\mathrm
(或\text
) 作為 s 的下標y
。並使用\dots
代替...
.
對於對齊,alignat
環境可以幫助您在兩個等號處對齊。
另外,(1)
和(2)
是方程式編號嗎?如果是這樣,不要手動寫出來,只需使用*
末尾不帶 a 的數學環境,它們會自動編號。
最後,不要以 結束最後一行align
(或類似行)\\
,這會在數學顯示後給您帶來不必要的垂直空間(以及編號方程式的額外數字)。
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{alignat}{2}
y_{\mathrm{destr}} &= nL\lambda/2d, \text{ where } & n &= \pm 1, \pm 3, \pm 5, \dots \\
y_{\mathrm{constr}} &= nL\lambda/d, \text{ where} & n &= 0, \pm1, \pm2, \pm3, \dots
\end{alignat}
\end{document}
正如 Sam Carter 所建議的,最好在 處對齊where
而不是第二個=
。或者,如果第二個n
是比第一個更寬的符號/更長的表達式n
,那麼您可以在where
和處對齊=
。但在這種情況下這不會有什麼不同。
\documentclass{article}
\usepackage{amsmath}
\begin{document}
Align at where:
\begin{alignat}{2}
y_{\mathrm{destr}} &= nL\lambda/2d, &&\text{ where } n = \pm 1, \pm 3, \pm 5, \dots \\
y_{\mathrm{constr}} &= nL\lambda/d, &&\text{ where } n = 0, \pm1, \pm2, \pm3, \dots
\end{alignat}
Align at where and =:
\begin{alignat}{3}
y_{\mathrm{destr}} &= nL\lambda/2d, &&\text{ where } & n &= \pm 1, \pm 3, \pm 5, \dots \\
y_{\mathrm{constr}} &= nL\lambda/d, &&\text{ where } & n &= 0, \pm1, \pm2, \pm3, \dots
\end{alignat}
\end{document}