6

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.

enter image description here

  • 1
    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
  • 1
    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
7

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}

enter image description here

  • 1
    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
6

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}

enter image description here

(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
  • 1
    I think this is the only correct answer. – GuM Jul 19 '18 at 0:57
4

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

enter image description here

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
  • 1
    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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.