Math & ScienceMatrix with labels

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
Antobiotic
Posts: 1
Joined: Mon Jan 09, 2012 1:47 pm

Matrix with labels

Post by Antobiotic »

Dear all,

I would need your advices to write a pretty 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 to the bottom and one on the upper side pointing on the right. With each arrows labeled by a name.
I tried several things such as:

Code: Select all

\[
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 ?


Best regards,

Antobiotic.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Matrix with labels

Post by localghost »

It would be very kind if you mention when doing a crossposting [1]*. This is only fair because it prevents others from double efforts and waste of time.

And you got an answer there which you accepted. So, do you want others here to solve a problem that is already solved?

* According to the rules you are obliged to do so.

[1] {TeX} SX – Matrix with arrows and labels


Best regards and welcome to the board
Thorsten
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Matrix with labels

Post by Stefan Kottwitz »

Hi,

welcome to the board!

A solution, also posted to the linked site:

Code: Select all

\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.png
matrix.png (3.48 KiB) Viewed 10773 times
Btw. I guess it would be good to typeset reg and Ca in upright shape.

Stefan
LaTeX.org admin
Post Reply