質問

私はちょうどは、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 -- botKerntopUser -- botUser)下に画像の上から行きます。これらは、手動xshift=7mmを使用して2つのノードの間になるようにx軸に整列している。

ラベル「ハードウェア」を確保するため\phantom{p}の私の使用は、他の2つのラベルと同じベースラインを持っています。

役に立ちましたか?

解決

pgfmanual.pdfに相談し、ツリー構造を構築するには、の木は、の成長作ります。

ラインのために、私は2つのノードの途中で表すノードを作成し、あなたが行ったように垂直な座標系を使用します。また、あなたは「国境」を識別するためにcurrent bounding boxを使用することができます。

、正しくベースラインを揃えるtext heighttext depthを指定します。あなたのケースでは、スタイルevery labelでインスタンスのため。あなたが見るようにしかし、私は...

以下のノードとしてラベルをしました
\begin{tikzpicture}[level distance=35mm,node distance=15mm,text height=1.5ex,text depth=0.25ex]

\begin{scope}[every node/.style={rounded corners,rectangle,thick,minimum width=20mm, minimum height=10mm}]
\begin{scope}[level 1/.style={sibling distance=19mm,nodes={fill=green!20,draw=green!50}}]
\node[draw=blue!50,fill=blue!20] (stack) {1394 Stack} [grow=left]
  child {node (app2) {Application}}
  child {node (app1) {Application}};
\end{scope}

\begin{scope}[level 1/.style={sibling distance=15mm,nodes={fill=yellow!70,draw=yellow!35}}]
\node[right= of stack,draw=orange!50,fill=orange!20] (ohci) {OHCI} [grow=right]
  child {node {Device}}
  child {node {Device}}
  child {node {Device}};
\end{scope}
\end{scope}

\node[below=0mm of app1] (userspace) {User space};
\node at (userspace -| stack) (kernel) {Kernel};
\node at (userspace -| ohci) (hardware) {Hardware}; 

\path (app1) -- (stack) node[coordinate,midway] (between1) {};
\draw (ohci) -- (stack) node[coordinate,midway] (between2) {};

\draw[dashed] (current bounding box.north -| between1) -- (current bounding box.south -| between1);
\draw[dashed] (current bounding box.north -| between2) -- (current bounding box.south -| between2);

\end{tikzpicture}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top