LaTeX matrix formatting
The following sets the arrangement inside an array
, with the first row handling the labels on top of each bmatrix
, while the second row sets each of the matrices/vectors. \arraystretch
has been increased to spread the content vertically.
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[
\setlength{\arraycolsep}{0pt}% No column separation in array; manual spacing
% by supplying empty groups {} around operators
\renewcommand{\arraystretch}{1.5}% Stretch out content vertically
\begin{array}{ *{8}{c} }
% Header row in \scriptstyle
\scriptstyle W_1 & & % +
\scriptstyle W_2 & & % + ... +
\scriptstyle W_n & & & % = 1/n
\scriptstyle D \\
% Matrix/vector row
\begin{bmatrix}
W_{11} \\ W_{12} \\ \vdots \\ W_{1n}
\end{bmatrix}
& {} + {} &
\begin{bmatrix}
W_{21} \\ W_{22} \\ \vdots \\ W_{2n}
\end{bmatrix}
& {} + \dots + {} &
\begin{bmatrix}
W_{n1} \\ W_{n2} \\ \vdots \\ W_{nn}
\end{bmatrix}
& {} = {} &
\dfrac{1}{n} &
\begin{bmatrix}
W_{11} + W_{21} + \dots + W_{n1} \\
W_{12} + W_{22} + \dots + W_{n2} \\
\vdots \\
W_{1n} + W_{2n} + \dots + W_{nn}
\end{bmatrix}
\end{array}
\]
\end{document}
Since scalar multiplication of a vector results in each component being multiplied by the scalar, some simplification in the presentation makes things line up nicely.
For numbering the equation, you probably want to consider the following solution; it sets the equation number on the math axis.
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{equation}
\setlength{\arraycolsep}{0pt}% No column separation in array; manual spacing
% by supplying empty groups {} around operators
\renewcommand{\arraystretch}{1.5}% Stretch out content vertically
\mathop{\begin{bmatrix}
W_{11} \\ W_{12} \\ \vdots \\ W_{1n}
\end{bmatrix}}^{W_1}
+
\mathop{\begin{bmatrix}
W_{21} \\ W_{22} \\ \vdots \\ W_{2n}
\end{bmatrix}}^{W_2}
+ \dots +
\mathop{\begin{bmatrix}
W_{n1} \\ W_{n2} \\ \vdots \\ W_{nn}
\end{bmatrix}}^{W_n}
=
\dfrac{1}{n}
\mathop{\begin{bmatrix}
W_{11} + W_{21} + \dots + W_{n1} \\
W_{12} + W_{22} + \dots + W_{n2} \\
\vdots \\
W_{1n} + W_{2n} + \dots + W_{nn}
\end{bmatrix}}^{D}
\end{equation}
\end{document}
A proposition with the mmatrix
environment (medium size matrix) from nccmath
and cellspace
for a proper row spacing:
\documentclass{article}
\usepackage{amsmath, nccmath}
\usepackage[math]{cellspace}
\setlength{\cellspacetoplimit}{2pt}
\setlength{\cellspacebottomlimit}{2pt}
\newenvironment{bmmatrix}{\begin{bmatrix} \begin{mmatrix}}{\end{mmatrix}\end{bmatrix}}
\begin{document}
\begin{alignat}{3}
\begin{matrix}
W_1 \\
\begin{bmmatrix}
W_{11} \\
W_{12} \\[-1.5ex]
\vdots \\
W_{1n}
\end{bmmatrix}
\end{matrix} &+ &
\begin{matrix}
W_2 \\
\begin{bmmatrix}
W_{21} \\
W_{22} \\[-1.5ex]
\vdots \\
W_{2n}
\end{bmmatrix}
\end{matrix}
&+ \hdots{}
&
+ \begin{matrix}
W_n \\
\begin{bmmatrix}
W_{n1} \\
W_{n2} \\[-1.5ex]
\vdots \\
W_{nn}
\end{bmmatrix}
\end{matrix}
&=
\begin{matrix}
D \\
\begin{bmatrix}
\mfrac{W_{11} + W_{21} + \hdots + W_{n1}}{n} \\[-1ex]
\smash[b]{ \vdots }\\[-0.5ex]
\mfrac{W_{1n} + W_{2n} + \hdots + W_{nn}}{n}
\end{bmatrix}
\end{matrix}
\end{alignat}
\end{document}
You can make use of the \overset
command from the amsmath
package; this lines up your code with the intended meaning, and avoids setting up any extra array structures for the contents of your equation.
If you've got a scalar factor next to a matrix (as suggested in another answer), then \overbrace
makes it clear that the scalar factor is included within the annotated object.
\documentclass[10pt]{article}
\usepackage{amsmath} %maths
\begin{document}
\begin{equation}
\overset{W_{1}}{
\begin{bmatrix}
W_{11} \\ W_{12} \\ \vdots \\ W_{1n}
\end{bmatrix}}
%
+
%
\overset{W_{2}}{\begin{bmatrix}
W_{21} \\ W_{22} \\ \vdots \\ W_{2n}
\end{bmatrix}}
%
+\dots+
%
\overset{W_{n}}{\begin{bmatrix}
W_{n1} \\ W_{n2} \\ \vdots \\ W_{nn}
\end{bmatrix}}
%
=
%
\overbrace{ \dfrac{1}{n}
\begin{bmatrix}
W_{11} + W_{21} + \dots + W_{n1} \\
W_{12} + W_{22} + \dots + W_{n2} \\
\vdots \\
W_{1n} + W_{2n} + \dots + W_{nn}
\end{bmatrix}}^{D}
\end{equation}
\end{document}