将对齐环境的列设置为与边距固定距离

将对齐环境的列设置为与边距固定距离

我想按照以下样式设置样稿这个答案 右列与左边缘保持恒定距离,这样解释就会始终出现在文档中我所拥有的许多证明中。FWIW,我正在使用fleqn选项article.cls

是否有某个地方的扩展align可以实现这个功能?

答案1

这种方法通过使用flalign并保持与等式最右侧文本部分右边距的固定距离来工作。进行一些调整以考虑标签使用calc尺寸表达式的软件包功能。

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

右对齐

相关内容