8

I am trying to produce 3 matrices on the same line. And on top of the each matrix, there is a name. I tried using tabular for the names and then I use align for the matrices. However, this creates some kind of space between the names and the matrices, which I do not want. Is there a better way to do this ? I have seen other posts but they do not seem to solve my problem. Please note that I need to use bordermatrix because I need to label the rows and columns as well.

\begin{center}
\begin{tabular}{ccc}
Kay & Brian &  Edwin \\
\end{tabular}
\end{center}
\begin{align*}
\bordermatrix{ & I & A \cr
I &1 & 2 \cr
A & 3 & 4
} 
&
\bordermatrix{ & I & A \cr
I &5 & 6 \cr
A & 7 & 8
} 
&
\bordermatrix{ & I & A \cr
I &9 & 10 \cr
A & 11 & 12
} 
\end{align*}
1
  • Welcome to TeX.SE! Please convert your code snippets into a compilable MWE (minimum working example). The MWE should load any and all specialized packages you require as well as all custom commands you use.
    – Mico
    Sep 15, 2013 at 18:48

3 Answers 3

5

The optional argument to \stackon which I set to 3pt, is the spacing between the matrix and the name.

\documentclass{article}
\usepackage{amsmath}
\usepackage[usestackEOL]{stackengine}[2013-09-11]

\begin{document}
\(
\stackon[3pt]{%
\bordermatrix{ & I & A \cr
I &1 & 2 \cr
A & 3 & 4
}%
}{Kay}\quad
\stackon[3pt]{%
\bordermatrix{ & I & A \cr
I &5 & 6 \cr
A & 7 & 8
}%
}{Brian}\quad
\stackon[3pt]{%
\bordermatrix{ & I & A \cr
I &9 & 10 \cr
A & 11 & 12
} %
}{Edwin}
\)
\end{document}

enter image description here

7
  • Do I need to install a package usestackEOL ? Sep 15, 2013 at 19:21
  • @user1769197 No, [usestackEOL] is an package option on the stackengine package. I could actually omit it for this case, because I didn't make use of a stack that employed that feature. Sep 15, 2013 at 19:25
  • But I do need to install stackengine package right ? Sep 15, 2013 at 19:32
  • @user1769197 yes, It is at ctan.org/pkg/stackengine. In the short run, you can place the .sty file in your working directory, if your installation doesn't know how to install it. In the long run, you should figure out where LaTeX would like to place the file on your system. Sep 15, 2013 at 19:41
  • thanks a lot for your great answer. Just want to know where should i place the packages in the long run. Because I dont have "texmf" folder on my system and I am using texmaker at the moment. Sep 15, 2013 at 19:54
5

The following example converts \bordermatrix to a math operator \mathop that allows putting a "limit" (superscript) on top of it.

Just for fun, two variants follow:

  1. Curly brace over the matrix below the label.

  2. Matrix label in the top left corner of the matrix.

\documentclass{article}
\usepackage{amsmath}

\newcommand*{\topbordermatrix}[2]{%
  {\mathop{\bordermatrix{#2}}\limits^{\mbox{#1}}}%
}

\begin{document}
  \begin{align*}
    \topbordermatrix{Kay}{ & I & A \cr
    I &1 & 2 \cr
    A & 3 & 4
    }
    &&
    \topbordermatrix{Brian}{ & I & A \cr
    I &5 & 6 \cr
    A & 7 & 8
    }
    &&
    \topbordermatrix{Edwin}{ & I & A \cr
    I &9 & 10 \cr
    A & 11 & 12
    }
  \end{align*}

  \renewcommand*{\topbordermatrix}[2]{%
    {\overbrace{\bordermatrix{#2}}^{\mbox{#1}}}%
  }
  \begin{align*}
    \topbordermatrix{Kay}{ & I & A \cr
    I &1 & 2 \cr
    A & 3 & 4
    }
    &&
    \topbordermatrix{Brian}{ & I & A \cr
    I &5 & 6 \cr
    A & 7 & 8
    }
    &&
    \topbordermatrix{Edwin}{ & I & A \cr
    I &9 & 10 \cr
    A & 11 & 12
    }
  \end{align*}

  \renewcommand*{\topbordermatrix}[2]{%
    {\settowidth{\dimen0}{$\scriptstyle\text{#1}$}\kern\dimen0}%
    {\settowidth{\dimen0}{$A$}\kern-\dimen0}%
    \kern-\tabcolsep
    \bordermatrix{\hfill\llap{$\scriptstyle\text{#1}$}\kern-\tabcolsep #2}%
  }  
  \begin{align*}
    \topbordermatrix{Kay}{ & I & A \cr
    I &1 & 2 \cr
    A & 3 & 4
    } 
    &&
    \topbordermatrix{Brian}{ & I & A \cr
    I &5 & 6 \cr
    A & 7 & 8
    } 
    &&
    \topbordermatrix{Edwin}{ & I & A \cr
    I &9 & 10 \cr
    A & 11 & 12
    }
  \end{align*} 
\end{document}

Result

1

With {pNiceMatrix} of nicematrix.

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

\begin{center}
\NiceMatrixOptions{first-row,first-col}
\setlength{\tabcolsep}{10pt}
\begin{tabular}{ccc}
Kay & Brian & Edwin \\
$\begin{pNiceMatrix}
  & I & A \\
I & 1 & 2 \\
A & 3 & 4
\end{pNiceMatrix}$
&
$\begin{pNiceMatrix}
  & I & A \\
I & 5 & 6 \\
A & 7 & 8
\end{pNiceMatrix}$
&
$\begin{pNiceMatrix}
  & I  & A \\
I & 9  & 10 \\
A & 11 & 12
\end{pNiceMatrix}$
\end{tabular}
\end{center}

\end{document}

Output of the above code

You must log in to answer this question.

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