16

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.

1
  • Regarding meta.stackoverflow.com/questions/421831/… , you say "Interesting that both answers bring up the inaccuracy." - actually that's explainable. Both questions were asked in one session, so everything is still in context. The answer would probably be different if asked on its own in a single session Commented Jun 14 at 13:04

3 Answers 3

6

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} 

output

6
  • This looks like it works more properly. I'll try mathtools.
    – bombcar
    Commented Mar 11, 2014 at 21:54
  • It's an extension to amsmath: it loads it, and by default fixes two bugs in amsmath.
    – Bernard
    Commented Mar 11, 2014 at 21:58
  • Yep, it worked though I had to figure out \mathclap (I think). Otherwise it wasn't centering.
    – bombcar
    Commented Mar 11, 2014 at 22:00
  • 1
    @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 Commented Mar 11, 2014 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
    Commented Mar 11, 2014 at 23:36
16

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}
9
  • Oh! You can put equation inside intertext. It works but seems naughty somehow!
    – bombcar
    Commented Mar 11, 2014 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:-) Commented Mar 11, 2014 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
    Commented Mar 11, 2014 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
    Commented Mar 11, 2014 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:-) Commented Mar 11, 2014 at 23:44
2

In this case, it seems to be safe to use \multispan:

\documentclass[12pt]{memoir}
\usepackage{amsmath}

\newcommand{\equationinalign}[1]{%
  \multispan{2}%
  \hfill$\displaystyle{#1}$\hfill
  \ignorespaces
}

\begin{document}
\noindent
\hspace*{\fill}\smash{\vrule depth 10cm width 0.1pt}\hspace*{\fill}

Here we see
\begin{align}
\text{cat} &= \text{dog}\\
\text{dog} &= \text{cute}\\
\intertext{and if we remove}
\equationinalign{\text{dog}}
\intertext{we get}
\text{cat} &= \text{cute}
\end{align}

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .