5

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!

  • A general explanation of how elements of equations are treated by the align environment is given in this answer: Aligning equations – barbara beeton Jun 13 at 3:12
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

  • Thank you so much! I got it. Could you please instruct me to put the \cdots right below the center of =? – Le Anh Dung Jun 12 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.) – marmot Jun 12 at 4:26
  • I admire your great memory :) – Le Anh Dung Jun 12 at 4:28
  • 1
    @LeAnhDung Those who live in burrows need it otherwise they cannot find out. ;-) – marmot Jun 12 at 4:30
  • @marmot such a nice suggestion.... – MadyYuvi Jun 12 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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.