2

I would like to define one matrix relative another, similarly as I have done with the red arrow at the right-hand side. For instance, I tried \matrix(c1) at (m.center)++(3,0) [matrix of math nodes,text=blue, nodes={minimum size=1cm}] which gives an error. I am sure that there is a way, but I can't find it. How it is done?

\documentclass[border=5pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}

\usepackage{tikz}
\usetikzlibrary{matrix,shapes,arrows,calc}




\begin{document}

\begin{tikzpicture}

\matrix(m) [matrix of math nodes, 
         left delimiter=(,right delimiter={)}, nodes={minimum size=1cm, outer sep=0pt, text height=1.5ex, text depth=.25ex}]
{
15 & 3 & 30 & 20 \\
20 & 2 & 20 & 30\\
40 & 20 & 10 & 40 \\
5 & 30 & 40 & 40 \\
};

\matrix(c1) at (-3,0) [matrix of math nodes,text=blue, nodes={minimum size=1cm}]
{
A \\
B \\
C \\
D \\
};

\matrix(r1) at (0,2.5) [matrix of math nodes,text=blue, nodes={minimum size=1cm}]
{
I & II & III & IV \\
};

\path (m.center)++(3,0) node [text=red] {\huge $\Rightarrow$};

\end{tikzpicture}
\end{document}

enter image description here

1 Answer 1

3

Just use positioning library and define your nodes or matrices with right = <distance> of <node>.

matrix positioning

\documentclass[border=5pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}

\usepackage{tikz}
\usetikzlibrary{positioning,matrix,shapes,arrows,calc}




\begin{document}

\begin{tikzpicture}

\matrix(m) [matrix of math nodes, 
         left delimiter=(,right delimiter={)}, nodes={minimum size=1cm, outer sep=0pt, text height=1.5ex, text depth=.25ex}]
{
15 & 3 & 30 & 20 \\
20 & 2 & 20 & 30\\
40 & 20 & 10 & 40 \\
5 & 30 & 40 & 40 \\
};

\matrix(c1) at (-3,0) [matrix of math nodes,text=blue, nodes={minimum size=1cm}]
{
A \\
B \\
C \\
D \\
};

\matrix(r1) at (0,2.5) [matrix of math nodes,text=blue, nodes={minimum size=1cm}]
{
I & II & III & IV \\
};

\node [right = 5mm of m, text=red] (arr) {\huge $\Rightarrow$};

\matrix(m2) [right= 5mm of arr,matrix of math nodes, 
         left delimiter=(,right delimiter={)}, nodes={minimum size=1cm, outer sep=0pt, text height=1.5ex, text depth=.25ex}]
{
15 & 3 & 30 & 20 \\
20 & 2 & 20 & 30\\
40 & 20 & 10 & 40 \\
5 & 30 & 40 & 40 \\
};
\end{tikzpicture}
\end{document}
1
  • 1
    That's what I was looking after! Thanks! Commented May 2, 2021 at 18:19

You must log in to answer this question.

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