7

The following matrix equation looks great:

\begin{align*}
\overset{A}{\left[\begin{matrix}t_{1}&1\\ 
\vdots&\vdots\\
t_{n}&1
\end{matrix}\right]}
\overset{x}{\left[\begin{matrix}
x_{1}\\x_{2}
\end{matrix}\right]}
&=
\overset{b}{\left[\begin{matrix}
b_{1}\\ \vdots \\ b_{n}
\end{matrix}\right]}
\end{align*}

Except I am accustomed to having the tops of my matrices aligned when I write on scratch paper. How can I accomplish this in LaTeX?

David Carlisle
  • 757,742
Roci
  • 73

3 Answers3

7

A note before, amsmath provides special *matrix environments:

  • pmatrix for ( · )
  • bmatrix for [ · ]
  • Bmatrix for { · }
  • vmatrix for | · |
  • Vmatrix for || · ||

Solution 1

I used the \vphantom macro that resizes the box inside the \overset to same height like the other parts.

Code

\documentclass{article}
\usepackage{amsmath}
\newcommand*\biggestpart{}
\begin{document}
\renewcommand*\biggestpart{
  \begin{bmatrix}
    t_1    & 1 \\
    \vdots & \vdots \\
    t_n    & 1
  \end{bmatrix}
}
\begin{align*}
\overset{A}{\biggestpart}
\overset{x}{
  \vphantom{\biggestpart}
  \begin{bmatrix}
    x_1 \\ x_2
  \end{bmatrix}
}
&=
\overset{b}{
  \begin{bmatrix}
    b_1 \\ \vdots \\ b_n
  \end{bmatrix}
}
\end{align*}
\end{document}

Output

enter image description here

Solution 2

As the second row in the bigger matrices are not of the same height of x_2 the \vphantom command is used again (try it without to see the effect or replace \vdots with “normal” math stuff like x_0).

Code

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
\overset{A}{
  \begin{bmatrix}
    t_1    & 1 \\
    \vdots & \vdots \\
    t_n    & 1
  \end{bmatrix}}
\overset{x}{
\begin{array}{@{}c@{}}{
  \begin{bmatrix}
    x_1 \\ x_2 \vphantom{\vdots}
  \end{bmatrix}}\\
  \\
  \end{array}
}
&=
\overset{b}{
  \begin{bmatrix}
    b_1 \\ \vdots \\ b_n
  \end{bmatrix}
}
\end{align*}
\end{document}

Output

enter image description here

David Carlisle
  • 757,742
Qrrbrbirlbel
  • 119,821
  • In the second solution, what does @{}c@{} do? – alexpghayes Jul 05 '22 at 18:30
  • 1
    @alexpghayes array is the math version of tabular, its first argment is the column specification. c stands for a horizontally centered column, @{<stuff>} inserts <stuff> between columns (or in this case before the first or after the last column) instead of the usual horizontal space. Since <stuff> is nothing we don't have any horizontal space between the content and the delimiters [ and ]. – Qrrbrbirlbel Jul 05 '22 at 19:16
  • 1
    @alexpghayes Internally, AMSmath uses array for its matrix environments in a similar way. – Qrrbrbirlbel Jul 05 '22 at 19:21
3

Here is a sans-amsmath version of Qrrbrbirlbel's answer:

enter image description here

\documentclass{article}
\newcommand{\matlabel}[2]{% \matlabel{<label>}{<stuff>}
  \begin{array}{@{}c@{}} \mbox{\small$#1$} \\ #2 \end{array}
}
\begin{document}
\[
  \matlabel{A}{\left[\begin{array}{@{}cc@{}}
      t_1 & 1 \\
      \vdots & \vdots \\
      t_n & 1
    \end{array}\right]}
  \matlabel{x}{\left[\begin{array}{@{}c@{}}
      x_1 \\ \vphantom\vdots x_2 \\
    \end{array}\right] \\
    \mathstrut}\mathrel{\raisebox{-.5\normalbaselineskip}{=}}
  \matlabel{b}{\left[\begin{array}{@{}c@{}}
      b_1 \\ \vdots \\ b_n
    \end{array}\right]}
\]
\end{document}

The only major difference is the setting of the matrix label as an element in an "vertical array", rather than an "upper limit in a math operator." As a consequence, the vertical alignment with respect to the mathematical axis has to be adjusted... using \mathrel{\raisebox{-.5\normalbaselineskip}{=}}.

Moriambar
  • 11,466
Werner
  • 603,163
2

This is janky but I wanted something dead simple so I just wrapped a \raisebox{0.5em}{$ [matrix goes here] $} around the matrix that was too low and adjusted the distance until it looked ok.

Note, \raisebox seems to put you back into text mode so you have to wrap the matrix in $ $.

Before:

enter image description here

\begin{align*}
x^T x:  
\begin{bmatrix} 
x_1 \\
x_2 \\
x_3
\end{bmatrix}
\begin{bmatrix} 
x_1 & x_2 & x_3\\
\end{bmatrix}
\end{align*}

After:

enter image description here

\begin{align*}
    x^T x:  
    \begin{bmatrix} 
    x_1 \\
    x_2 \\
    x_3
    \end{bmatrix}
    \raisebox{1.15em}{$
    \begin{bmatrix} 
    x_1 & x_2 & x_3\\
    \end{bmatrix}
    $}
\end{align*}
Casey L
  • 221