Tikz を使って簡単なモデルを描く方法

Tikz を使って簡単なモデルを描く方法
\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                chains,
                decorations.pathreplacing,
                calligraphy,
                positioning,
                shapes}

ここに画像の説明を入力してください

答え1

バンドルで提供されるライブラリのみを使用しますtikz。 2 つのケースを示します: (i) イメージを再作成するケース、(ii) 可能な再設計 (後者の方が好ましい)。

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                calc, chains,
                decorations.pathreplacing,
                calligraphy,
                positioning,
                quotes,
                shapes}

\begin{document}
    \begin{figure}[ht]
    \centering
\begin{tikzpicture}[
node distance = 8mm and 24mm,
            > = Stealth,
every path/.append style = {draw=cyan},
every edge quotes/.append style = {font=\footnotesize, sloped},
     E/.style = {ellipse, draw, semithick, fill=cyan!30},
     N/.style = {draw, semithick, minimum width = 8em, inner sep=1ex}
                    ]
\node (a) [N]  {text};
\node (b) [N, below=of a]  {text};
\node (e) [E, right=of {$(a.east)!0.5!(b.east)$}]  {TEXT};
%
\coordinate[below=of b.south] (aux);
\draw[<->]  (a.west) -- ++ (-2em,0) |- (b.west) coordinate[pos=0.25] (ab);
\draw[->]   (ab) -- ++ (-1em,0)
                 |- (aux) node[below, font=\footnotesize] {Model 3}
                 -| (e.west);
\draw[->, shorten >=1pt]   (a.east) to ["Model 1"]     (e.west);
\draw[->, shorten >=1pt]   (b.east) to ["Model 2" ']   (e.west);
\end{tikzpicture}
    \end{figure}

    \begin{figure}[ht]
    \centering
\begin{tikzpicture}[
node distance = 8mm and 16mm,
            > = Stealth,
every path/.append style = {draw=cyan},
every edge quotes/.append style = {font=\footnotesize, sloped},
     E/.style = {ellipse, draw, semithick, fill=cyan!30},
     N/.style = {draw, semithick, minimum width = 8em, inner sep=1ex}
                    ]
\node (a) [N]  {text};
\node (b) [N, below=of a]  {text};
\node (e) [E, right=of {$(a.east)!0.5!(b.east)$}]  {TEXT};
%
\coordinate[below=of b.south] (aux);
\draw[<->]  (a.west) -- ++ (-2em,0) |- (b.west) coordinate[pos=0.25] (ab);
\draw[->]   (ab) -- ++ (-1em,0) 
                 |- (aux) node[below, font=\footnotesize] {Model 3} 
                 -| (e);
\draw[->, shorten >=1pt]   (a.east) to ["Model 1"]     (e);
\draw[->, shorten >=1pt]   (b.east) to ["Model 2" ']   (e);
\end{tikzpicture}
    \end{figure}
\end{document}

ここに画像の説明を入力してください

答え2

適切なツールを使用すれば:

  • ライブラリellipseからの形状shapes.geometric

  • ライブラリquotesを使用すると、エッジに沿ってノードを簡単に配置できます。

  • ライブラリext.paths.orthoはパス操作を提供するr-lr

    (<start>) r-lr (<target>)
    

    最初にortho/lr distance左に描画し、次に上/下に描画し、最後に右に描画します<target>

  • 図書館ext.positioning-plusでは

    right = of (r1)(r2)
    

    これは、r1 と r2 の垂直中心の右側にノードを配置します($(r1.north east)!.5!(r2.south east)$)

およびm座標r3は、モデル 3 の矢印の始点と中間として使用されます。

コード

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{
  arrows.meta,          % for arrow tips
  shapes.geometric,     % for ellipse shape
  ext.positioning-plus, % for of (r1)(r2)
  ext.paths.ortho,      % for r-lr and r-du
  quotes,               % for "nodes" on edges
}
\begin{document}
\begin{tikzpicture}[
  >=Latex,
  r/.style   = {rectangle, draw=blue, minimum width=2cm},
  ell/.style = {ellipse,   draw,      fill=blue!30},
  node distance=5mm and 2cm,
  % r-lr: to the left, then up/down, then right
  lr/.style   = {to path={r-lr (\tikztotarget)\tikztonodes}},
  % lrhv: lr to #1, from #1 to target
  lrhv/.style = {to path={r-lr (#1) \tikztonodes -| (\tikztotarget)}},
]
\node[r] (r1)                        {TEXT};
\node[r] (r2) [below=of r1]          {TEXT};
\coordinate[below=of r2] (r3); % auxilliary coordinate

% right = of (r1)(r2) → right = of <the vertical middle of r1 and r2>
\node[ell] (ell) [right=of (r1)(r2)] {TEXT};

\path[blue, ->, text=black, sloped]
  (r1)      edge[-,lr]           coordinate(m) (r2)
  (r1.east) edge["Model 1"]                    (ell.west)
  (r2.east) edge["Model 2" ']                  (ell.west)
  (m)       edge["Model 3" at end, ', lrhv=r3] (ell.west);
\end{tikzpicture}
\end{document}

出力

ここに画像の説明を入力してください

答え3

単純な図形は単純なコードで描画する必要があります。

(サーバー側で何らかのエラーが発生し、図をアップロードできません)

\documentclass[tikz,border=5mm]{standalone}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}[teal,thick,nodes={text=black}]
\path 
(5,0) node[ellipse,draw,fill=yellow,inner ysep=3mm] (E) {Ellipse}
(0,1) node[draw,minimum width=3cm,minimum height=8mm] (Ra) {Rectangle}
(0,-1) node[draw,minimum width=3cm,minimum height=8mm] (Rb) {Rectangle}
(-2,0) coordinate (A)
;       
\draw[->] (Ra.east)--(E) node[above,sloped,midway]{Model 1};
\draw[->] (Rb.east)--(E) node[below,sloped,midway]{Model 2};
\draw (A)|-(Ra) (A)|-(Rb);
\draw[->] (A)--++(180:.5)--++(-90:2.5)-|(E) node[below,pos=.25]{Model 3};
\end{tikzpicture}
\end{document}

関連情報