我正在根据给定的代码进行工作这里.我有这个:
\newcommand\Textbox[2]{%
\parbox[c][\dimexpr#1-7.7pt][c]{2cm}{\centering#2}}
\tikzstyle{partition}=[draw,
align=center,
color=blue,
rectangle split,]
\begin{tikzpicture}[font=\footnotesize]
\node[partition,
rectangle split parts=7,
rectangle split part fill={gray!30, blue!15}] (start) {
\textbf{Start}
\nodepart{two} \Textbox{30.0pt}{300 KB}
\nodepart{three}\Textbox{60.0pt}{600 KB}
\nodepart{four} \Textbox{35.0pt}{350 KB}
\nodepart{five} \Textbox{20.0pt}{200 KB}
\nodepart{six} \Textbox{75.0pt}{750 KB}
\nodepart{seven}\Textbox{12.5pt}{125 KB}
};
% 115 KB
\node[right=0.5em of start,
partition,
rectangle split parts=8,
rectangle split part fill={
gray!30,
blue!15, blue!15, blue!15, blue!15, blue!15, green!15, blue!15
}] (step1) {
\textbf{Step 1}
\nodepart{two} \Textbox{30.0pt}{300 KB}
\nodepart{three}\Textbox{60.0pt}{600 KB}
\nodepart{four} \Textbox{35.0pt}{350 KB}
\nodepart{five} \Textbox{20.0pt}{200 KB}
\nodepart{six} \Textbox{75.0pt}{750 KB}
\nodepart{seven}\Textbox{11.5pt}{115 KB}
\nodepart{eight}\Textbox{01.0pt}{10 KB}
};
% 500 KB
\node[right=0.5em of step1,
partition,
rectangle split parts=9,
rectangle split part fill={
gray!30,
blue!15, green!15, blue!15,blue!15,blue!15,blue!15, green!15, blue!15
}] (step2) {
\textbf{Step 2}
\nodepart{two} \Textbox{30.0pt}{300 KB}
\nodepart{three}\Textbox{50.0pt}{500 KB}
\nodepart{four} \Textbox{10.0pt}{100 KB}
\nodepart{five} \Textbox{35.0pt}{350 KB}
\nodepart{six} \Textbox{20.0pt}{200 KB}
\nodepart{seven}\Textbox{75.0pt}{750 KB}
\nodepart{eight}\Textbox{11.5pt}{115 KB}
\nodepart{nine} \Textbox{01.0pt}{10 KB}
};
% 358 KB
\node[right=0.5em of step2,
partition,
rectangle split parts=10,
rectangle split part fill={
gray!30,
blue!15, green!15, blue!15, blue!15, blue!15, green!15, blue!15, green!15, blue!15
}] (step3) {
\textbf{Step 3}
\nodepart{two} \Textbox{30.0pt}{300 KB}
\nodepart{three}\Textbox{50.0pt}{500 KB}
\nodepart{four} \Textbox{10.0pt}{100 KB}
\nodepart{five} \Textbox{35.0pt}{350 KB}
\nodepart{six} \Textbox{20.0pt}{200 KB}
\nodepart{seven}\Textbox{35.8pt}{358 KB}
\nodepart{eight}\Textbox{39.2pt}{392 KB}
\nodepart{nine} \Textbox{11.5pt}{115 KB}
\nodepart{ten} \Textbox{01.0pt}{10 KB}
};
% 200 KB
\node[right=0.5em of step3,
partition,
rectangle split parts=10,
rectangle split part fill={
gray!30,
blue!15, green!15, blue!15, blue!15, green!15, green!15, blue!15, green!15, blue!15
}] (step4) {
\textbf{Step 4}
\nodepart{two} \Textbox{30.0pt}{300 KB}
\nodepart{three}\Textbox{50.0pt}{500 KB}
\nodepart{four} \Textbox{10.0pt}{100 KB}
\nodepart{five} \Textbox{35.0pt}{350 KB}
\nodepart{six} \Textbox{20.0pt}{200 KB}
\nodepart{seven}\Textbox{35.8pt}{358 KB}
\nodepart{eight}\Textbox{39.2pt}{392 KB}
\nodepart{nine} \Textbox{11.5pt}{115 KB}
\nodepart{ten} \Textbox{01.0pt}{10 KB}
};
% 375 KB
\node[right=0.5em of step4,
partition,
rectangle split parts=11,
rectangle split part fill={
gray!30,
blue!15, green!15, blue!15, blue!15, green!15, green!15, green!15, blue!15, green!15, blue!15
}] (step5) {
\textbf{Step 5}
\nodepart{two} \Textbox{30.0pt}{300 KB}
\nodepart{three} \Textbox{50.0pt}{500 KB}
\nodepart{four} \Textbox{10.0pt}{100 KB}
\nodepart{five} \Textbox{35.0pt}{350 KB}
\nodepart{six} \Textbox{20.0pt}{200 KB}
\nodepart{seven} \Textbox{35.8pt}{358 KB}
\nodepart{eight} \Textbox{37.5pt}{375 KB}
\nodepart{nine} \Textbox{1.7pt}{17 KB}
\nodepart{ten} \Textbox{11.5pt}{115 KB}
\nodepart{eleven}\Textbox{01.0pt}{10 KB}
};
\end{tikzpicture}
我该怎么做才能清理它以便它能够适用于最小的切片?
答案1
最好不要将标签作为内容放置在节点上,因为节点总是会尝试与其内容一样大。另外,我不确定诸如此类的多部分节点是否rectangle split
真的是最佳选择,因为rectangle split
节点不允许您轻松定义不同部分的特定高度。
我可能会用pic
这个:
\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\newcounter{multipartblockvalue}
\newcounter{multipartblocklabel}
\newcounter{multipartblockfill}
\tikzset{
pics/multipart block/.style={
code={
\tikzset{multipart block/.cd, reset counters, #1}
\node (-head) at (0,0)
[multipart block/head]
{\pgfkeysvalueof{/tikz/multipart block/head content}};
\foreach \v/\c/\f [count=\i] in {1,...,\pgfkeysvalueof{/tikz/multipart block/parts count}} {
\pgfmathtruncatemacro{\lasti}{\i-1}
\tikzset{
multipart block/part \i/.initial={},
multipart block/part label \i/.initial={}
}
\ifnum\lasti=0\relax
\node (-part \i) at ([yshift={\pgflinewidth}]-head.south)
[anchor=north, multipart block/parts, multipart block/part \i]
{};
\else
\node (-part \i) at ([yshift={\pgflinewidth}]-part \lasti.south)
[anchor=north, multipart block/parts, multipart block/part \i]
{};
\fi
\node (-part label \i) at (-part \i)
[multipart block/part label \i]
{};
}
}
},
multipart block/reset counters/.code={
\setcounter{multipartblockvalue}{0}
\setcounter{multipartblocklabel}{0}
\setcounter{multipartblockfill}{0}
},
multipart block/step value counter/.code={
\stepcounter{multipartblockvalue}
},
multipart block/step label counter/.code={
\stepcounter{multipartblocklabel}
},
multipart block/step fill counter/.code={
\stepcounter{multipartblockfill}
},
multipart block/parts count/.initial={1},
multipart block/parts value/.style={
/tikz/multipart block/step value counter,
/tikz/multipart block/part \themultipartblockvalue/.append style={
text height={#1 pt}, inner sep=0pt
}
},
multipart block/parts label/.style={
/tikz/multipart block/step label counter,
/tikz/multipart block/part label \themultipartblocklabel/.append style={
node contents={#1}
}
},
multipart block/parts fill/.style={
/tikz/multipart block/step fill counter,
/tikz/multipart block/part \themultipartblockfill/.append style={
fill={#1}
}
},
multipart block/parts value/.initial={},
multipart block/parts label/.initial={},
multipart block/parts fill/.initial={},
multipart block/parts/.style={draw, fill=blue!15},
multipart block/head content/.initial={header},
multipart block/head/.style={draw, fill=gray!30, text depth=0pt},
}
\begin{document}
\begin{tikzpicture}
\pic[draw=blue, minimum width=2cm] (column 1) {
multipart block={
head content={\textbf{Start}},
parts count=6,
parts label/.list={300 KB, 600 KB, 350 KB, 200 KB, 750 KB, 125 KB},
parts value/.list={30, 60, 35, 20, 75, 12.5},
}
};
\pic[draw=blue, minimum width=2cm] (column 2) at ([xshift=2.5cm]column 1-head) {
multipart block={
head content={\textbf{Step 1}},
parts count=7,
parts label/.list={300 KB, 600 KB, 350 KB, 200 KB, 750 KB, 115 KB, 10 KB},
parts value/.list={30, 60, 35, 20, 75, 11.5, 1},
parts fill/.list={,,,,,green!15,}
}
};
\pic[draw=blue, minimum width=2cm] (column 3) at ([xshift=2.5cm]column 2-head) {
multipart block={
head content={\textbf{Step 2}},
parts count=8,
parts label/.list={300 KB, 500 KB, 100 KB, 350 KB, 200 KB, 750 KB, 115 KB, 10 KB},
parts value/.list={30, 50, 10, 35, 20, 75, 11.5, 1},
parts fill/.list={,green!15,,,,,green!15,},
part label 8/.append style={
xshift=1.25cm,
minimum width=0pt,
anchor=west,
append after command={
\pgfextra{
\draw (-part label 8.west) -- (-part 8.east);
}
},
}
}
};
\end{tikzpicture}
\end{document}