10

I would like your advice on writing a matrix with latex. In order to explain the meaning of the rows and columns, the matrix should be surrounded by two arrows, one on the left side pointing downward and one on the upper side pointing to the right. Where the arrows are labeled. I tried several things such as:

\[
M_{reg} = \bordermatrix{~  & 0 & 1 & 2 & 3 & 4 &  \cr
                  0 & 0 & 0 & 0 & 1 & 1 \cr
                  1 & 0 & 0 & 1 & 1 & 1 \cr
                  2 & 0 & 0 & 1 & 1 & 0 \cr
                  3 & 0 & 0 & 1 & 1 & 0 \cr
                  4 \downarrow{Ca^{2+}} & 0 & 0 & 0 & 0 & 0 \cr
                  %Ca^{2+}
                  }^{\xrightarrow{DAG}}
\]

But it's not pretty and things are not correctly aligned. Do you have any ideas, or pointers to draw that matrix correctly ?

Roelof Spijker
  • 17,663
  • 5
  • 55
  • 63
Albert
  • 103

3 Answers3

10

Another way with TikZ similar to Highlight elements in the matrix:

\documentclass{article}
\usepackage{tikz}
\newcommand{\tikzmark}[1]{\tikz[overlay, remember picture] \coordinate (#1);}
\begin{document}
\[
  M_{reg} = \qquad \bordermatrix{~  & \tikzmark{harrowleft} 0 & 1 & 2 & 3
                        & 4\tikzmark{harrowright}  \cr
                    \tikzmark{varrowtop} 0 & 0 & 0 & 0 & 1 & 1 \cr
                    1 & 0 & 0 & 1 & 1 & 1 \cr
                    2 & 0 & 0 & 1 & 1 & 0 \cr
                    3 & 0 & 0 & 1 & 1 & 0 \cr
                    \tikzmark{varrowbottom}4 & 0 & 0 & 0 & 0 & 0 \cr
                    }
\]
\tikz[overlay,remember picture] {
  \draw[->] ([yshift=3ex]harrowleft) -- ([yshift=3ex]harrowright)
            node[midway,above] {\scriptsize DAG};
  \draw[->] ([yshift=1.5ex,xshift=-2ex]varrowtop) -- ([xshift=-2ex]varrowbottom)
            node[near end,left] {\scriptsize $Ca^{2+}$};
}
\end{document}

Matrix with arrows

Stefan Kottwitz
  • 231,401
5

You can use TikZ to annotate the matrix.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\[
M_{reg} = \bordermatrix{~  & 0 & 1 & 2 & 3 & \tikz[remember picture]\node[inner sep=0pt] (a) {4}; & \cr
                  0 & 0 & 0 & 0 & 1 & 1 \cr
                  1 & 0 & 0 & 1 & 1 & 1 \cr
                  2 & 0 & 0 & 1 & 1 & 0 \cr
                  3 & 0 & 0 & 1 & 1 & 0 \cr
                  \tikz[remember picture]\node[inner sep=0pt] (b) {4}; & 0 & 0 & 0 & 0 & 0 \cr
                  }
\]
  \begin{tikzpicture}[overlay, remember picture]
    \draw[->] (a.east) ++(2mm,0) -- node[above] {DAG} ++(1,0);
    \draw[->] (b.south) ++(0,-2mm) -- node[right] {$Ca^{2+}$} ++(0,-1);
  \end{tikzpicture}
\end{document}

The result:

TikZ annotated matrix

There is an extra space between the last column and the closing parenthesis because you have an extra & on the first row. I left that in my code, because I though you might have a reason for it. If you don't you can just remove it and the spacing will be correct.

Roelof Spijker
  • 17,663
  • 5
  • 55
  • 63
  • Thanks a lot ! That's a nice starting point ! Ideally, I would like to avoid the enumeration and have an arrow all above and on the left side of the matrix – Albert Jan 09 '12 at 15:22
0

With {NiceArray} of nicematrix and Tikz to draw the arrows.

\documentclass{article}
\usepackage{nicematrix,tikz}

\begin{document}

$\begin{NiceArray}{ccccccc} & & \Block{1-}{\text{\small DAG}}\ \rule{0pt}{12pt} & & 0 & 1 & 2 & 3 & 4 \ \Block{-1}{\text{Ca}^{2+}} & 0 & 0 & 0 & 0 & 1 & 1 \ & 1 & 0 & 0 & 1 & 1 & 1 \ & 2 & 0 & 0 & 1 & 1 & 0 \ & 3 & 0 & 0 & 1 & 1 & 0 \ & 4 & 0 & 0 & 0 & 0 & 0 \ \CodeAfter \SubMatrix({3-3}{7-7}) \tikz \draw [->] (2-|3) -- ([xshift=1mm]2-|last) ; \tikz \draw [->] (3-|2) -- ([yshift=1mm]last-|2) ; \end{NiceArray}$

\end{document}

You need several compilations (because of the PGF/Tikz nodes).

Output of the above code

F. Pantigny
  • 40,250