我有一个tikz
matrix
,其中一些单元格是矩形分割的,我如何在的两个部分中设置文本rectangle split
?
这是 MWE。我希望在矩形分割的两个部分都包含文本...
\documentclass{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{amsfonts}
\usepackage{amsmath} % \text nas equacoes
\usepackage[left=3.5cm,right=1.5cm,top=2.5cm,bottom=2.0cm,bindingoffset=-1cm]{geometry}
\usepackage{indentfirst}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,matrix,fit,shapes}
\begin{document}
\begin{figure}[htb]
\centering
\begin{tikzpicture}
\tikzset{
status/.style={draw=black, minimum width=2em, minimum height=2em, text=gray, anchor=center},
mstyle/.style={nodes={status}, column sep=0.12em, row sep=0.12em},
splitstyle/.style={rectangle split, rectangle split horizontal, rectangle split parts=2, rectangle split every empty part={}, rectangle split empty part width={0.3em}, anchor=center},
line/.style={draw,ultra thick,-latex},
row 2 column 2/.style={nodes={fill=green}},
row 1 column 3/.style={nodes={splitstyle, rectangle split part fill={green,orange}}},
row 2 column 3/.style={nodes={fill=green}},
row 4 column 2/.style={nodes={splitstyle, rectangle split part fill={red,green}}},
row 3 column 6/.style={nodes={fill=green}},
row 4 column 3/.style={nodes={fill=orange}},
row 4 column 5/.style={nodes={fill=orange}},
row 3 column 4/.style={nodes={fill=red}},
row 1 column 6/.style={nodes={fill=red}},
}
\matrix(m)[matrix of nodes,ampersand replacement=\&,mstyle]{
0 \& 0 \& {} \& 0 \& 0 \& 3 \\
0 \& 4 \& 5 \& 0 \& 0 \& 0 \\
0 \& 0 \& 0 \& 6 \& 0 \& 7 \\
0 \& 8 \& 10 \& 0 \& 11 \& 0 \\
};
\draw[line] (m-4-5.center) -- (m-3-4.center);
\draw[line] (m-1-6.center) -- (m-3-6.center);
\draw[line] (m-2-2.center) -- (m-4-1.center);
\end{tikzpicture}
\end{figure}
\end{document}
只是为了说清楚。我想在红色圆圈处添加文本。我可以使用这种矩阵方法吗?
答案1
您必须直接在节点内部应用分割。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,matrix,fit,shapes,backgrounds}
\begin{document}
\begin{figure}[htb]
\centering
\begin{tikzpicture}
\tikzset{
status/.style={draw=black, minimum width=2em, minimum height=2em, text=gray, anchor=center},
mstyle/.style={nodes={status}, column sep=0.12em, row sep=0.12em},
splitstyle/.style={inner sep=0.23em,rectangle split, rectangle split horizontal, rectangle split parts=2,rectangle split every empty part={}, rectangle split empty part width={0.3em}, anchor=center},
line/.style={draw,ultra thick,-latex},
row 2 column 2/.style={nodes={fill=green}},
%row 1 column 3/.style={nodes={splitstyle, rectangle split part fill={green,orange}}},
row 2 column 3/.style={nodes={fill=green}},
%row 4 column 2/.style={nodes={splitstyle, rectangle split part fill={red,green}}},
row 3 column 6/.style={nodes={fill=green}},
row 4 column 3/.style={nodes={fill=orange}},
row 4 column 5/.style={nodes={fill=orange}},
row 3 column 4/.style={nodes={fill=red}},
row 1 column 6/.style={nodes={fill=red}},
}
\matrix(m)[matrix of nodes,ampersand replacement=\&,mstyle]{
0 \& 0 \& |[splitstyle,rectangle split part fill={green,orange}]| 0\nodepart{two}8 \& 0 \& 0 \& 3 \\
0 \& 4 \& 5 \& 0 \& 0 \& 0 \\
0 \& 0 \& 0 \& 6 \& 0 \& 7 \\
0 \& |[splitstyle,rectangle split part fill={orange,green}]| 8\nodepart{two}0 \& 10 \& 0 \& 11 \& 0 \\
};
\draw[line] (m-4-5.center) -- (m-3-4.center);
\draw[line] (m-1-6.center) -- (m-3-6.center);
\draw[line] (m-2-2.center) -- (m-4-1.center);
\end{tikzpicture}
\end{figure}
\end{document}