3

I am trying to get the following equation, but I can't find a way to center the vertical dots. The vertical dots are centered

My current code is this:

\begin{equation}
\begin{aligned}
b(n_1) &= a_2 n_1{^2} + a_1n_1 + a_ 0\\
b(n_2) &= a_2 n_2{^2} + a_1n_2 + a_ 0\\
       & \vdots \\
b(n_L) &= a_2 n_L{^2} + a_1n_L + a_ 0,
\end{aligned}
\end{equation}

Which gives this: Vertical dots not centered

Can anyone help me?

  • This alignment never vertically centers things, but left-aligns the signs after &. One thing you might do is to replace \vdots by \makebox[12pt][c]{\vdots}. Of course, if you are very picky, you may insist on precisely centered \vdots. Frankly, I would be much more concerned about the placement of the equation number. I'd use an ordinary align instead (which does not help on the issue with \vdots though) and only number the last equation. But that's just an opinion. – user121799 Sep 27 '18 at 23:24
  • When I want to dots etc in such a situation I it manually using one or more of \quad, \qquad or \hspace*{16mm}. It might be a matter of taste but like you I would prefer one equation number that is centered on the system of equations here, rather than an equation at the end as suggested by marmot. – Andrew Sep 27 '18 at 23:33
  • Marmot can you post this as an answer? :) thanks – Take2 Sep 27 '18 at 23:42
3

Sorry, I did not read the question carefully. If you really want to use aligned, you could do

\documentclass{article}
\usepackage{amsmath,calc}
\begin{document}
\begin{equation}
\begin{aligned}
b(n_1) &= a_2 n_1{^2} + a_1n_1 + a_ 0\\
b(n_2) &= a_2 n_2{^2} + a_1n_2 + a_ 0\\
       &\makebox[\widthof{$=a_2 n_2{^2} + a_1n_2 + a_ 0$}-\widthof{$b(n_2)$}][c]{\vdots} \\
b(n_L) &= a_2 n_L{^2} + a_1n_L + a_ 0,
\end{aligned}
\end{equation}
\end{document}

enter image description here

I picked a random line and computed its approximate width with calc to center the \vdots. (Approximate because of the spacing around the =.) Let's see how well that works.

\documentclass{article}
\usepackage{amsmath,calc}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\begin{document}
\begin{equation}
\begin{aligned}
b(n_1) &= a_2 n_1{^2} + a_1n_1 + a_ 0\\
\tikzmark{1}b(n_2) &= a_2 n_2{^2} + a_1n_2 + a_ 0\tikzmark{2}\\
       &\makebox[\widthof{$=a_2 n_2{^2} + a_1n_2 + a_ 0$}-\widthof{$b(n_2)$}][c]{\vdots} \\
b(n_L) &= a_2 n_L{^2} + a_1n_L + a_ 0,
\end{aligned}
\tikz[overlay,remember picture]{\draw[red] (pic cs:1) -- (pic cs:2)
coordinate[midway](3);
\draw[red](3) -- ++(0,-1);}
\end{equation}
\end{document}

enter image description here

Modulo the above-mentioned spacing around = that seems to work. I personally wouldn't use this in my own notes or papers, nor have I ever used aligned there because IMHO these vertically centered equation numbers insult my eyes. But of course this is only an opinion, so feel free to disagree. And I do not think my answer is the better option, when you wrote your comment you didn't even know it.... wait, do you have my crystal ball??? ;-)

  • But then the \vdots are horizontally centered only w.r.t. the RHS and not w.r.t. the full line width. – Henri Menke Sep 27 '18 at 23:47
  • This isn't really centered sadly :'( I think it is because \widthof{$=a_2 n_2{^2} + a_1n_2 + a_ 0$} does not give the width of b(n_1) &= a_2 n_1{^2} + a_1n_1 + a_ 0 (because of the &) – Take2 Sep 27 '18 at 23:48
  • 1
    @DiogoTec Yes, sorry, I misread your question. I thought you wanted it to be centered w.r.t. the stuff on the right-hand side. – user121799 Sep 28 '18 at 0:16
6

Another possibility, with the \vdotswithin command from mathtools:

\documentclass{article}
\usepackage{mathtools}

\begin{document}

\begin{equation}\label{eqlbl}
  \begin{alignedat}{2}
    b(n_1) &= a_2 n_1{^2} & & + a_1n_1 + a_ 0\\
    b(n_2) &= a_2 n_2{^2} & & + a_1n_2 + a_ 0\\[-1.2ex]
 &\vdotswithin{ = } & & \vdotswithin{ + }\\[-1ex]
    b(n_L) &= a_2 n_L{^2} & & + a_1n_L + a_ 0,
\end{alignedat}
\end{equation}

\end{document} 

enter image description here

  • 1
    Why do you need eqparbox? – Henri Menke Sep 28 '18 at 0:10
  • @HenriMenke: It was a first attempt – notsatisfying. I forgot to remove it from the code. Fixed now. Thanks for pointing the leftover! – Bernard Sep 28 '18 at 7:46
4

You can make use of the fact that aligned is actually just \halign under the hood. Then you can insert content spanning several columns using the Plain TeX macro \multispan. You only need to know the number of columns for this to work.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{equation}
\begin{aligned}
    b(n_1) &= a_2 n_1{^2} + a_1n_1 + a_ 0\\
    b(n_2) &= a_2 n_2{^2} + a_1n_2 + a_ 0\\
    \multispan{2}\hfil$\vdots$\hfil\\
    b(n_L) &= a_2 n_L{^2} + a_1n_L + a_ 0,
\end{aligned}
\end{equation}
\end{document}

enter image description here


I can offer another solution for align.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
    b(n_1) &= a_2 n_1{^2} + a_1n_1 + a_ 0\\
    b(n_2) &= a_2 n_2{^2} + a_1n_2 + a_ 0\\
    \noalign{\centering$\vdots$}
    b(n_L) &= a_2 n_L{^2} + a_1n_L + a_ 0,
\end{align*}
\end{document}

enter image description here

  • Any way to number the whole system as one equation (as in my images), and that the number is centered vertically? – Take2 Sep 27 '18 at 23:37
  • @DiogoTec You can place \nonumber on the lines you don't want to have numbered. Vertically centered numbering is only possible with aligned but then the above trick does not work. – Henri Menke Sep 27 '18 at 23:39
  • Alright, thank you! Given that I want the number centered, marmot answer seems a better option. Many thanks tho :) – Take2 Sep 27 '18 at 23:42
  • 1
    @DiogoTec I added a second part to my answer. – Henri Menke Sep 27 '18 at 23:48
  • @DiogoTec I have found another solution which does not require you to know the width of the alignment. – Henri Menke Sep 28 '18 at 21:39

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.