4

I would like to create a matrix with arrows next to it. Say, I created a 10x10 matrix in Latex. Then, I want to put one arrow parallel to the "x-axis" of the matrix and I want to label the arrow, e.g. with "variables". The same for the vertical axis which I want to label, say, "observations".

Is there any way to do this in Latex? Thanks in advance!

1
  • 1
    Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}.
    – user31729
    Commented Mar 13, 2015 at 12:26

1 Answer 1

9

Try this. Both arrows should automatically expand base on the size of the matrix. You may want to shorten the horizontal arrow a bit, but it'd be hard to do without manually specifying the width of the matrix through the use of custom spacer such as \hphantom{\hrule{1cm}} replacing the \hphantom part of the code below, unless someone has better idea.

enter image description here

\documentclass{article}
\usepackage{mathtools}
\begin{document}

\newcommand{\mymatrix}[1]{\ensuremath{\left\downarrow\vphantom{#1}\right.\overset{\xrightarrow[\hphantom{#1}]{\text{variables}}}{#1}}}
\begin{equation*}
\text{\tiny observations}\mymatrix{\begin{pmatrix}
        a_{1,1} & a_{1,2} & \cdots & a_{1,n} \\
        a_{2,1} & a_{2,2} & \cdots & a_{2,n} \\
        \vdots  & \vdots  & \ddots & \vdots  \\
        a_{m,1} & a_{m,2} & \cdots & a_{m,n}
        \end{pmatrix}}
\end{equation*}
\end{document}
2
  • Exactly what I was looking for. Thanks a lot, great solution! You're correct about shortening the horizontal arrow, though. It would be nice to have an easy solution here.
    – GS9
    Commented Mar 13, 2015 at 15:07
  • @GS9 You can also use \newcommand{\mymatrix}[1]{\ensuremath{\left\downarrow\vphantom{#1}\right.\overset{\xrightarrow[\hphantom{#1}]{\text{variables}}}{\left(#1\right)}}} and change pmatrix to matrix. This slightly shortens the horizontal arrow because this leave the curly brace out of the automatic horizontal length measurement. Commented Mar 13, 2015 at 15:53

You must log in to answer this question.

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