# Aligning multiple lines of text in an align environment

I want to use the right side of an aligned environment to present the reason for the next line. If the explanation requires more than one line the alignment fails. This could be eye-balled by adding a horizontal space but there should be a better way.

How can this be fixed?

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align}
a + b &= \quad \text{short reason} \\
c + d &= \quad \text{a really long and} \\
&\phantom{=} \quad \text{complicated reason} \notag \\
e + f \text{.}
\end{align}
\end{document}


If you compile the above code you will see what I mean. I can't figure out how to add compiled code to a question. If you know how do add compiled code to the question, please do so.

• You can make a screenshot of the result and add it as in image, clicking on the 6th icon in the edit toolbar the icon which looks like a mountain). – Bernard Jul 16 '18 at 15:06
• You might also want to add a & on line 8 before \text{.}, because currently that line of the equation is a little bit further to the left. – Flexo013 Jul 16 '18 at 15:10

One option is to use the aligned construct for the multi-line comments as below.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align}
a + b &= \quad \text{short reason} \\
c + d &= \quad \begin{aligned}[t]&\text{a really long and} \\
&\text{complicated reason}\end{aligned}\\
e + f \text{.}
\end{align}
\end{document}


• if the "long and complicated" text takes even more lines, the lines are really too far apart for it to be recognized easily as a unit. a paragraphing approach (with ragged right text) is better. – barbara beeton Jul 18 '18 at 19:49
• Notably this solution also works in mathjax, which doesn't support parbox – Migwell Apr 19 at 12:00

with use of parbox:

\documentclass{article}
\usepackage{amsmath}

\begin{document}
\begin{align}
a + b &= \quad \text{short reason} \\
c + d &= \quad \parbox[t]{0.35\textwidth}{
really long and complicated\\
reason in two lines} \\
e + f &=\text{.}
\end{align}
\end{document}


(red lines indicate text borders)

supplement: considering comment of barbara beton, the above solution should be:

\documentclass{article}
\usepackage{amsmath}

\begin{document}
\begin{align}
a + b & = \quad \text{short reason} \\
c + d & = \quad \parbox[t]{0.35\textwidth}{\raggedright  % <---
really long and complicated\\
reason in two lines} \\
e + f & = .
\end{align}
\end{document}


in this simple case result is the same as at the first case, however if there's really long word that can't fit on the first line, added \ragged will avoid wide spaces between words in the first line.

• Another good way to solve this alignment problem. – Jay Jul 16 '18 at 22:14
• although it's not obvious here, if there's a really long word that can't fit on the first line, it would be better to specify ragged right to avoid wide spaces in the first line. – barbara beeton Jul 18 '18 at 19:51
• @barbarabeeton, thank you very much for your comment. i consider it in my answer. now result will look better also at circumstances of very long words in text. – Zarko Jul 18 '18 at 21:03
• I think this is the only correct answer. – GuM Jul 19 '18 at 0:57

A variation on @AboAmmar's answer, but using an environment that takes text and paragraphs:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align}
a + b &= \quad \text{short reason} \\
c + d &= \quad \begin{tabular}{@{}p{0.8\textwidth}}
really long and\\
complicated reason
\end{tabular} \\
e + f &=\text{.}
\end{align}
\end{document}


to produce

Of course, the 0.8\textwidth might need tweaking...

• Thanks. Typically the reasons are no more than two lines so I accepted AboAmmar's answer. But I will remember your answer if there are really, really long reasons. – Jay Jul 16 '18 at 15:25
• @Jay It's AboAmmar's idea so he deserves the tick on principle! – Andrew Jul 16 '18 at 15:26
• I up-ticked AboAmmar's answer and accepted it as well. – Jay Jul 16 '18 at 22:07
• the second group would really look better if the numbe were not dropped down a line. (i would also prefer that the baseline of the text be the same as that of the math at the left, but that's more subjective.) – barbara beeton Jul 18 '18 at 19:47