我想右对齐(类似 \raggedleft ?)每行的注释。我使用的是 \ \ \ \ ,效果不好。请给我一个更好的方法来写这个。我应该使用拆分还是其他什么?
\begin{align*}
& \ \ \ Opt_\rho (i,j,M)\\
&= \min_{\kappa \in Seg(i,j)} (Cost(\rho, \kappa, M))\\
& \ \ \ \ \ \ \ \ \ \text{[Comment for the line]}\\
&= \min_{1\leq l\leq i} (\min_{\kappa' \in Seg(l,j)} (Cost(\rho,\kappa',M)))\\
& \ \ \ \ \ \ \ \ \ \text{[Comment for another line]} \\
&= \min_{1\leq l\leq i} (\min_{\kappa''[l:i] \in Seg(l,j)} (\max_{\iota'' \in
\kappa''[l:i]} (||Cost(\rho, \iota'')-M||)))\\
& \ \ \ \ \ \ \ \ \ \text{[More Comments]} \\
&= \min_{1\leq l\leq i} (\min_{\kappa''[l:i] \in Seg(l,j)} (\max (\max_{\iota'' \in \kappa''} (||Cost(\rho, \iota'')-M||)), &\\
& \ \ \ ||Cost(\rho,[l:i])-M||))\\
& \ \ \ \ \ \ \ \ \ \text{[This is a long long long long comment]} \\
&= \min_{1\leq l\leq i} (\max (\min_{\kappa'' \in Seg(l,j-1)} (\max_{\iota'' \in \kappa''} (||Cost(\rho, \iota'')-M||))), &\\
& \ \ \ ||Cost(\rho,[l:i])-M||)\\
& \ \ \ \ \ \ \ \ \ \text{[Finally this comment]} \\
\end{align*}
答案1
我的第一个建议,在不了解更多信息的情况下,是使用一个flalign*
使用其最大可用宽度的环境,并将注释作为下一个对齐组的右对齐部分,大致如下所示:
\documentclass[12pt]{article}
\usepackage{amsmath}
\DeclareMathOperator{\Opt}{Opt}
\DeclareMathOperator{\Cost}{Cost}
\DeclareMathOperator{\Seg}{Seg}
\usepackage{mathtools}
\begin{document}
\begin{flalign*}
&\phantom{=\ } \Opt_\rho (i,j,M)\\
&= \min_{\kappa \in \Seg(i,j)} (\Cost(\rho, \kappa, M)) & \text{[Comment for the line]}\\
&= \min_{1\leq l\leq i} (\min_{\kappa' \in \Seg(l,j)} (\Cost(\rho,\kappa',M))) & \text{[Comment for another line]} \\
&= \min_{1\leq l\leq i} (\min_{\kappa''[l:i] \in \Seg(l,j)} (\max_{\iota'' \in
\kappa''[l:i]} (||\Cost(\rho, \iota'')-M||))) & \text{[More Comments]} \\
&= \min_{1\leq l\leq i} (\min_{\kappa''[l:i] \in \Seg(l,j)} (\max (\max_{\iota'' \in \kappa''} (||\Cost(\rho, \iota'')-M||)), &\\
&\phantom{=\ } ||\Cost(\rho,[l:i])-M||)) & \mathllap{\text{[This is a long long long long comment]}} \\
&= \min_{1\leq l\leq i} (\max (\min_{\kappa'' \in \Seg(l,j-1)} (\max_{\iota'' \in \kappa''} (||\Cost(\rho, \iota'')-M||))), &\\
&\phantom{=\ } ||\Cost(\rho,[l:i])-M||) & \text{[Finally this comment]} \\
\end{flalign*}
\end{document}
补充几点:如果注释太长,注释的“列”就会太宽,所以我习惯\mathllap
让它水平地与等式的各部分重叠;幸运的是,它应用的行并不那么长。如果太长,你可能需要把注释放在单独的一行上。
此外,我建议使用\DeclareMathOperator
诸如“Cost”和“Opt”之类的内容,因为除非以不同的方式处理,否则数学模式中的完整“单词”看起来不正确。
正如 Zarko 在评论中提到的那样,对于不同大小的页面,最佳效果会有所不同,因此,如果不进行调整,这可能无法在您的实际使用情况下发挥作用。
答案2
我提出一个基于 的解决方案\intertext
,内容左边不齐:
\documentclass{article}
\usepackage{amsmath}
\DeclareMathOperator{\Cost}{Cost}
\DeclareMathOperator{\Opt}{Opt}
\DeclareMathOperator{\Seg}{Seg}
\begin{document}
\begin{align*}
& \Opt_\rho (i,j,M)\\
& = \min_{\kappa \in \Seg(i,j)} (\Cost(\rho, \kappa, M)) \\[-3ex]
\intertext{\raggedleft [From Eq. \ref{eq:opt}]}
& = \min_{1\leq l\leq i} (\min_{\kappa' \in \Seg(l,j)} (\Cost(\rho,\kappa',M))) \\[-3ex]
\intertext{[\raggedleft From Proposition \ref{prop:minmin}]}
&= \min_{1\leq l\leq i} (\min_{\kappa''[l:i] \in \Seg(l,j)} (\max_{\iota'' \in
\kappa''[l:i]} (\|\Cost(\rho, \iota'')-M\|))) \\[-2.5ex]
\intertext{\raggedleft [Definition of $\Cost(\rho, \kappa''[l:i],M)$]}
& = \min_{1\leq l\leq i} (\min_{\kappa''[l:i] \in \Seg(l,j)} (\max (\max_{\iota'' \in \kappa''} (\|\Cost(\rho, \iota'')-M\|)), \|\Cost(\rho,[l:i])-M\|)) \\[-2.5ex]
\intertext{\raggedleft [Separating the last segment $[l:i]$]}
& = \min_{1\leq l\leq i} (\max (\min_{\kappa'' \in \Seg(l,j-1)} (\max_{\iota'' \in \kappa''} (\|\Cost(\rho,
\iota'')-M\|))), \|\Cost(\rho,[l:i])-M \|) \\[-2.5ex]
\intertext{\raggedleft [From Proposition \ref{prop:minmax}]} \\
\end{align*}
\end{document}
答案3
使用mathtools
和linegoal
包。由于您的等式相当宽,我添加了geometry
包以增加\textwidth
尺寸。
对于方程式使用align*
和split
环境。长注释写在\parbox
:
\documentclass{article}
\usepackage{geometry}
\usepackage{mathtools}
\DeclareMathOperator{\cost}{Cost}
\DeclareMathOperator{\opt}{Opt}
\DeclareMathOperator{\seg}{Seg}
\DeclarePairedDelimiterX{\norm}[1]\lVert\rVert{#1}
\usepackage{linegoal}
\begin{document}
\begin{align*}
\MoveEqLeft
\opt_\rho (i,j,M)
& = \min_{\kappa \in\seg(i,j)} (\cost(\rho, \kappa, M))
&& \text{[From Eq. \ref{eq:opt}]} \\
& = \min_{1\leq l\leq i} (\min_{\kappa' \in \seg(l,j)} (\cost(\rho,\kappa',M)))
&& \text{[From Proposition \ref{prop:minmin}]} \\
& = \min_{1\leq l\leq i} (\min_{\kappa''[l:i] \in Seg(l,j)}
(\max_{\iota'' \in \kappa''[l:i]} (\norm{\cost(\rho, \iota'')-M} )))
&& \text{[Definition of $\cost(\rho, \kappa''[l:i],M)$]} \\
\begin{split}
& = \min_{1\leq l\leq i} (\max (\min_{\kappa'' \in Seg(l,j-1)}
(\max_{\iota'' \in \kappa''}\\
&\qquad (\norm{\cost(\rho, \iota'')-M} ))), \norm{\cost(\rho,[l:i])-M})
\end{split} && \parbox{\linegoal}{\raggedright
[This is a very, very, very long comment in two lines]}
\end{align*}
\end{document}