41

I'm new to LaTeX and I'm trying to figure out how to correctly format a proof. Can someone show me a basic template for how to do this?

The part I am having the most trouble with is creating new columns and customizing alignment... for instance, how do I add a right-aligned annotation (i.e. by distributive property) to a line of this sample proof? Should I use eqnarray* or is there a better option?

\begin{proof}
  Let $t,u \in \mathbb{R}$ where $t=xy$ and $u=zw$. So,
  \begin{eqnarray*}
    4xyzw &=& 2\cdot2tu \\
    &\le& 2\cdot(t^2+u^2) \\
    &=& 2\cdot((xy)^2+(zw)^2) \\
    &=& 2\cdot(x^2y^2+z^2w^2) \\
    &=& 2x^2y^2+2z^2w^2 \\
    &\le& ((x^2)^2+(y^2)^2)+((z^2)^2)+(w^2)^2) \\
    &=& x^4+y^4+z^4+w^4
  \end{eqnarray*}
\end{proof}
David Carlisle
  • 757,742
Alex Lockwood
  • 731
  • 1
  • 8
  • 16

5 Answers5

52
\documentclass{article}

\usepackage{amsmath,amsthm,amssymb}

\begin{document}

\begin{proof}
  Let $t,u \in \mathbb{R}$ where $t=xy$ and $u=zw$. So,
  \begin{align*}
    4xyzw &= 2\cdot2tu \\
    &\le 2\cdot(t^2+u^2) \\
    &= 2\cdot((xy)^2+(zw)^2) &&\text{(substituting variables)} \\
    &= 2\cdot(x^2y^2+z^2w^2) \\ 
    &= 2x^2y^2+2z^2w^2 \\
    &\le ((x^2)^2+(y^2)^2)+((z^2)^2)+(w^2)^2) \\
    &= x^4+y^4+z^4+w^4 &&\qedhere
  \end{align*}
\end{proof}

\end{document}

The alignment is better (eqnarray should never be used for serious mathematical writing) and, moreover, the "end-of-proof" can be placed aligned with the last equation; \qedhere is necessary only when the proof ends with an alignment environment or with a list (enumerate, itemize or description); the && before \qedhere is only necessary when there are other comments.

I didn't check the math, though. ;-)

align with QED and comment

Andrew Swann
  • 95,762
egreg
  • 1,121,712
  • thanks for the info! should the QED symbol always be placed to the far right of the last line of text? is that convention? – Alex Lockwood Sep 02 '11 at 17:28
  • @alex: It has become convention because of how amsmath places the symbol :) The important point is that you should use \qedhere if the last line is inside an equation, since otherwise the QED ends up alone on the next line, which is ugly. – Ryan Reich Sep 02 '11 at 17:57
  • 5
    @alex, @Ryan -- the qed symbol (sometimes called the "tombstone") was placed to the far right by many math publishers long before amsmath came into being. that said, the position is considered to be a "house style". the originator appears to be Paul Halmos; see Handbook of Writing for the Mathematical Sciences, by Nicholas J. Higham, quote on p.11. before the square, "qed" in small caps was often used to indicate the end of a proof, and some authors still prefer that. – barbara beeton Sep 02 '11 at 19:15
  • "eqnarray should never be used for serious mathematical writing" - I've used it for 10 years now ... – Martin Brandenburg Mar 28 '15 at 01:50
  • 3
    @MartinBrandenburg You're always in time for switching to serious math writing. ;-) – egreg Mar 28 '15 at 10:16
  • @AndrewSwann Thanks for the editing; I'm under the impression that several old answers suffered from some update to MarkDown. – egreg Dec 31 '16 at 13:24
19

Adding to egreg's remarks: to add right-aligned annotation — in parentheses — you can use the \tag macro; to have annotation without parentheses, use the \tag* macro. (This must be given before the line-break; for this reason, I like to put the line break immediately before the following line, but that's just my personal style.) And again, as egreg noted, you should use \qedhere on the last line of an equation environment, if your proof ends at an equation.

