TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to center-align a series of equations and then align their comments (which are themselves to be right-justified (except not all of them!). I'm slightly overwhelmed by the numerous options available for alignment of equations and can't seem to find an appropriate example (online or in the docs). Thanks for your help/suggestions in advance.

\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}

enter image description here

share|improve this question
    
"All '0's in alignment" means they're "left-aligned"... – Werner Mar 2 at 21:48
    
i think you want to put && before the zeros so that they will be left-aligned. (this has been asked before. i'll look for the question.) – barbara beeton Mar 2 at 22:12
    
potential duplicate: Align-environment: Align on the left side – barbara beeton Mar 2 at 22:14
up vote 3 down vote accepted

Here is a way to do it: I defined an \eqmathbox command, derived from the \eqmakebox command. manually, I could align the last equation. I also replaced the horizontal dots with \vdotswithin{=} from math tools:

\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} 

enter image description here

share|improve this answer
    
Hi @Bernard. Looks great but is there a way to consolidate eqn #s (1)-(6) under just one eqn #. Secondly, (low on priority), can the comment of (7) be right justified? – Will Tech Mar 5 at 20:02
    
It is normally right justified. I purposely right justified the whole group of equations 1–7, with the same width of the comment box, hence the shortest comments do not look right aligned (the box is right aligned, and comments are left-aligned in their box). To have on number only, unfortunately, there doesn't exist a flaligned environment, so I had to cheat with a series of \notag at every equation, excepts the middle one. See my modified answer. – Bernard Mar 5 at 20:23

The following seems to achieve what you're after:

enter image description here

\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}

The vertical rules denote the text block boundary as indicated by showframe.

share|improve this answer
    
This looks really good, @Werner. One issue I have is with eqns (1) and (2) not in alignment about ``=" when using the construct suggested by @Bernard in the post tex.stackexchange.com/questions/292790/…. Eqn (2) needs a right-justified comment that matches that of the last comment in (1). – Will Tech Mar 5 at 20:23
    
@WillTech: I've updated my answer to accommodate your request. – Werner Mar 6 at 6:30

If you want to align the second column, you should add an extra &. The odd & characters are used to vertically align your equations and the even ones create a separation (fill) between the columns.

I can't get the flalign to work on my computer, so here a quick example with align. It shouldn't be heard to implement this in your document as well.

\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}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.