19

I find that I have unpleasant spacing between the equals sign and (e.g.) the exponential function in this particular case, while using the align environment. I have a long expression which has to be split up in multiple rows. The alignment character & appears to gobble up all space when it comes after the equals sign. How could I remedy this while still preserving the plus sign alignment below?

Ideally, I would like to have the second row from the first equation, and the first row from the second equation.

Compiled document

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align} % bad spacing at first row, but correctly placed second row
    2 \cosh t =& e^t \\
            &+ e^{-t} 
\end{align}
\begin{align} % good spacing at first row, but incorrectly placed second row
    2\cosh t &= e^t \\
            &+ e^{-t} 
\end{align}
\end{document}
2

5 Answers 5

11

Put the ampersand before the equals sign. Then use \quad to create the indentation in the second row.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align}                                                                   
    2 \cosh t &= e^t \\                                                         
              &\quad+ e^{-t}                                                    
\end{align}
\end{document}

You can also use \hspace if you want a different length for the indentation.

alignment

3
  • 9
    Wouldn't \begin{align} 2 \cosh t &= e^t \\ &\phantom{{}={}} + e^{-t} \end{align} be better? Then the plus symbol would be inset by the width of the equals sign, with the correct spacing. Nov 17, 2014 at 17:21
  • I'd say it's a matter of taste. Nov 18, 2014 at 8:08
  • 2
    @Niel de Beaudrap: You are missing a \negmedspace for correct spacing: 2 \cosh t &= e^t \\ &\phantom{{}={}} \negmedspace + e^{-t}
    – user117833
    Apr 6, 2019 at 6:42
10

I wouldn't try aligning the plus with e^t, but if you insist, here's how.

\documentclass{article}
\usepackage{amsmath}
\begin{document}

\noindent
The plus is flush with $e^t$ (I wouldn't recommend it):
\begin{align}
2\cosh t ={}& e^t \\
            & \negmedspace+ e^{-t}
\end{align}
The plus is moved right (better):
\begin{align}
2\cosh t &= e^t \\
         &\qquad+ e^{-t}
\end{align}
\end{document}

With \negmedspace we kill the space at the left of the binary operation symbol.

enter image description here

However, align is the wrong tool here:

\documentclass{article}
\usepackage{amsmath}
\begin{document}

\begin{equation}
\begin{split}
2\cosh t &= e^t \\
         &\qquad + e^{-t}
\end{split}
\end{equation}

enter image description here

1
  • +1 for recommending split
    – Felix
    Mar 8, 2023 at 11:30
5

Suppose you wish to ensure that the two instances of e are aligned vertically, while respecting the fact that a binary operator (+) precedes the e in the second row. The most direct way to obtain this type of alignment is to use a pair of \hphantom ("horizonal phantom") statements. The one in the first row mimics the + symbol (a binary operator) from the second row, and the \hphantom statement in the second row mimics the = symbol (a relational operator) from the first row. The {} pairs are there to help TeX figure out which type of operator applies.

enter image description here

\documentclass{article}
\usepackage{amsmath}
\setlength\textwidth{3in} %% just for this example
\begin{document}
\begin{align}
    2\cosh t &= \phantom{{}+{}} \mathrm{e}^t \\
             &\phantom{{}={}} + \mathrm{e}^{-t}
\end{align}
\end{document} 
5

You have placed the & in an odd position, I think; it's "smarter" to put it in front of the equal sign to get the correct spacing. Also, I've used \hphantom to indent the expression in the second line to get the correct alignment. (Notice the {} before =.)

\documentclass{article}

\usepackage{amsmath}

\begin{document}

\begin{align}
   2\cosh t
   &= e^{t} \\
   &\hphantom{{}=} + e^{-t} 
\end{align}

\end{document}

output

3
  • 2
    It is not wrong, one just have to be a bit more careful. Besides ` = {} &` is a lot short to type than &\hphantom{{}=} ;-)
    – daleif
    Nov 17, 2014 at 15:19
  • @daleif Good point. The reason why I used \hphantom is that it's more 'universal'. Nov 17, 2014 at 16:33
  • I had to use <\hphantom{{}={}}>, since your solution still made the second line start a bit too early... Apr 7, 2020 at 11:20
5

Strictly speaking, only the first part of egreg's answer and Niel de Beaudrap's modified comment solve the problem as intended by Martin L. All other answers require space corrections of at least 1 or 2 mu. Here is an alternative.

LaTeX encloses relation symbols in thick spaces \; and binary operator symbols in medium spaces \:. The symbols = and + in our example are each of this type. Therefore, downgrading them to ordinary symbols, what we want is:

2 \cosh t & \; \mathord{=} \; e^t \\
          & \; \phantom{=} \; \mathord{+} \: e^{-t}

A practical incarnation of the above is (see page 36 of l2kurz.pdf):

2 \cosh t & = e^{t} \\
          & \phantom{=} \  + e^{-t}

The \phantom command strips = of its relation status, leaving it short of two thick spaces. On the other hand, LaTeX interprets + as a binary operator, creating a spurious medium space. So we need an extra normal space: \ = \; + \; - \:.

enter image description here

You must log in to answer this question.

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