\begin{align*}
  4xyzw 
  &= 2\cdot2tu 
  \\ &\le 2\cdot(t^2+u^2)                    \tag{a remark in parentheses}
  \\ &= 2\cdot((xy)^2+(zw)^2)
  \\ &= 2\cdot(x^2y^2+z^2w^2)                \tag*{a remark without parentheses}
  \\ &= 2x^2y^2+2z^2w^2
  \\ &\le ((x^2)^2+(y^2)^2)+((z^2)^2)+(w^2)^2)
  \\ &= x^4+y^4+z^4+w^4                      \qedhere
\end{align*}

If you find yourself having multi-line equations where you want equation numbers — but only on the last line — the macro \notag will also come in handy. (I insert them just before the line-breaks, to make it easy to copy the sequence \notag \\ &= for multi-line equations.)

\begin{align}
  4xyzw 
  &= 2\cdot2tu 
  \notag\\ &\le 2\cdot(t^2+u^2)                    \tag{a remark in parentheses}
  \\ &= 2\cdot((xy)^2+(zw)^2)
  \notag\\ &= 2\cdot(x^2y^2+z^2w^2)                \tag*{a remark without parentheses}
  \\ &= 2x^2y^2+2z^2w^2
  \notag \\ &\le ((x^2)^2+(y^2)^2)+((z^2)^2)+(w^2)^2)
  \notag \\ &= x^4+y^4+z^4+w^4
\end{align}

Edited to add: don't use \tag or \tag* for remarks, unless you're happy with them appearing on the left (instead of on the right) whilst using the lefteqn option.

Ryan Reich
  • 37,958
  • 7
    I wouldn't abuse \tag for annotations: with the lefteqn option they will go to the wrong side. Use rather align's features: a&=b &&\text{remark} – egreg Sep 02 '11 at 17:14
  • Hm. I didn't know that, perhaps as a result of not using lefteqn. I adopted this method (those rare times when I've used it) as it is a way of getting remarks flush with equation numbers. – Niel de Beaudrap Sep 02 '11 at 17:23
  • two questions: 1) under what circumstances would you use eqnarray as opposed to something like align. thanks for everything, guys! – Alex Lockwood Sep 02 '11 at 17:32
  • @alexjlockwood: in a word — never. What was the second question? – Niel de Beaudrap Sep 02 '11 at 17:33
  • 6
    Easy: never ever use eqnarray – egreg Sep 02 '11 at 17:33
  • sorry, clicked "enter" accidentally... and 2) what exactly does the & character mean in LaTeX? i noticed sometimes people use &=& and other times &=...&&. does it create a column break or something? – Alex Lockwood Sep 02 '11 at 17:34
  • 2
    @alexjlockwood: typically, it means "advance to the next column". In eqnarray (don't use it!) equations are blocked into groups of three columns: right-aligned, center-aligned, and left-aligned, after which you jump rightwards some distance to start a new equation further to the right. In align, equations are blocked into groups of two columns: right-aligned, and left-aligned. You'll also encounter & any time you use a table, or a matrix, or similar sorts of environments. – Niel de Beaudrap Sep 02 '11 at 17:37
  • so in egrep's above comment, the command a&=b &&\text{remark} would left-align a and right-align =b... right? but what does the last && do? – Alex Lockwood Sep 02 '11 at 17:41
  • Why don't you playing around with it and find out, and try putting other things between the & characters? I could try to describe it in detail, but I'm not going to get much clearer than what I've already said, unfortunately. – Niel de Beaudrap Sep 02 '11 at 17:49
  • 3
    @alex: Jumping of Niel's comment, there is a somewhat more specialized environment called alignat that gives you complete control over how the equation breaks into columns. It's useful if you have several stacked equations which should be aligned at multiple points, with appropriate padding added to make that happen. I only mention it because this effect is impossible to obtain otherwise, but it will be a long time before you need to use it. You should read amsldoc.pdf (or the result of texdoc amsmath) to learn about how these things work. – Ryan Reich Sep 02 '11 at 18:01
  • As mentioned by others \tag should not be abused in this way. It is intende for adding non-standard equation numbers such as \tag{*} – Andrew Swann Aug 10 '12 at 07:37
  • To be honest, I don't see what makes this an "abuse". It's obviously for labelling (steps of) equations, and most prominently so where the equation occurs. While it's something I don't often do, if I were to take a Dijkstra-esque approach to writing my mathematical notes, this is almost certainly the best mechanism to achieve it. But as you prefer... – Niel de Beaudrap Aug 10 '12 at 09:21
5

You can also use the package witharrows specially written in this aim.

\documentclass{article}
\usepackage{amsthm,amssymb}
\usepackage{witharrows}
\begin{document}
\begin{proof}
  Let $t,u \in \mathbb{R}$ where $t=xy$ and $u=zw$. So,
  \begin{DispWithArrows*}
    4xyzw &= 2\cdot2tu \\
    &\le 2\cdot(t^2+u^2) \Arrow[i]{substituting variables}\\
    &= 2\cdot((xy)^2+(zw)^2)  \\
    &= 2\cdot(x^2y^2+z^2w^2) \\ 
    &= 2x^2y^2+2z^2w^2 \\
    &\le ((x^2)^2+(y^2)^2)+((z^2)^C2)+(w^2)^2) \\
    &= x^4+y^4+z^4+w^4 \qedhere
  \end{DispWithArrows*}
