5

I am wondering what is the best way to make multi-row text comments in the align environment. Here is an example code:

\begin{align*}
\int \left( \frac{x+3}{2}\right) \, dx =& \int \frac{1}{2}(x+3) \, dx & \text{Factoring out a constant.} \\
 =& \frac{1}{2} \int (x+3) \, dx & \text{Factoring the constant outside the integral} \\
 =& \frac{1}{2}[\frac{1}{2}x^2+3x]+C & \text{Applying the power rule and adding the constant of integration} \\
 =& \frac{1}{4}x^2+\frac{3}{2}x+C & \text{Distributing the } \frac{1}{2} \\
 =& \frac{x^2+6x}{4}+C& \text{Finding a common denominator} \\
 =& \frac{x(x+6)}{4}+C & \text{Factoring out an } x
 \end{align*}

I am not very fond of the way the comment is close to the equation in the third line where it says "applying the power rule...", is there any neat way of making a 2 line comment that doesn't look awkward?

1 Answer 1

7

Using amsmath package the code:


Method 1:

\begin{align*}
\int \left( \frac{x+3}{2}\right) \, dx
=& \int \frac{1}{2}(x+3) \, dx && \text{Factoring out a constant} \\
=& \frac{1}{2} \int (x+3) \, dx && \text{Factoring the constant outside the integral} \\
=& \frac{1}{2}\left[\frac{1}{2}x^2+3x\right]+C && \text{Applying the power rule and }\\ 
 &  && \text{adding the constant of integration} \\
=& \frac{1}{4}x^2+\frac{3}{2}x+C && \text{Distributing the } \frac{1}{2} \\
=& \frac{x^2+6x}{4}+C && \text{Finding a common denominator} \\
=& \frac{x(x+6)}{4}+C && \text{Factoring out an }
\end{align*}

produces a nice aligned set as seen by: enter image description here


Method 2: Using Barbara Beeton's \parbox suggestion:

\begin{align*}
\int \left( \frac{x+3}{2}\right) \, dx
=& \int \frac{1}{2}(x+3) \, dx && \text{Factoring out a constant} \\
=& \frac{1}{2} \int (x+3) \, dx && \text{Factoring the constant outside the integral} \\
=& \frac{1}{2} \left[ \frac{1}{2}x^2+3x \right]+C && \parbox{5.5cm}{Applying the power rule and 
                                                             adding the constant of integration} \\
=& \frac{1}{4}x^2+\frac{3}{2}x+C && \text{Distributing the } \frac{1}{2} \\
=& \frac{x^2+6x}{4}+C && \text{Finding a common denominator} \\
=& \frac{x(x+6)}{4}+C && \text{Factoring out an }
\end{align*}

enter image description here

6
  • That is a good answer! Why do you insert && before the text comment? Does it have any different effect than just a single ampersand?
    – 1028
    Commented Jul 24, 2015 at 2:31
  • @1028 The use of & and && have different outcomes when using amsmath as given in the documentation ftp.ams.org/pub/tex/doc/amsmath/amsldoc.pdf
    – Leucippus
    Commented Jul 24, 2015 at 2:38
  • 1
    the wide separation between the two lines of the comment makes it look like maybe there is a line of math missing. since the fractions essentially make the relevant equation two lines tall, a small two-line block of text would be appropriate, and can be accomplished by using a \parbox. also, the square brackets are too small in that line, and can be improved by using \Bigl[ and \Bigr] (maybe \bigg would be better; i can't try it out and don't remember the sizes exactly). Commented Jul 24, 2015 at 4:58
  • @barbarabeeton The spacing of the equation component and \parbox does blend well
    – Leucippus
    Commented Jul 24, 2015 at 6:12
  • just one more little suggestion -- the inter-word spaciong would look nicer if you use \raggedright. Commented Jul 24, 2015 at 7:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .