4

I'd like to set proofs in the style shown in this answer but with the right column at a constant distance from the left margin, so that the explanations show up consistently located in the many proofs I have in the document. FWIW, I'm using the fleqn option to article.cls.

Is there some extension to align somewhere which does this?

1 Answers1

3

Here is a method which works by using flalign and maintaining a fixed distance to the right margin of the rightmost, textual, part of the equation. Some adjustment to take into account the tag use the calc package facilities for dimension expressions.

\documentclass[letterpaper,fleqn]{article}
\usepackage{amsmath,amssymb}
\usepackage{calc}

% The default width is here set to 5cm
% I quickly checked amsmath.sty to guess a reasonable way to adjust
% for the space taken up by the equation number: I imitated  how
% \tagform@ works by default was defined, and also saw there the 
% \mintagsep command.

% It seems to work here, but I have not tested the code any further and 
% I don't know how (not) robust this code will prove to be.

\newcommand\justif[2][5cm]{&&\text{\makebox[#1-\widthof{\normalfont(\theequation)}-\mintagsep][l]{#2}}}
\begin{document}

\begin{flalign}
\quad\lvert p-q\rvert &=\sqrt{(p-q)^2} \justif{by definition of square root}\\
    &=\sqrt{p^2 -2pq +q^2}            \justif{by multiplication}\\
    &=\sqrt{p^2-2pq+q^2 +2pq -2pq}    \justif{by the additive identity}\\
    &=\sqrt{p^2+2pq+q^2 -4pq}         \justif{by grouping like terms}\\
    &=\sqrt{(p+q)^2 -4n}              \justif{by the distributive law}
\end{flalign}

\null\hfill\rule{5cm}{12pt}

\null\hfill\rule{5.5cm}{12pt}

\begin{flalign}
\quad\lvert p-q\rvert &=\sqrt{(p-q)^2} \justif[5.5cm]{by definition of square root}\\
    &=\sqrt{p^2 -2pq +q^2}            \justif[5.5cm]{by multiplication}\\
    &=\sqrt{p^2-2pq+q^2 +2pq -2pq}    \justif[5.5cm]{by the additive identity}\\
    &=\sqrt{p^2+2pq+q^2 -4pq}         \justif[5.5cm]{by grouping like terms}\\
    &=\sqrt{(p+q)^2 -4n}              \justif[5.5cm]{by the distributive law}
\end{flalign}


\end{document}

rightaligned