8

I'm writing a little array whose elements are matrices of different sizes, and I want them aligned by their top rows.

Here's the sort of thing:

\documenstyle{article}
\use{mathtools}
\begin{document}
\begin{array}{ccc}
I_2&I_3&I_4\\
\hline
\begin{bmatrix}
   1&0\\ 0&1
\end{bmatrix}
\begin{bmatrix}
   1&0&0\\ 0&1&0\\ 0&0&1
\end{bmatrix}
\begin{bmatrix}
   1&0&0&0\\ 0&1&0&0\\ 0&0&1&0\\ 0&0&0&1
\end{bmatrix}
\end{array}
\end{document}

But the matrices are vertically centred:

LaTeX matrices

I can get the matrices vertically aligned by their top rows by using raisebox but this is fiddly:

\documentclass{article}
\usepackage{mathtools}
\begin{document}
\[
  \begin{array}{ccc}
    I_2&I_3&I_4\\
    \hline
    \rule{0mm}{11mm}\raisebox{4mm}{\begin{bmatrix}
      1&0\\ 0&1
    \end{bmatrix}}
    &
    \raisebox{2mm}{\begin{bmatrix}
      1&0&0\\ 0&1&0\\ 0&0&1
    \end{bmatrix}}
    &
    \begin{bmatrix}
      1&0&0&0\\ 0&1&0&0\\ 0&0&1&0\\ 0&0&0&1
    \end{bmatrix}
  \end{array}
\]
\end{document}

LaTeX matrices aligned

This is the effect I want - but surely there's a better way of obtaining this alignment than trial-and-error with raisebox?

3 Answers 3

6

Use the \belowbaseline macro of the stackengine package. It will place the top of its argument a given distance below the baseline. The distance is given either as an optional argument (\belowbaseline[<gap>]{...}), or else may be set as the default optional argument via \setstackgap{S}{<gap>}.

There is a comparable \abovebaseline macro for setting the bottom of an object at a given vertical level relative to the baseline.

\documentclass{article}
\usepackage{mathtools,stackengine}
\begin{document}
\[
\begin{array}{ccc}
I_2&I_3&I_4\\
\hline
\belowbaseline[-3pt]{$\begin{bmatrix}
   1&0\\ 0&1
\end{bmatrix}$}
&
\belowbaseline[-3pt]{$\begin{bmatrix}
   1&0&0\\ 0&1&0\\ 0&0&1
\end{bmatrix}$}
&
\belowbaseline[-3pt]{$\begin{bmatrix}
   1&0&0&0\\ 0&1&0&0\\ 0&0&1&0\\ 0&0&0&1
\end{bmatrix}$}
\end{array}
\]
\end{document}

enter image description here

Note that the $ delimiters in the \belowbaseline argument can be eliminated if \stackMath (rather than the default \stackText) is in force.

5

You can use delarray:

\documentclass{article}
\usepackage{delarray,booktabs}

\begin{document}

\[
\begin{array}{ccc}
I_2&I_3&I_4\\
\midrule
\begin{array}[t]\lbrack{@{}cc@{}}\rbrack
   1&0\\ 0&1
\end{array}
&
\begin{array}[t]\lbrack{@{}ccc@{}}\rbrack
   1&0&0\\ 0&1&0\\ 0&0&1
\end{array}
&
\begin{array}[t]\lbrack{@{}cccc@{}}\rbrack
   1&0&0&0\\ 0&1&0&0\\ 0&0&1&0\\ 0&0&0&1
\end{array}
\end{array}
\]

\end{document}

The spacing of the horizontal rule is better with \midrule from booktabs.

enter image description here

3

You can do that with the environment {bNiceMatrix} of nicematrix which has a key t.

\documentclass{article}
\usepackage{nicematrix}
\begin{document}
$\begin{array}{ccc}
I_2&I_3&I_4\\
\hline
\rule{0pt}{10pt}
\begin{bNiceMatrix}[t]
   1&0\\ 0&1
\end{bNiceMatrix}
& 
\begin{bNiceMatrix}[t]
   1&0&0\\ 0&1&0\\ 0&0&1
\end{bNiceMatrix}
& 
\begin{bNiceMatrix}[t]
   1&0&0&0\\ 0&1&0&0\\ 0&0&1&0\\ 0&0&0&1
\end{bNiceMatrix}
\end{array}$
\end{document}

You need several compilations (because nicematrix uses PGF/Tikz nodes under the hood).

Output of the above code

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .