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 have the following align enviroment:

\documentclass[12pt]{memoir}
\usepackage{amsmath}
\begin{document}
Here we see
\begin{align}
\text{cat} &= \text{dog}\\
\text{dog} &= cute
\intertext{and if we remove}
\text{dog}\\
\intertext{we get}
\text{cat} &= cute
\end{align}
\end{document}

Which creates:

An unaligned equation

How do I center equation 3 while keeping everything else aligned? I can get close by putting in an & in the real equation, but it's still not perfectly centered.

share|improve this question

2 Answers 2

up vote 4 down vote accepted

With the gathered environment. Better using mathtools instead of amsmath (it's an extension that loads amsmath and fixes two bugs in it). Here is how:

    \documentclass[12pt]{article}
    \usepackage{mathtools}
    \usepackage[showframe]{geometry} 

    \begin{document}

    \begin{align}
    \text{catxxxxxxxxxxxxxxxxxxxx} &= \text{dog}\\
    \text{dog} &= \text{cute}\\
    \intertext{and if we remove}
     \begin{gathered}
    \text{and if we remove dog}
    \end{gathered} \\
    \intertext{we get}
    \text{cat} &= \text{cute}
    \end{align}

    \end{document} 

enter image description here

share|improve this answer
    
This looks like it works more properly. I'll try mathtools. –  bombcar Mar 11 at 21:54
    
It's an extension to amsmath: it loads it, and by default fixes two bugs in amsmath. –  Bernard Mar 11 at 21:58
    
Yep, it worked though I had to figure out \mathclap (I think). Otherwise it wasn't centering. –  bombcar Mar 11 at 22:00
    
@bombcar note that that this doesn't actually answer the question (although it makes a reasonable layout on the MWE) It puts the centre of the dog line at the alignment point which only approximately centres the line as cat=cute have similar length, if you change the first line to \text{catxxxxxxxxxxxxxxxxxxx} &= \text{dog}\\ you'll see the dog line moves using this approach but stays if it is set in equation –  David Carlisle Mar 11 at 23:02
    
@David Carlisle: You're perfectly right. Actually I added \clap \ or \mathclap when I observed the "gathered" part wasn't really centred. It must have been because of some other code in my file, which I've deleted since then. So simply using the gathered environment gives the same result as equation, but it seems to me more natural to use gathered, and you can have several gathered lines. –  Bernard Mar 11 at 23:36

enter image description here

\documentclass[12pt]{memoir}
\usepackage{amsmath}
\begin{document}
Here we see
\begin{align}
\text{cat} &= \text{dog}\\
\text{dog} &= cute
\intertext{and if we remove
\begin{equation}dog\end{equation}
we get\vspace{-\baselineskip}}\\
\text{cat} &= cute
\end{align}

\end{document}
share|improve this answer
    
Oh! You can put equation inside intertext. It works but seems naughty somehow! –  bombcar Mar 11 at 21:47
    
@bombcar well i can't say I've ever done it before but it was worth a try. It doesn't really work it makes the first following line of the align to be not numbered, which is why I add the \\ and back up a row so the cat line gets numbered. If you look at the chat site you'll see a comment about that:-) –  David Carlisle Mar 11 at 21:51
    
It's close enough for what I needed, so it's good enough for me. I'm kind of surprised that amsmath doesn't already have some default for it, though. –  bombcar Mar 11 at 21:53
    
@bombcar: I modified my answer to take David Carlisle's remark into account. It makes me coming back to my initial answer, which was very close to his's. Gathered offers the possibility to have several lines centred within one environment, which equation can't do. –  Bernard Mar 11 at 23:43
    
@Bernard no this answer centres the dog line on the text block, so it is unlike yours (but it is probably an abuse of the ams code:-) –  David Carlisle Mar 11 at 23:44

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.