# How to center elements of different sizes

I would like to display some matrix things

\begin{frame}
\begin{align*}
\left(
\begin{array}{c}
y_1 \\ y_2 \\ \vdots \\ y_T \\
\end{array}
\right)
& =
\left(
\begin{array}{ccccc}
1 & x_{11} & x_{12} & \cdots & x_{1k} \\
1 & x_{21} & x_{22} & \cdots & x_{2k} \\
\vdots & \vdots & \vdots &  & \vdots \\
1 & x_{T1} & x_{T2} & \cdots & x_{Tk} \\
\end{array}
\right)
&
\left(
\begin{array}{c}
b_0 \\
b_1 \\
\vdots \\
b_k \\
\end{array}
\right)
+
&
\left(
\begin{array}{c}
u_1 \\
u_2 \\
\vdots \\
u_T \\
\end{array}
\right)
\\
y    & = X          &b          + & u \\
(T,1)& = (T,k+1)    &(k+1,1)    + &(T,1)
\end{align*}
\end{frame}


I get that :

But I would like my elements of the second and third lines centered like that

I have tried an array of array but it has been disastrous.

You can place the entire structure inside an array with the appropriate alignment for each column - centred:

\documentclass{article}

\usepackage{amsmath}

\begin{document}

$\begin{array}{ *{3}{@{}c} @{\qquad} *{3}{c@{}} } \begin{pmatrix} y_1 \\ y_2 \\ \vdots \\ y_T \end{pmatrix} & {}={} & \begin{pmatrix} 1 & x_{11} & x_{12} & \cdots & x_{1k} \\ 1 & x_{21} & x_{22} & \cdots & x_{2k} \\ \vdots & \vdots & \vdots & & \vdots \\ 1 & x_{T1} & x_{T2} & \cdots & x_{Tk} \\ \end{pmatrix} & \begin{pmatrix} b_0 \\ b_1 \\ \vdots \\ b_k \end{pmatrix} & {}+{} & \begin{pmatrix} u_1 \\ u_2 \\ \vdots \\ u_T \end{pmatrix} \\ y & {}={} & X & b & {}+{} & u \\ (T,1) & {}={} & (T,k+1) & (k+1,1) & {}+{} & (T,1) \end{array}$

\end{document}


*{<n>}{<col spec>} replicates the column specification <col spec> a total of <n> times; @{<stuff>} inserts <stuff> as the inter-column space between successive columns, so @{} removes the inter-column space (similar to setting \arraycolsep to 0pt) locally. Using \qquad inserts a space of width 2em between the respective columns. So, *{3}{@{}c} @{\qquad} *{3}{c@{}} is shorthand for @{} c @{} c @{} c @{\hspace{2em}} c @{} c @{} c @{}.

Since the dominant display comes from the pmatrix elements, the spacing around them should probably remain consistent. As such, the b and u elements could be spaced out similarly to (k+1,1), as well as adding a little vertical spacing below the matrices:

%...
$\begin{array}{ *{3}{@{}c} @{\qquad} *{3}{c@{}} } \begin{pmatrix} y_1 \\ y_2 \\ \vdots \\ y_T \end{pmatrix} & {}={} & \begin{pmatrix} 1 & x_{11} & x_{12} & \cdots & x_{1k} \\ 1 & x_{21} & x_{22} & \cdots & x_{2k} \\ \vdots & \vdots & \vdots & & \vdots \\ 1 & x_{T1} & x_{T2} & \cdots & x_{Tk} \\ \end{pmatrix} & \begin{pmatrix} b_0 \\ b_1 \\ \vdots \\ b_k \end{pmatrix} & {}+{} & \begin{pmatrix} u_1 \\ u_2 \\ \vdots \\ u_T \end{pmatrix} \\[2\normalbaselineskip] y & {}={} & X & b & {}+{} & u \\ (T,1) & {}={} & (T,k+1) & (k+1,1) & {}+{} & (T,1) \\[-\normalbaselineskip] & & & & & \phantom{(k+1,1)} \end{array}$
%...

• Thanks a lot, can you just elaborate a little on the definition of your columns, i.e. *{3}{@{}c} @{\qquad} *{3}{c@{}} ? – Anthony Martin Mar 14 '16 at 19:21
• just a bit of extra space following the row of pmatrix elements would improve the appearance immensely. i'm glad to see the additional space before the last plus on the last line, although it comes at the cost of uneven spacing around the plus between the pmatrix elements. – barbara beeton Mar 14 '16 at 19:32
• @Aerandal: *{<n>}{<col spec>} replicates the column specification <col spec> a total of <n> times; @{<stuff>} inserts <stuff> as the inter-column space between successive columns, so @{} removes the inter-column space (similar to setting \arraycolsep to 0pt) locally. Using \qquad inserts a space of width 2em between the respective columns. So, *{3}{@{}c} @{\qquad} *{3}{c@{}} is shorthand for @{} c @{} c @{} c @{\hspace{2em}} c @{} c @{} c @{}. – Werner Mar 14 '16 at 19:33