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'm very picky regarding alignment inside my proofs. What's frustrating me right now is that I have some lines that I want to be center-aligned (using \begin{gather}) and others that I wish to align at the "=" sign (using \begin{align}). My idea for how to do this was to just switch between the two within one proof, but this creates extra spacing (because closing one and opening another comes with implicit spacing).

I've messed around with adding in \vspace[-20pt] or something to that effect, but it's a rather clumsy solution and I've had problems with it. Also, ideally I would be able to go from align to gather back to align and have the second align keep aligned with the first, and obviously closing and reopening everything doesn't allow this.

Can anybody think of a better way to switch between the two alignment structures? Perhaps using a box to nest my gathers within align or something. Essentially, I usually like most of my proof in align but then want a couple of tangential points in gather. I've spent a while pondering the amsmath readme (and this website), but I can't find an answer.

Many thanks in advance!

Here's a little example coding to demonstrate the issue with my current scheme:

\documentclass{article}
\usepackage{amsmath}
\usepackage{amsthm}
\begin{document}
\begin{proof}
\begin{align*}
10 &= 2+2+2+2+2 \\
&= 3+3+3+1
\end{align*}\begin{gather*}
\intertext{But now it puts this annoying large space above this line...}
5=5
\end{gather*}
\end{proof}
\end{document}
share|improve this question
    
These are not an align* and a `gather* one after the other, because there's a line of text between them. Just put the text between the environments. –  egreg Apr 2 '12 at 17:56
    
Thanks so much to all of you for helping me with this question. I understand that it may be a non-standard formatting for proofs, but I'm putting simple proofs together for undergraduates that need a fair amount of commentary and explanation, so having that flexibility regarding alignment is helpful. All of your answers were very helpful, especially as they pointed me towards shortintertext, which I was not aware of (stupidly). I selected JMC's as my preferred answer because it gave me everything I wanted, even if it was a cheeky workaround. But thanks so much to all of you for the help! –  Shane Apr 2 '12 at 21:00
    
thanks for the rationale for this style of presentation. it makes sense in those circumstances. the answer by @jmc "misuses" \shortintertext, but it's ingenious and should probably work okay unless the aligned material gets to be too long and has to be broken to another page. i'm not really sure what would happen then, but would be interested to find out, presented with a real example. –  barbara beeton Apr 3 '12 at 15:08
add comment

3 Answers

up vote 2 down vote accepted

[Note: the improvement below, actually does not work.]

[Note: there is an important improvement to this code below.]

The closest I can get to a solution is

\documentclass[10pt,a4paper]{article}

\usepackage{amsmath,amsthm,mathtools}

\begin{document}
\begin{proof}
  \begin{align*}
    15 &= 5+4+3+2+1 = \sum_{i=1}^5 i \\
    120&=5\cdot4\cdot3\cdot2\cdot1 = 5! \\
    \shortintertext{
      \[ e^{\pi i} + 1 = 0 \]
      \[ x^n + y^n = z^n \]
    } 
    27 &= 3^3 \qedhere
  \end{align*}
\end{proof}
\end{document}

which gives as result Centered equation in align

and actually the spacing is quite nice, I think.


Failing important edit

I think the below code is nicer, and even gives better results.

\documentclass[10pt,a4paper]{article}

\usepackage{amsmath,amsthm,mathtools}

\begin{document}
\begin{proof}
  \begin{align*}
    15 &= 5+4+3+2+1 = \sum_{i=1}^5 i \\
    120&=5\cdot4\cdot3\cdot2\cdot1 = 5! \\
    \begin{gathered}
      e^{\pi i} + 1 = 0
      x^n + y^n = z^n
    \end{gathered} 
    27 &= 3^3 \qedhere
  \end{align*}
\end{proof}
\end{document}

Credits go to barbara beeton (please vote up her comment on her own answer).

share|improve this answer
1  
Thanks so much jmc. To clarify the situation in which I would use this: for my undergraduates, I like to have the main argument of the proof aligned at the equals sign but then to have some more tangential mathematical points aligned differently to mark clearly that they're not part of the main/direct logic of the proof. For those, it's nice to have them center-aligned as it distinguishes them from the main course. I'm sure many typesetters would disagree with this usage, but I find it quite useful for my UGs. Thanks for giving me the tools to do so. –  Shane Apr 2 '12 at 21:07
    
@Shane --- I made an improvement to my answer. Credits for the improvement should go to barbara beeton –  jmc Apr 3 '12 at 6:11
    
@jmc -- did you actually look at the output? you need some \` to separate the gathered` lines from one another, and then from the aligned material ... and then the gathered material isn't centered, but right-aligned (as a block) at the left side of the alignment. not a bad idea (i tried it yesterday myself), but it doesn't work. sigh. –  barbara beeton Apr 3 '12 at 12:19
    
