我无法获得具有相同高度(10 厘米)的图形。当一个分区被分成更多部分时,高度显然会增加。如何解决这个问题?
这是一个可重现的例子。
\documentclass[a4paper]{scrbook}
\usepackage[hmargin=2.5cm,vmargin=2.5cm]{geometry}
\usepackage[utf8x]{inputenc}
\usepackage{caption}
\usepackage{latexsym}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{subcaption}
\usepackage{calc}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows,positioning,shapes,calc,arrows}
\newcommand\Textbox[2]{%
\parbox[c][#1][c]{2.3cm}{\centering#2}}
\begin{document}
\begin{figure}
\begin{subfigure}[b]{0.32\textwidth}
\centering
\resizebox{\linewidth}{!}{
\begin{tikzpicture}
\node (h1) {\textbf{Text I}};
\node[draw,
align=center,
text width=2.5cm,
%minimum height=7cm,
draw=red!50,
rectangle split,
rectangle split parts=3, below of= h1,yshift=.5cm,
rectangle split part fill={gray!30, blue!20, green!15},
anchor=north east]{\textbf{Tit A}
\nodepart{two}\Textbox{6.7cm}{Cir 1\\67\% }
\nodepart{three}\Textbox{3.3cm}{Cir 2\\33\%} };
\node[draw,
align=center,
text width=2.5cm,
%minimum height=7cm,
draw=red!50,
rectangle split,
rectangle split parts=4, below of=h1,yshift=0.5cm,
rectangle split part fill={gray!30, blue!15, green!15,green!30},
anchor=north west]{\textbf{Tit B}
\nodepart{two}\Textbox{4.6cm}{Cir 1\\ 46\%}
\nodepart{three}\Textbox{3cm}{Met \\30\%}
\nodepart{four}\Textbox{2.4cm}{Let\\24\%} };
\end{tikzpicture}
}
\end{subfigure}
\begin{subfigure}[b]{0.32\textwidth}
\centering
\resizebox{\linewidth}{!}{
\begin{tikzpicture}
\node (h1) {\textbf{Text II}};
\node[draw,
align=center,
text width=2.5cm,
%minimum height=7cm,
draw=red!50,
rectangle split,
rectangle split parts=3, below of= h1,yshift=0.5cm,
rectangle split part fill={gray!30, blue!20, green!15},
anchor=north east]{\textbf{Tit A}
\nodepart{two}\Textbox{3.3cm}{Part 1\\33\% }
\nodepart{three}\Textbox{6.7cm}{Part 2\\67\%} };
\node[draw,
align=center,
text width=2.5cm,
%minimum height=7cm,
draw=red!50,
rectangle split,
rectangle split parts=5, below of=h1,yshift=0.5cm,
rectangle split part fill={gray!30, blue!15, green!15,green!30,yellow!15},
anchor=north west]{\textbf{Tit B}
\nodepart{two}\Textbox{3.3cm}{Cr1 \\ 33\%}
\nodepart{three}\Textbox{2.5cm}{Cr2\\25\%}
\nodepart{four}\Textbox{2.2cm}{Cr3\\22\%}
\nodepart{five}\Textbox{2.0cm}{Cr4\\20\%} };
\end{tikzpicture}
}
\end{subfigure}
\end{figure}
\end{document}
谢谢你的帮助!
答案1
在tex.SE@Steven B. Segletes 建议修改\Textbox
命令,从每个分割高度中减去 7.7pt。
\newcommand\Textbox[2]{%
\parbox[c][\dimexpr#1-7.7pt][c]{2.3cm}{\centering#2}}