【发布时间】:2010-08-07 23:16:11
【问题描述】:
我刚刚完成了我在 Tikz 中的第一个图表。它看起来像我想要的那样,但我对我如何“编码”它不满意:
\begin{tikzpicture}
[node distance=14mm,
item/.style={rounded corners,rectangle,
thick,
minimum width=20mm, minimum height=10mm}]
\node[item,draw=blue!50,fill=blue!20] (stack) {1394 Stack};
\node[item,left=of stack,draw=green!50,fill=green!20,yshift=-9mm] (app1) {Application};
\node[item,left=of stack,draw=green!50,fill=green!20,yshift=9mm] (app2) {Application};
\node[item,right=of stack,draw=orange!50,fill=orange!20] (ohci) {OHCI};
\node[item,right=of ohci,yshift=-15mm,draw=yellow!70,fill=yellow!35] (dev1) {Device};
\node[item,right=of ohci,yshift=0mm,draw=yellow!70,fill=yellow!35] (dev2) {Device};
\node[item,right=of ohci,yshift=15mm,draw=yellow!70,fill=yellow!35] (dev3) {Device};
\draw[thick] (app1) -- (stack)
(app2) -- (stack)
(stack) -- (ohci)
(ohci) -- (dev1)
(ohci) -- (dev2)
(ohci) -- (dev3);
\node[xshift=7mm,yshift=1mm] (topUser) at (app1.east |- dev3.north) {};
\node[xshift=7mm,yshift=-1mm,label=above left:User space] (botUser) at (app1.east |- dev1.south) {};
\draw[dashed] (topUser) -- (botUser);
\node[xshift=7mm,yshift=1mm] (topKern) at (stack.east |- dev3.north) {};
\node[xshift=7mm,yshift=-1mm,label=above left:Kernel space,
label=above right:Hardware\phantom{p}] (botKern) at (stack.east |- dev1.south) {};
\draw[dashed] (topKern) -- (botKern);
\end{tikzpicture}
让我不舒服的事情是:
我如何使用yshift 手动移动“应用程序”和“设备”节点以将它们彼此分开;我确信必须有一种更优雅的方式来生成简单的树状结构
从图片顶部到底部的线条(topKern -- botKern 和topUser -- botUser);这些是使用xshift=7mm 在 x 轴上手动对齐的,以便在两个节点之间。
我使用\phantom{p} 来确保标签“硬件”与其他两个标签具有相同的基线。
【问题讨论】:
-
仅供参考,这种问题可以在TeX/LaTeX Stack Exchange site 上找到一个很好的归宿,现在处于公开测试阶段。如果您愿意,可以关闭此问题并将其重新发布到其他网站。