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.

Suppose I have something like the following:

    \begin{eqnarray*}
\mathrm{gcd}(x^3 + 6x^2 + 5x + 5, x^3 + 13x^2 + 6x + 3) &=& 102x^2 + 108x + 2 \ \mathrm{with} \ p = 109 \\
\mathrm{gcd}(x^3 + 2x^2 + 9x + 4, x^3 + 3x^2 + 7x + 9) &=& 1 \ \mathrm{with} \ p = 131 \\
\mathrm{gcd}(x^3 + 3x^2 + 9x + 12, x^3 + 6x^2 + 12x + 4) &=& 6x + 122 \ \mathrm{with} \ p = 157
\end{eqnarray*}

How do I align the statements at the end of each line (i.e. the "with p = ..." bit) to the right?

share|improve this question
2  
    
Welcome to TeX.SE. –  Peter Grill Mar 29 '12 at 22:20
add comment

1 Answer

Never ever use eqnarray!

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
\gcd(x^3 + 6x^2 + 5x + 5, x^3 + 13x^2 + 6x + 3) &= 102x^2 + 108x + 2 &&\text{with } p = 109 \\
\gcd(x^3 + 2x^2 + 9x + 4, x^3 + 3x^2 + 7x + 9) &= 1 &&\text{with } p = 131 \\
\gcd(x^3 + 3x^2 + 9x + 12, x^3 + 6x^2 + 12x + 4) &= 6x + 122 &&\text{with } p = 157
\end{align*}
\end{document}

The align environment provided by amsmath (with the not numbered *-variant) provides for as many alignment points you want. The first column is right aligned, the second is left aligned, the third is right aligned and so on.

Notice that the & goes before the alignment point (usually a relation).

So we put the explanation text in the fourth column; the rl blocks are separated from one another by suitable space.

The \text command allows spaces in it (contrarywise to \mathrm). The \gcd operator is predefined in LaTeX.

share|improve this answer
1  
Why not to use eqnarray? you may ask. So, they say "Avoid eqnarray" in many ways: PracTeX Journal, TeX Blog, and LaTeX Tips. –  adn Mar 30 '12 at 5:48
add comment

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.