我正在尝试重现一个简化的英特尔处理器图,没有任何好运气。
我不明白如何使 L3 部分变得通用,并且我的代码产生了以下内容:
我想要实现的是 L3 的大小等于图表的宽度(不包括 RAM):如果我再添加两个核心,它应该会相应地拉伸。
这是我的最小可编译代码,这里我遗漏了什么?
谢谢!
\documentclass{article}
\usepackage{tikz}
\usepackage{subfigure}
\usetikzlibrary{calc,trees,positioning,arrows,chains,shapes.geometric,%
decorations.pathreplacing,decorations.pathmorphing,shapes,%
matrix,shapes.symbols}
\tikzset
{
% nodes
darkstyle/.style =
{
circle,draw,fill = gray!20
},
% trajectory
serpent/.style =
{
line join = round,
line width = 2pt,
line cap = round,
opacity = .7,
red
},
>=stealth',
core/.style =
{
rectangle,
rounded corners,
draw = black, thick,
text width = 5em,
minimum height = 3em,
text centered,
on chain
},
cache/.style =
{
rectangle,
rounded corners,
draw = gray!40, thin,
text width = 5em,
minimum height = 3em,
text centered,
on chain
},
line/.style =
{
draw, thick, <-
},
element/.style =
{
tape,
top color = white,
bottom color = blue!50!black!60!,
minimum width = 8em,
draw = blue!40!black!90, very thick,
text width = 10em,
minimum height = 3.5em,
text centered,
on chain
},
every join/.style =
{
->, thick,shorten >=1pt
},
decoration =
{
brace
},
tuborg/.style =
{
decorate
},
tubnode/.style =
{
midway, right = 2pt
},
}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[node distance = .8cm, start chain = going below]
% cores
\node [core] (c1) {Core 1};
\node [core] (c2) [right = of c1] {Core 2};
% caches
\node [cache] (l11) [below = of c1] {L1 \\ 64 KB} edge [-] (c1);
\node [cache] (l12) [below = of c2] {L1 \\ 64 KB} edge [-] (c2);
\node [cache] (l21) [below = of l11] {L2 \\ 256 KB} edge [-] (l11);
\node [cache] (l22) [below = of l12] {L2 \\ 256 KB} edge [-] (l12);
% common cache
\node [core,text width = 10em,xshift=-20.5pt] (l3) {L3 \\ 8 MB} edge [-] (l21) edge [-] (l22);
% ram
\node [core] (ram) [right = of l3] {RAM} edge [-] (l3);
\end{tikzpicture}
\label{fig:cache}
\caption{Cache hierarchy diagram for the 2016 Intel Kaby Lake Microarchitechture.}
\end{figure}
\end{document}
答案1
\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows, calc, chains, positioning}
\tikzset
{
core/.style = {
rectangle,
rounded corners,
draw = black, thick,
text width = 5em,
minimum height = 3em,
align=center,
on chain
},
cache/.style = {
core,
draw = gray
}
}% end of tikzset
\begin{document}
\begin{tikzpicture}[
node distance = 8mm,
start chain = going below]
% left branch
\node [core] (c1) {Core 1};
\node [cache,join] (l11) {L1 \\ 64 KB};
\node [cache,join] (l12) {L2 \\ 256 KB};
% right branch
\node [core,right=of c1] (c2) {Core 1};
\node [cache,join] (l21) {L1 \\ 64 KB};
\node [cache,join] (l22) {L2 \\ 256 KB};
% common cache
\path let \p1 = ($(c2.east)-(c1.west)$),
\n1 = {veclen(\x1,\y1)} in
node [core,minimum width = \n1,
below=of $(l12.south)!0.5!(l22.south)$] (l3) {L3 \\ 8 MB};
\draw (l12) -- (l12 |- l3.north) (l22) -- (l22 |- l3.north);
% ram
\node [core,join] (ram) [right = of l3] {RAM};
\end{tikzpicture}
\end{document}
无关:
包subfigure
已过时,它已被替换subfig
,但你可以通过 实现对子图形的更好控制subcaption
。在上面的例子中没有使用图形环境,但将图像代码放在其中(并使用article
文档类)应该不是大问题 :-)
对于 L3 块的宽度,使用calc
带宏的库veclen
。还利用chain
库来定位垂直分支。