@barbarabeeton Whoops, I did look at the output, but somehow to quickly. I think the output of my previous solution remained, and only a second run showed that it did not work. That really is a pity... –  jmc Apr 3 '12 at 12:40
    
It is interesting that you can run align within gather but not vice-versa. I suppose gather directly contradicts the instructions of align whereas align just adds to the instructions in gather. Anyway, thanks to all three of you (Barbara, jmc and Peter). –  Shane Apr 3 '12 at 13:24
add comment

taking a hint from @PeterGrill, here's a method of combining all the parts into one, using gather* since the "single" line is to be center-aligned, and the sub-environment aligned to take care of the multi-line expression.

since you're using amsthm, i've also taken the liberty to use \qedhere to position the "tombstone" on the last line of the display.

display with some lines aligned, another centered

\documentclass{article}
\usepackage{mathtools}
\usepackage{amsthm}
\begin{document}
\begin{proof}
\begin{gather*}
 \begin{aligned}
10 &= 2+2+2+2+2 \\
&= 3+3+3+1
\end{aligned}
\shortintertext{No annoying large space above this line...}
5=5
\qedhere
\end{gather*}
\end{proof}
\end{document}
share|improve this answer
    
This does, however, not show how to continue an aligned. –  jmc Apr 2 '12 at 18:34
1  
@jmc -- that's a pretty nasty request, if a centered element is to appear in the middle. although there's a gathered sub-environment, alignment will still be in effect from the main environment if it's align*, so centering would have to be forced manually. i don't see any neat way to do it (or, for that matter, a situation in which it would make sense). –  barbara beeton Apr 2 '12 at 18:58
    
neither do I. Still it is what the OP requests: "Also, ideally I would be able to go from align to gather back to align and have the second align keep aligned with the first, and obviously closing and reopening everything doesn't allow this." –  jmc Apr 2 '12 at 19:12
add comment

As per Adjust vspace between multiple align environments you should never use two consecutive display math environments.

Single align environment:

You could just use a single align* environment. I would also recommend using \shortintertext form the \mathtools package as that provides tighter vertical spacing:

enter image description here

\documentclass{article}
\usepackage{showframe}
\usepackage{mathtools}
\usepackage{amsthm}
\begin{document}
\begin{proof}
\begin{align*}
    10 &= 2+2+2+2+2\\
       &= 3+3+3+1
    \shortintertext{Now this no longer puts an annoying large space above this line...}
    5 &=5 \qedhere
\end{align*}
\end{proof}
\end{document}

Using align within gather:

Alternatively, you could also use gather to center some equations and also align other portions, but this dot not look very good, especially with short text snippets in between.

enter image description here

\documentclass{article}
\usepackage{showframe}
\usepackage{mathtools}
\usepackage{amsthm}
\begin{document}
\begin{proof}
\begin{gather*}
\begin{align*}
10 &= 2+2+2+2+2 &\\
   &= 3+3+3+1
\end{align*}
    \shortintertext{Now this no longer puts an annoying large space above this line...}
5=5 \qedhere
\end{gather*}
\end{proof}
\end{document}
share|improve this answer
    
The single align solution does not solve the OP's problem, since it does not give the possibility to center equations. –  jmc Apr 2 '12 at 18:33
    
@Peter - When I use your coding above for align within gather, it pushes my align segments out to the right quite some way. Any idea why that's happening? Interestingly, when I use aligned within gather, as Barbara does, I don't have that problem. –  Shane Apr 3 '12 at 13:50
    
@Shane: Updated version now posted. –  Peter Grill Apr 3 '12 at 14:49
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.