[Tex/LaTex] How to properly format a proof/explanation with multiple points of alignment

horizontal alignmentmath-mode

This answered question addresses how to properly align/format a proof, allowing one to add text commentary alongside equations without ruining the alignment of the equations; however, it only seems to allow for one point of alignment in the equation and one point of alignment in the text, how can we get a similar result with multiple points of alignment?

eg. points of alignment for equations are indicated by an asterisk (*)

  *aaaaaaaaa *= bbbbbbbb
= *ccccccccc *= bbbbbbbb      comment or explanatory remark.
= *ddddddddd *= bbbbbbbb      second comment or explanatory remark.

Here is a hacked approximation of what I was trying to describe:
Sample rendering approximating desired format
Here:

  • the column of \Rightarrow and = are right-aligned;
  • the LHS of the equations are right-aligned;
  • the column of = are left-aligned;
  • the RHS of the equations are left-aligned;
  • the text is also left-aligned.

Issues that I could not resolve even in this hacked example:

  1. Ideally the the text would be pushed as far to the right as possible and have minimal effect on the horizontal centering of the equations (i.e. w.r.t. the page). It would be especially nice if it were possible to specify the width of the text column in such a way that text exceeding that width would automatically format justified and multi-lined, vertically centered about the corresponding line of math, but I imagine that's a bit of a pipe dream …

  2. The final boxed form would be properly centered w.r.t. to the math above it. I realize it may not be possible to do this easily and so am open to any other means of clearly distinguishing the final form.

Best Answer

Here are two ways of doing things.

I define right aligned notes, that require using the flalign(*) environment and the \llap command. If there is enough white space to input a (short) note, you use the \shortrnote command. If there is not, you put the note on a line of its own.

Similarly, I define left aligned notes, that use the alignat(*) environment and the \rlap command. There are \shortlnote and \longlnote commands. If the note is very long, one has to replace \rlap with \clap — so that it's the middle of the note that is left aligned.

    \documentclass[ a4paper]{article}

    \usepackage[utf8]{inputenc}
    \usepackage[T1]{fontenc}
    \usepackage{lmodern}
    \usepackage{mathtools}

    \newcommand{\shortrnote}[1]{ &  & \text{\footnotesize\llap{#1}}}
    \newcommand{\longrnote}[1]{ &  &  \\ \notag  &  &  &  &  & \text{\footnotesize\llap{#1}}}

    \newcommand{\shortlnote}[1]{&\qquad & \text{\footnotesize\rlap{#1}}}
    \newcommand{\longlnote}[1]{   \\ \notag &  &  & \text{\footnotesize\rlap{#1}}}
    \newcommand{\verylonglnote}[1]{   \\ \notag &  &  & \text{\footnotesize\clap{#1}}}

    \begin{document}

    Right aligned notes result  in this :
    \begin{flalign}
     &  & xyz  & = abc \\
      &  &           abc  & = xyz  &  & \\
    \shortintertext{next math group: }
        &  &           cba &= abc \shortrnote{(A short note)} \\
        & & (x + y + z)^{2} & = x^{2} + y^{2}  + z^{2}
    \longrnote{(A longer note:  true only in characteristic 2)}
    \end{flalign}

    While left aligned notes give:
    \begin{alignat}{2}
     xyz  & = abc \\
                abc  & = xyz  \\
    \shortintertext{next math group: }
                   cba &= abc  \shortlnote{(A short note)}  \\
         (x + y + z)^{2} & = x^{2} + y^{2}  + z^{2}\longlnote{(A somewhat longer note)}\\
         (x + y + z)^{3} & = x^{3} + y^{3}  + z^{3}
     \verylonglnote{(A really longer note:  true only in characteristic 3)}
    \end{alignat}

    With two alignment points: 

    \begin{alignat}{3}
     xyz  & =  abc  &&  =  def\\
                abc  & = xyz & &  =  uvw  \\
    \shortintertext{next math group: }
                   cba & = xyzt   &  &  = acb \shortlnote{(A short note)}  \\
        (x + y + z)^{3} & =  \mathrlap{x^{3} + y^ {3} + z^{3}}    & 
   \shortlnote{(In characteristic 3)} \\
         (x + y + z)^{3} & =  \mathrlap{x^{3}+y^ {3} + z^{3}} 
   \longlnote{(True only in characteristic 3)} 
    \end{alignat}

    \end{document}​ 

enter image description here

Related Question