
次のようなグラフィックを作成したいと思います。
以下が私のコードです:
\documentclass[11pt]{article}
\usepackage{tikz}
\usetikzlibrary{arrows}
\newcommand{\psign}{+}
\newcommand{\ppsign}{++}
\begin{document}
\noindent
\begin{tikzpicture}
\tikzstyle{my node} = [draw,rectangle,minimum width=2.2cm,minimum height=0.8cm, node distance=2cm]
%\draw[black!20] (-0.5cm,-0.5cm) grid (14cm,7cm);
\node [my node] (A) {GDI DDI};
\node [my node] (B) [above of=A] {GDI};
\begin{scope}[xshift=3cm]
\node (C) {Graphics Driver};
\node [my node] (D) [above of=C] {GDI\psign Flat API};
\node [my node] (E) [above of=D] {GDI\psign\ C\ppsign API};
\end{scope}
\begin{scope}[xshift=6cm]
\node [my node] (F) {DX DDI};
\node [my node] (G) [above of=F] {DXGI};
\node [my node] (H) [above of=G] {Direct3D};
\node [my node] (I) [above of=H,minimum width=4cm,right=0pt] {Direct2D};
\node [my node] (J) [right of=I,right=0pt,node distance=3cm] {DirectWrite};
\node [my node] (K) [right of=F, node distance=4cm] {Software Rasterizer};
\end{scope}
\begin{scope}[->,>=triangle 45,semithick]
\path (B) edge (A);
\path (E) edge (D);
\path (H) edge (G);
\path (G) edge (F);
\path (J) edge (I);
\end{scope}
\draw [dashed] (-1.25,1cm) -- (14,1cm);
\end{tikzpicture}
\end{document}
答え1
\documentclass[11pt]{article}
\usepackage{tikz,xcolor}
\usetikzlibrary{arrows,calc,fit,backgrounds}
\definecolor{fcolor}{HTML}{F1F1F1}
\newcommand{\psign}{+}
\newcommand{\ppsign}{++}
\begin{document}
\noindent
\begin{tikzpicture}
\tikzstyle{my node} = [draw,rectangle,minimum width=2.2cm,minimum height=0.8cm, node distance=2cm]
%\draw[black!20] (-0.5cm,-0.5cm) grid (14cm,7cm);
\node [my node] (A) {GDI DDI};
\node [my node] (B) [above of=A] {GDI};
\begin{scope}[xshift=3cm]
\node (C) {Graphics Driver};
\node [my node] (D) [above of=C] {GDI\psign Flat API};
\node [my node] (E) [above of=D] {GDI\psign\ C\ppsign API};
\end{scope}
\begin{scope}[xshift=6cm]
\node [my node] (F) {DX DDI};
\node [my node] (G) [fill=white,above of=F] {DXGI};
\node [my node] (H) [fill=white,above of=G] {Direct3D};
\node [my node] (I) [fill=white,above of=H,minimum width=4.5cm,right=0pt] {Direct2D};
\node [my node] (J) [fill=white,right of=I,right=0pt,node distance=3.5cm] {DirectWrite};
\node [my node] (K) [fill=white,right of=G, node distance=4cm] {Software Rasterizer};
\end{scope}
\begin{scope}[->,>=triangle 45,semithick]
\path (B) edge (A);
\path (E) edge (D);
\path (H) edge (G);
\path (G) edge (F);
\path (J) edge (I);
\path (I.south-|K) edge (K);
\path (I.south-|{$(H.north)!.5!(H.north east)$}) edge ($(H.north)!.5!(H.north east)$);
\end{scope}
\begin{scope}[on background layer]
\node[rectangle,fill=fcolor,fit=(G.south west) (J.north east)] {};
\end{scope}
\draw [dashed] (-1.25,1cm) -- (14,1cm);
\end{tikzpicture}
\end{document}
まずSoftware Rasterizer
ノードの配置を修正しましたright of=G
:
\node [my node] (K) [right of=G, node distance=4cm] {Software Rasterizer};
次に、残りの 2 つの矢印接続について、edge
次の 2 行を s に追加しました。
\path (I.south-|K) edge (K);
\path (I.south-|{$(H.north)!.5!(H.north east)$}) edge ($(H.north)!.5!(H.north east)$);
ここで、 はノードの中心の真上にあるノード(I.south-|K)
上の点です。 についても同じ考え方ですが、少し複雑です。今度は、 はノードの北と北東の中間点の真上にあるノード上の点です。Direct2D
Software Rasterizer
(I.south-|{$(H.north)!.5!(H.north east)$})
Direct2D
Direct3D
ハイライト表示された 5 つのブロックはライブラリによって取得できますfit
が、今回はスコープ ( on background layer
) 内で取得して、ノードを 2 回描画しないようにします。 や などの最も外側の 2 つのノードを選択しG
、それぞれJ
最も外側のコーナー、(G.south west)
およびを指定します(J.north east)
。
答え2
これは、あなたが探している機能のようなものです。fit
上に描画することに注意してください。下にフルカラーが必要な場合は、それらのノードを 2 回描画する必要がある場合があります (1 回はfit
計算用のノードを取得するため、もう 1 回はフィット領域に再度描画するためです。描画コードをマクロに保存し、そのマクロを 2 回実行するだけです)。
\documentclass[11pt]{article}
\usepackage{tikz}
\usetikzlibrary{arrows,calc}
\usetikzlibrary{positioning,fit}
\newcommand{\psign}{+}
\newcommand{\ppsign}{++}
\begin{document}
\noindent
\begin{tikzpicture}
\tikzstyle{my node} = [draw,rectangle,minimum width=2.2cm,minimum height=0.8cm, node distance=2cm]
%\draw[black!20] (-0.5cm,-0.5cm) grid (14cm,7cm);
\node [my node] (A) {GDI DDI};
\node [my node] (B) [above of=A] {GDI};
\begin{scope}[xshift=3cm]
\node (C) {Graphics Driver};
\node [my node] (D) [above of=C] {GDI\psign Flat API};
\node [my node] (E) [above of=D] {GDI\psign\ C\ppsign API};
\end{scope}
\begin{scope}[xshift=6cm]
\node [my node] (F) {DX DDI};
\node [my node] (G) [above of=F] {DXGI};
\node [my node] (H) [above of=G] {Direct3D};
\node [my node] (I) [above of=H,minimum width=4cm,right=0pt] {Direct2D};
\node [my node] (J) [right of=I,right=0pt,node distance=3cm] {DirectWrite};
\node [my node] (K) [right of=G, node distance=4cm] {Software Rasterizer};
\end{scope}
\begin{scope}[ transform canvas={xshift=1cm},
->,>=triangle 45,semithick]
\draw (I) -- (I |- K.north);
\end{scope}
\begin{scope}[ transform canvas={xshift=-4em},
->,>=triangle 45,semithick]
\draw (I) -- (I |- H.north);
\end{scope}
\begin{scope}[->,>=triangle 45,semithick]
\path (B) edge (A);
\path (E) edge (D);
\path (H) edge (G);
\path (G) edge (F);
\path (J) edge (I);
\end{scope}
\draw [dashed] (-1.25,1cm) -- (14,1cm);
\node [fill=gray,opacity=0.2,dotted,fit = (H) (I) (J) (K) ] {};
\end{tikzpicture}
\end{document}
灰色の領域の上に凡例を追加する方法がわかると思います。
答え3
@daleif と @ AboAmmar のソリューションを若干変更して簡略化しました (私にはほとんど同じに見えます :-)):
\documentclass[11pt, border=1mm,
tikz,
preview]{standalone}
\usetikzlibrary{arrows,calc,fit,backgrounds}
\newcommand{\psign}{+}
\newcommand{\ppsign}{++}
\begin{document}
\begin{tikzpicture}[
node distance = 2cm,
every node/.style = {draw, rectangle,
fill=white, % if you liked, otherwise should be omitted
minimum width=2.2cm, minimum height=0.8cm}
]
\node (A) {GDI DDI};
\node (B) [above of=A] {GDI};
\begin{scope}[xshift=3cm]
\node (C) [draw=none] {Graphics Driver};
\node (D) [above of=C] {GDI\psign Flat API};
\node (E) [above of=D] {GDI\psign\ C\ppsign API};
\end{scope}
\begin{scope}[xshift=6cm]
\node (F) {DX DDI};
\node (G) [above of=F] {DXGI};
\node (H) [above of=G] {Direct3D};
\node (I) [above of=H,minimum width=4.5cm,right=0pt] {Direct2D};
\node (J) [right of=I,right=0pt,node distance=3.5cm] {DirectWrite};
\node (K) [right of=G, node distance=4cm] {Software Rasterizer};
\end{scope}
\coordinate (L) at ([xshift=7mm] H.north);
\path[-triangle 45,semithick]
(B) edge (A) (E) edge (D) (H) edge (G)
(G) edge (F) (J) edge (I) (I.south-|K) edge (K)
(I.south -| L) edge (L)
(I.south-|{$(H.north)!.5!(H.north east)$}) -- ($(H.north)!.5!(H.north east)$);
\scoped[on background layer]
\node (M) [rectangle,fill=gray!30,fit=(G.south west) (J.north east)] {};
\coordinate (N) at ($(A.west)!0.5!(B.west)$);
\draw [dashed] (N) -- (N -| M.east);
\end{tikzpicture}
\end{document}
このコードは次のようになります: