多个方程及其注释的对齐

多个方程及其注释的对齐

我需要将一系列方程式居中对齐,然后对齐它们的注释(注释本身需要右对齐(但不是全部!))。我对可用于对齐方程式的众多选项感到有点不知所措,似乎找不到合适的示例(在线或在文档中)。提前感谢您的帮助/建议。

\documentclass[12pt, leqno]{book}
\usepackage{mathtools,amsthm}

\begin{document}
\noindent 2-parter: First, eqns. (1) and (2) should be in alignment (centered on page). 
 Here, (1) is pushed/pulled left while (2) is perfect. Secondly, the last comment 
 ($0 < r_{k} < r_{k-1},$) of (1) should be right-justified as is the comment of (2), with 
 the final form then being all ``0"s in alignment.
 \begin{flalign}
    \begin{aligned}
             a &= qb + r,               &0 < r < b,                   \\
             b &= q_{1}r + r_{1},       &0 < r_{1} < r,               \\
             r &= q_{2}r_{1} + r_{2},   &0 < r_{2} < r_{1},           \\
         r_{1} &= q_{3}r_{2} + r_{3},   &0 < r_{3} < r_{2},           \\
        &\texttt{.\quad.\quad.\quad.}   &\texttt{.\quad.\quad.\quad.} \\
       r_{k-2} &= q_{k}r_{k-1} + r_{k}, &0 < r_{k} < r_{k-1},         \\
       r_{k-1} &= q_{k+1}r_{k}.
    \end{aligned}
 \end{flalign}
 %% Thanks, @Bernard for your help with the following eqn
 \begin{flalign}
    && a = qb + r, && \llap{$0 \leq r < b$,} 
 \end{flalign}
 \end{document}

在此处输入图片描述

答案1

这里有一种方法可以做到:我定义了一个\eqmathbox命令,该命令源自命令。手动,我可以对齐最后一个方程。我还用数学工具\eqmakebox替换了水平点:\vdotswithin{=}

\documentclass[12pt, leqno]{book}
\usepackage{mathtools,amsthm}
\usepackage{eqparbox}
\newcommand\eqmathbox[2][]{\llap{\eqmakebox[#1][l]{\ensuremath{\displaystyle#2}}}}


\begin{document}

\noindent 2-parter: First, eqns. (1) and (2) should be in alignment (centered on page).
Here, (1) is pushed/pulled left while (2) is perfect. Secondly, the last comment
($0 < r_{k} < r_{k-1},$) of (1) should be right-justified as is the comment of (2), with
the final form then being all ``0"s in alignment.

\begin{flalign}
  \notag & & a &= qb + r, & & \eqmathbox[C]{0 < r < b,}\\
 \notag & & b &= q_{1}r + r_{1}, & & \eqmathbox[C]{0 < r_{1} < r,} \\
 \notag & & r &= q_{2}r_{1} + r_{2}, & & \eqmathbox[C]{0 < r_{2} < r_{1},} \\
  & & r_{1} &= q_{3}r_{2} + r_{3}, & & \eqmathbox[C]{0 < r_{3} < r_{2},} \\
  \notag & & &\vdotswithin{=} & & \eqmathbox[C]{\hspace*{2em}\vdots}\\
 \notag & & r_{k-2} &= q_{k}r_{k-1} + r_{k}, & & \eqmathbox[C]{0 < r_{k} < r_{k-1},} \\
 \notag & & r_{k-1} &= q_{k+1}r_{k}.
\end{flalign}

\begin{flalign}
  && a & = qb + r,\quad &&\mathllap{0 \leq r < b,}
\end{flalign}

\end{document} 

在此处输入图片描述

答案2

以下内容似乎可以实现您所追求的目标:

在此处输入图片描述

\documentclass[leqno]{article}
\usepackage{mathtools}

\newlength{\mathlen}
\begin{document}

\settowidth{\mathlen}{$0 < r_k < r_{k-1},$}% Widest comment on the right
\newcommand{\rightcomment}[1]{\makebox[0pt][r]{\makebox[\mathlen][l]{$#1$}}}% Simplify code with a macro
\begin{flalign}
  &&          a &= qb + r,            &\rightcomment{0 < r < b,}                         \nonumber \\
  &&          b &= q_1 r + r_1,       &\rightcomment{0 < r_1 < r,}                       \nonumber \\
  &&          r &= q_2 r_1 + r_2,     &\rightcomment{0 < r_2 < r_1,}                     \nonumber \\
  &&        r_1 &= q_3 r_2 + r_3,     &\rightcomment{0 < r_3 < r_2,}                               \\
  &&            &\vdotswithin{=}      &\rightcomment{\phantom{0 < {}} \vdotswithin{r_k}} \nonumber \\
  &&    r_{k-2} &= q_k r_{k-1} + r_k, &\rightcomment{0 < r_k < r_{k-1},}                 \nonumber \\
  &&    r_{k-1} &= q_{k+1} r_k.                                                          \nonumber
\end{flalign}

For reference
\begin{equation}
  \mathmakebox[0pt]{
    \mathmakebox[\linewidth]{
      \phantom{r_{k-2}}\mathllap{a} = \mathrlap{qb + r}\phantom{q_{k}r_{k-1} + r_k,}
    }
    \rightcomment{0 \leq r < b,}
  }
\end{equation}

\end{document}

垂直规则表示文本块边界,如下所示showframe

答案3

如果要对齐第二列,则应添加一个额外的&。奇数&字符用于垂直对齐方程式,偶数字符用于在列之间创建分隔(填充)。

我无法flalign在我的计算机上运行,​​因此这里有一个简单的示例align。在您的文档中也不应该听到实现这一点。

\begin{align*}
             a &= qb + r,             & & 0 < r < b,                   \\
             b &= q_{1}r + r_{1},     & & 0 < r_{1} < r,               \\
             r &= q_{2}r_{1} + r_{2}, & & 0 < r_{2} < r_{1},           \\
         r_{1} &= q_{3}r_{2} + r_{3}, & & 0 < r_{3} < r_{2},           \\
        &\texttt{.\quad.\quad.\quad.} & & \texttt{.\quad.\quad.\quad.} \\
       r_{k-2} &= q_{k}r_{k-1} + r_{k},& &0 < r_{k} < r_{k-1},         \\
       r_{k-1} &= q_{k+1}r_{k}. \\[.6cm]
               & a = qb + r, && 0 \leq r < b
    \end{align*}
 \end{document}

在此处输入图片描述

相关内容