4

I have the following code to align a system of equations

\begin{aligned}
p       &= q r             &+ r_0 \\
r       &= q_0 r_0         &+ r_1 \\
r_0     &= q_1 r_1         &+ r_2 \\
r_k     &= q_{k+1} r_{k+1} &+ r_{k+2} \\
        &\mathrel{\vdots} \\
r_{k+1} &= q_{k+2} r_{k+2}
\end{aligned}

enter image description here

I can not understand why these equations do not align w.r.t +.

Please help me explain this phenomenon!

1
  • A general explanation of how elements of equations are treated by the align environment is given in this answer: Aligning equations Jun 13, 2019 at 3:12

2 Answers 2

6

You need one more & to have stuff left-aligned after it (if you want to work with aligned here).

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[\begin{aligned}
p       &= q r             &&+ r_0 \\
r       &= q_0 r_0         &&+ r_1 \\
r_0     &= q_1 r_1         &&+ r_2 \\
r_k     &= q_{k+1} r_{k+1} &&+ r_{k+2} \\
        &\mathrel{\vdots} \\
r_{k+1} &= q_{k+2} r_{k+2} \\
\end{aligned}\]
\end{document}

enter image description here

If you want to center the \vdots, you can use the mathtools package.

\documentclass{article}
\usepackage{mathtools}
\begin{document}
\[\begin{aligned}
p       &= q r             &&+ r_0 \\
r       &= q_0 r_0         &&+ r_1 \\
r_0     &= q_1 r_1         &&+ r_2 \\
r_k     &= q_{k+1} r_{k+1} &&+ r_{k+2} \\
        &\vdotswithin{=} \\
r_{k+1} &= q_{k+2} r_{k+2} \\
\end{aligned}\]
\end{document}

enter image description here

5
  • Thank you so much! I got it. Could you please instruct me to put the \cdots right below the center of =?
    – Akira
    Jun 12, 2019 at 4:21
  • @LeAnhDung I added something that does it. (Andrew Swann used this trick in an answer to a previous question of yours: tex.stackexchange.com/a/494424/121799.)
    – user121799
    Jun 12, 2019 at 4:26
  • I admire your great memory :)
    – Akira
    Jun 12, 2019 at 4:28
  • 1
    @LeAnhDung Those who live in burrows need it otherwise they cannot find out. ;-)
    – user121799
    Jun 12, 2019 at 4:30
  • @marmot such a nice suggestion....
    – MadyYuvi
    Jun 12, 2019 at 4:41
3

You need alignedat, that doesn't add horizontal spacing, but with one & more.

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\[
\begin{alignedat}{2}
p       &= q r             &&+ r_0 \\
r       &= q_0 r_0         &&+ r_1 \\
r_0     &= q_1 r_1         &&+ r_2 \\
        &\mathrel{\;\vdots} \\
r_k     &= q_{k+1} r_{k+1} &&+ r_{k+2} \\
r_{k+1} &= q_{k+2} r_{k+2}
\end{alignedat}
\]

\end{document}

enter image description here

2
  • I'm happy to see you on TexExchange ;)
    – Akira
    Jun 12, 2019 at 9:28
  • @Akira Happy to see you, too!
    – egreg
    Jun 12, 2019 at 9:29

You must log in to answer this question.

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