\end{proof}
\end{document}

Result of the above code

F. Pantigny
  • 40,250
  • 1
    I upvote this answer because, in addition to be different to all the previous answers, it also mentions a package which can be tweaked as needed. Thus, fulfilling any future necessity. – gfe Apr 29 '20 at 09:45
4

One may also use the alignat environment. See the following:

\documentclass[letterpaper]{article}
\usepackage{amsmath,amssymb}
\newcommand{\justif}[2]{&{#1}&\text{#2}}
\begin{document}
\begin{alignat*}{2}
4xyzw &= 2\cdot2tu                              \justif{\quad}{remark}\\
      &\le 2\cdot(t^2+u^2)                      \justif{\quad}{remark}\\
      &= 2\cdot((xy)^2+(zw)^2)                  \justif{\quad}{remark}\\
      &= 2\cdot(x^2y^2+z^2w^2)                  \justif{\quad}{remark}\\
      &= 2x^2y^2+2z^2w^2                            \\ % no remark
      &\le ((x^2)^2+(y^2)^2)+((z^2)^2)+(w^2)^2)     \justif{\quad}{remark}\\
      &= x^4+y^4+z^4+w^4          
\end{alignat*}
\end{document}

enter image description here

Note the introduction of a \justif{<horizontal space>}{<content>} command that takes as arguments the separation and content (remark).

egreg
  • 1,121,712
azetina
  • 28,884
3

This is not an elegant solution but might be an option nevertheless. You can also fake it with a tabular. This way, you can print some borders if you want (just in case of those provide-the-missing-part tests so loved by some high school math teachers).

\documentclass[10pt]{article}

\usepackage[margin=1in]{geometry}
\usepackage{amsmath}
\usepackage{array}
\newcolumntype{L}{@{\hphantom{.}}>{$}l<{$}}
\renewcommand{\arraystretch}{1.2}
\begin{document}

\begin{tabular}{LLll}
\lvert p-q\rvert & =\sqrt{(p-1)^2} & \hphantom{some text} & by definition of square root\\
    &=\sqrt{p^2 -2pq +q^2} & &  by multiplication\\
    &=\sqrt{p^2-2pq+q^2 +2pq -2pq} & & by the additive identity\\
    &=\sqrt{p^2+2pq+q^2 -4pq} & &     by grouping like terms\\
    &=\sqrt{(p+q)^2 -4n} & &          by the distributive law\\
\end{tabular}

\end{document}
David Carlisle
  • 757,742
hpesoj626
  • 17,282