Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am always describing the steps on how a formula is achieved or describing the underlying Mathematical principles taken to solve a problem in the align environment. But the descriptions are not displayed in the best manner possible. For example:

\documentclass[letterpaper]{article}
\usepackage{fullpage}
\usepackage{amsmath,amssymb,amsthm,enumitem}
\usepackage[dvipsnames]{xcolor}
\newcommand{\red}[1]{%
{\color{OrangeRed}#1}}

\begin{document}
Let us show that by completing the square, we can achieve this.
        \begin{align*}
        f(x)&=ax^2+bx+c \qquad\qquad\qquad\qquad\qquad\mbox{ Factor $a$ from $ax^2+bx$. Do you know why?}\\
            &=a\left(x^2+\frac{b}{a}x\right)+c\qquad\qquad\qquad\qquad\mbox{ \red{Complete the square by adding $\frac{b^2}{4a^2}$.}} \\
            &=a\left(x^2+\frac{b}{a}x+\red{\frac{b^2}{4a^2}} \right)+c\red{-a\left(\frac{b^2}{4a^2}\right)}\mbox{~~~Factor and simplify.}\\
            &=a\left(x+\frac{b}{2a}\right)^2+c-\frac{b^2}{4a}\\
            &=a\left(x+\frac{b}{2a}\right)^2+\frac{4ac-b^2}{4a}\\
            &=a(x-h)^2+k
        \end{align*}
 \end{document}

yeilds:

enter image description here

which does not display the description properly. If you notice in my code above, I am forcing the descriptions to have a left indent based on the longest line of math display (where the a\left(x^2+\frac{b}{a}x+\red{\frac{b^2}{4a^2}} \right)+c\red{-a\left(\frac{b^2}{4a^2}\right)} is found.)

Now here is a different scenario:

\documentclass[letterpaper]{article}
\usepackage{fullpage}
\usepackage{amsmath,amssymb,amsthm,enumitem}
\usepackage[dvipsnames]{xcolor}
\newcommand{\red}[1]{%
{\color{OrangeRed}#1}}

\begin{document}
Let us apply completing the square to the standard form of a quadratic equation, $ax^2+bx+c=0$.

\begin{align*}
    ax^2+bx+c&=0 &\mbox{Divide by $a$, the leading coefficient.}&\\[1.25ex]
    x^2+\frac{b}{a}x+\frac{c}{a}&=0 &\mbox{Transpose the constant term to the RHS.}&\\[1.25ex]
    x^2+\frac{b}{a}x&=-\frac{c}{a}&\mbox{\red{Add $\left(\frac{1}{2}\left(\frac{b}{a}\right)\right)^2$ to both sides.}}&\\[1.25ex]
    x^2+\frac{b}{a}x+\frac{b^2}{4a^2}&=-\frac{c}{a}+\frac{b^2}{4a^2}&\mbox{Factor the LHS and simplify the RHS.}&\\[1.25ex]
    \left(x+\frac{b}{a}\right)^2&=\frac{b^2-4ac}{4a^2}&\mbox{Take the square root of both sides.}&\\[1.25ex]
    x+\frac{b}{a}&=\pm\frac{\sqrt{b^2-4ac}}{2a}&\mbox{Solve for $x$.}&\\[1.25ex]
    x&=\frac{-b\pm\sqrt{b^2-4ac}}{2a}&\mbox{\textbf{Quadratic Formula}.}&
    \end{align*}
 \end{document}

which yields:

enter image description here

But what happens in this example is that the description is right aligned and not dependent on the longest line of math display. I have read somewhere that using

\text{\parbox[t]{2in}{ can be used in mathmode with a very long long long long long long long description}

Of course I foresee a drawback as the length of the parabox should be calculated on the remaining space of text while staying within the margin.

In summary, I would like the descriptions to be left aligned and dependent on the longest math display or possible split if using the split environment for math equations and that if the description goes beyond one line that it goes to a second or third line with the same proper indentation. Any help into the matter will be highly appreciated.

share|improve this question
    
I think you will be better with a tabular environment, or a special command to add lines of equations. –  Yiannis Lazarides May 21 '12 at 18:36
    
@YiannisLazarides I guess so, but how would the align feature still maintained within a tabular environment. Wouldn't there be column and row separation issues? And the declaration of the column type for the math section may pose an issue. –  azetina May 21 '12 at 18:49

1 Answer 1

up vote 8 down vote accepted

Somehing like this? (two && before the \mbox)

\documentclass[letterpaper]{article}
\usepackage{fullpage}
\usepackage{amsmath,amssymb,amsthm,enumitem}
\usepackage[dvipsnames]{xcolor}
\newcommand{\red}[1]{%
  {\color{OrangeRed}#1}}

\begin{document}
Let us apply completing the square to the standard form of a quadratic equation, $ax^2+bx+c=0$.

\begin{align*}
  ax^2+bx+c&=0 &&\mbox{Divide by $a$, the leading coefficient.}&\\[1.25ex]
  x^2+\frac{b}{a}x+\frac{c}{a}&=0 &&\mbox{Transpose the constant term to the RHS.}&\\[1.25ex]
  x^2+\frac{b}{a}x&=-\frac{c}{a}&&\mbox{\red{Add $\left(\frac{1}{2}\left(\frac{b}{a}\right)\right)^2$ to both sides.}}&\\[1.25ex]
  x^2+\frac{b}{a}x+\frac{b^2}{4a^2}&=-\frac{c}{a}+\frac{b^2}{4a^2}&&\mbox{Factor the LHS and simplify the RHS.}&\\[1.25ex]
  \left(x+\frac{b}{a}\right)^2&=\frac{b^2-4ac}{4a^2}&&\mbox{Take the square root of both sides.}&\\[1.25ex]
  x+\frac{b}{a}&=\pm\frac{\sqrt{b^2-4ac}}{2a}&&\mbox{Solve for $x$.}&\\[1.25ex]
  x&=\frac{-b\pm\sqrt{b^2-4ac}}{2a}&&\mbox{\textbf{Quadratic Formula}.}&
\end{align*}
\end{document}

enter image description here

share|improve this answer
6  
since amsmath is being used, i suggest using \text{...} rather than \mbox. –  barbara beeton May 21 '12 at 18:54
    
Yes, I agree, thanks. –  robert.marik.cz May 21 '12 at 18:58
    
This seems to do the job. I will wait and see if there are more feedback from the community and then will accept your answer. The question then would be: How do we deal with long descriptions while maintaining proper display? –  azetina May 21 '12 at 19:18
    
@azentina - perhaps minipage helps –  robert.marik.cz May 21 '12 at 19:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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