使用 Tikz 定义相对于其他矩阵的一个矩阵

使用 Tikz 定义相对于其他矩阵的一个矩阵

我想定义一个矩阵相对于另一个矩阵,就像我使用右侧的红色箭头所做的那样。例如,我尝试了,但\matrix(c1) at (m.center)++(3,0) [matrix of math nodes,text=blue, nodes={minimum size=1cm}]出现了错误。我确信有办法,但我找不到。怎么做?

\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}

在此处输入图片描述

答案1

只需使用positioning库并定义您的节点或矩阵right = <distance> of <node>

矩阵定位

\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}

相关内容