How to put text at the end of a line (outmost right) in an align* environment? I have a set of equations in align* and at the end of each line I want to write a little bit text which explains that line. And I want it to be at the right of each line.
1 Answer
There are two different kinds of objects that can adorn an equation:
- a number or tag or
- an “explanation”.
The number or tag doesn't belong in the equation: it's just a convenience for cross references, handier than “the third equation on page 234”.
An explanation instead is part of the equation (or the step in a derivation) and should not be flush right. The code:
\begin{alignat*}{2}
a+(b+s(c))
&=a+s(b+c) &\qquad& \text{(definition)} \\
&=s(a+(b+c)) && \text{(definition)} \\
&=s((a+b)+c)) && \text{(induction)} \\
&=(a+b)+s(c) && \text{(definition)}
\end{alignat*}
The same (ab)using \tag
:
\begin{align*}
a+(b+s(c))
&=a+s(b+c) \tag{definition} \\
&=s(a+(b+c)) \tag{definition} \\
&=s((a+b)+c)) \tag{induction} \\
&=(a+b)+s(c) \tag{definition}
\end{align*}
But this has an obvious problem: if the document class specifies leqno
, you'd get
with no warning.
A possible way out is to use flalign*
\documentclass[leqno]{article}
\usepackage{amsmath}
\usepackage{showframe}
\begin{document}
After observing that $a+(b+0)=a+b=(a+b)+0$ we can proceed to prove
the associativity of addition by induction, namely
\begin{flalign*}
&&a+(b+s(c))
&=a+s(b+c) &&\text{(definition)} \\
&&&=s(a+(b+c)) &&\text{(definition)} \\
&&&=s((a+b)+c)) &&\text{(induction)} \\
&&&=(a+b)+s(c) &&\text{(definition)}
\end{flalign*}
\end{document}
But I'd stay with the first display, for the reasons outlined at the beginning.
\documentclass
and end with\end{document}
. It'll make it easier to get you the solution(s) you want. Can you do that?\tag
does satisfy that. tex.stackexchange.com/a/27285/250119 Plus&&
is what people normally want anyway, and "right of each line" may not necessarily mean flush right. (maybe need OP to clarify)\tag
, it's buried in a comment that if the optionleqno
is chosen, the "tag" will end up on the left. So this is not foolproof. I've seen requests for flush right annotations rather often, and although most authors give in and settle for "shoved right and aligned", the request is a legitimate one and deserves a definitive answer.