2

I want to align multiple equations. Some of them span multiple lines, some of them don't. I'd like for the equation tag of the multiple-line equations to be aligned with both lines, not just one of them, so just using align with \notag don't work.

So I tried using aligned within align but everything got right aligned. Also tried flalign as the outer environment, same result. Any idea?

\begin{align}
\begin{aligned}
    X_{i+1} &= X_i + h (P_{X,i} + Y_{i+1}), \label{eq:symplectic-euler-X_i+1}
\end{aligned} \\
\begin{aligned}
    Y_{i+1} &= Y_i + h (P_{Y,i} - X_{i+1}), \label{eq:symplectic-euler-Y_i+1}
\end{aligned} \\
\begin{aligned}
    P_{X,i+1} &= P_{X,i} \\
    &+ h \left(P_{Y,i} - \dfrac{(1-k)(k+X_{i+1})}{((k+X_{i+1})^2+Y_{i+1}^2)^{3/2}} + \dfrac{k(X_{i+1}-1+k)}{((X_{i+1}-1+k)^2+Y_{i+1}^2)^{3/2}}\right), % \label{eq:symplectic-euler-PX_i+1}
\end{aligned} \\[0.4cm]
\begin{aligned}
    P_{Y,i+1} &= P_{Y,i} \\
    &+ h \left(-P_{X,i} - \dfrac{(1-k)Y_{i+1}}{((k+X_{i+1})^2+Y_{i+1}^2)^{3/2}} - \dfrac{k Y_{i+1}}{((X_{i+1}-1+k)^2+Y_{i+1}^2)^{3/2}}\right). % \label{eq:symplectic-euler-PY_i+1}
\end{aligned}

\end{align}

Which gives this:

enter image description here

How do I get everything left aligned, and with centered tags?

1
  • Can you provide an image of the expected output? You can cobble something together by moving the elements around.
    – Werner
    Sep 11, 2018 at 19:47

1 Answer 1

3

Your different aligned environments are not introduced by an ampersand, so there's an implicit one at the end of each line, whence the right alignment.

Maybe the following code produces what you want?

\documentclass{article}

\usepackage{mathtools}
\usepackage{geometry} 

\begin{document}

  \begin{align}
     X_{i+1} &=X_i + h (P_{X,i} + Y_{i+1}), \label{eq:symplectic-euler-X_i+1} \\[1ex]
     Y_{i+1} &= Y_i + h (P_{Y,i} - X_{i+1}), \label{eq:symplectic-euler-Y_i+1} \\[1ex]
     \begin{split} P_{X,i+1} &=P_{X,i} \\[-1ex]
        &\phantom{ = {}}+ h \left(P_{Y,i} - \dfrac{(1-k)(k+X_{i+1})}{((k+X_{i+1})^2+Y_{i+1}^2)^{3/2}} + \dfrac{k(X_{i+1}-1+k)}{((X_{i+1}-1+k)^2+Y_{i+1}^2)^{3/2}}\right), % \label{eq:symplectic-euler-PX_i+1}
\end{split} \\[1ex]
 \begin{split} P_{Y,i+1} &=P_{Y,i} \\[-1ex]
       & \phantom{ ={} } + h \left(-P_{X,i} - \dfrac{(1-k)Y_{i+1}}{((k+X_{i+1})^2+Y_{i+1}^2)^{3/2}} - \dfrac{k Y_{i+1}}{((X_{i+1}-1+k)^2+Y_{i+1}^2)^{3/2}}\right). % \label{eq:symplectic-euler-PY_i+1}
\end{split}
\end{align}

\end{document} 

enter image description here

3
  • Thanks, that works (sorry for late reply) :) Dec 20, 2018 at 20:44
  • Could you explain what this bit does? \phantom{ = {}} Dec 20, 2018 at 20:49
  • I believe the \phantom{ = {}} plays the role of the equal sign after the ampersand and just leaves the same space. \phantom{something here} adds the space of the string "something here". For example, in a matrix environment with some entries with negative signs, adding \phantom{-} before the entries that are non negative in the same column will align all the terms of the column.
    – F Zaldivar
    Nov 24, 2020 at 0:53

You must log in to answer this question.

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