
如果這個線程看起來與許多其他線程相似,我很抱歉,但我無法找到解決我的問題的好方法。基本上,我想對齊一些方程,但我也希望將這些方程分成幾行,並使用類似的不同點縮排(例如,請參閱有兩個斷點的方程式 4):
主要問題是,對於alignat
,&
不是一個簡單的標記來表示“將這一點與這一點對齊”,而是&
真正界定列。因此,如果前後一行太長,則會導致同一列中的所有其他元素變長。
現在,我透過到處放置\nonumber
(因此這意味著(2)
當行數為偶數時,等式編號不會在等式中居中)來解決我的問題\hspace{<find the good space in 5 tries>}
,但這確實不實用/優雅。
您有更好的解決方案嗎?這是一個 MWE,開頭是我的「理想語法」:
\documentclass{article}
\usepackage{mathtools}
\begin{document}
My ideal syntax:
% \begin{align}
% 2\times(1+\dots+10) &= 2 \times (1+2+3+4+5+6+7+8+9+10)\\
% &=
% \begin{split}
% 2 \times (&1+2+3+4\\
% &+5+6+7+8+9+10)\\
% \end{split}
% &=
% \begin{split}
% (1+1) \times (&3+7\\
% &+11+7+8+19)
% \end{split}
% &=
% \begin{split}
% (1+1) \times (&1+2+&(3
% & &+4)\\
% &+ 11+7+8+19)
% \end{split}
% \end{align}
My more or less ideal result:
\begin{align}
2\times(1+\dots+10) &= 2 \times (1+2+3+4+5+6+7+8+9+10)\\
&= 2 \times (1+2+3+4\\
&\hspace{10mm} +5+6+7+8+9+10)\nonumber\\
&= (1+1) \times (3+7\\
&\hspace{20mm}+ 11+7+8+19)\nonumber\\
&= (1+1) \times (1+2+(3\nonumber\\
&\hspace{33mm}+ 4)\\
&\hspace{20mm}+ 11+7+8+19)\nonumber
\end{align}
\end{document}
- 編輯 -
建議的解決方案很棒,除非我使用一個為我添加括號的巨集。例如,考慮下圖。我希望第一行右側的括號位於第二行。如果我加上換行符,那麼它會單獨出現在第三行,這不是我所期望的。如果我在\pr
.是否可以在不插入alignedat
巨集內部的情況下使該程式碼工作? (我喜歡有環境,因為它使縮排自動,而且我找不到如何產生環境命令pr
...
\documentclass{article}
\usepackage{mathtools}
\usepackage{etoolbox}
\newcommand*{\pr}[2][]{\Pr_{\substack{#1}}[\,#2\,]}
\begin{document}
\begin{align}
&\pr[a \leftarrow \{0,1\}]{
\begin{alignedat}[t]{2}
&\forall x\\
& \pr[b \leftarrow \{0,1\}]{b = a} \geq \delta
\end{alignedat}}+\alpha\\
&\geq \eta
\end{align}
\end{document}
謝謝!
答案1
您可以嵌套alignedat
環境。
\documentclass{article}
\usepackage{mathtools}
\begin{document}
\begin{alignat}{2}
2\times(1+\dots+10) &= 2 \times (1+2+3+4+5+6+7+8+9+10)\\
&=
\begin{alignedat}[t]{2}
2 \times (&1+2+3+4\\
&+5+6+7+8+9+10)
\end{alignedat}\\
&=
\begin{alignedat}[t]{2}
(1+1) \times (&3+7\\
&+11+7+8+19)
\end{alignedat}\\
&=
\begin{alignedat}[t]{2}
(1+1) \times (&1+2+
\begin{alignedat}[t]{2}
&(3\\
&+4)
\end{alignedat}\\
&+ 11+7+8+19)
\end{alignedat}
\end{alignat}
\end{document}