如何在 TikZ 中制作 diamond-e 框架?

如何在 TikZ 中制作 diamond-e 框架?

我正在尝试构建在 TikZ 中,但我做起来很麻烦。我希望有人可以改进下面的代码,让它看起来与图片相似。

\begin{tikzpicture}
\draw  (-0.5,1.5) rectangle (2,0);
\draw  (-9.5,1.5) rectangle (-7,0);

\draw  (-4.5,5) rectangle (-2,3.5);
\draw  (-4.5,-2) rectangle (-2,-3.5);
\draw  (4,1.5) rectangle (6.5,0);
\draw [-latex](-4.5,4.5) -- (-8,1.5);
\draw [-latex] (-8,0) -- (-4.5,-3);
\draw  [-latex](-2,-3) -- (1,0);
\draw [-latex] (-2,4.5) -- (1,1.5);
\draw  [-latex](2,0.5) -- (4,0.5);
\end{tikzpicture}

我尝试在矩形内添加文本,但不知道该怎么做。如果有人有 TikZ 以外的解决方案,那么这种方法也可以。

答案1

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\tikzset{
block/.style = {draw,rectangle,text width = 4em,align=left, rounded corners=0ex,     minimum height=2.0em}
}
\begin{document}
  \begin{tikzpicture}
\node[block] at (0,0) (a) {A. Some text};
\node[block,above right = .15cm and 1cm of a,] (b) {B. Some text};
\node[block, below right = .15cm and 1cm of a,] (c) {c. Some text};
\node[block, below right = .15cm and 1cm of b,]  (d) {D. Some text};
\node[block,  right = 1cm of d]  (e) {E. Some text};
%% lines
\draw[-latex] (a.10) -- (b.185);
\draw[-latex] (a.-10) -- (c.175);
\draw[-latex] (b.-10) -- (d.175);
\draw[-latex] (c.10) -- (d.185);
\draw[-latex] (d) -- (e);
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

新的 CVSgraphdrawing库可以很容易地完成这样的工作,但必须使用以下命令进行编译luatex

\documentclass[border=0.125cm]{standalone}

\usepackage{tikz}
\usetikzlibrary{graphdrawing}
\usetikzlibrary{graphs}
\usegdlibrary{layered}

\begin{document}

\begin{tikzpicture}[every node/.style={draw, text width=4em}, >=stealth]

\graph [layered layout,grow=right, level distance=1in, sibling distance=0.5in, 
  tail anchor=east, head anchor=west]
    {
        "A. Some text" -> {" B. Some text", "C. Some text"} 
        -> "D. Some text" -> "E. Some text"
    };

\end{tikzpicture}

\end{document}

在此处输入图片描述

答案3

column sep使用矩阵节点,可以实现这一点。可以通过和键更改块分离row sep。文本和块边界线的颜色选择也是可行的(这里是黑色)

在此处输入图片描述

代码:

\documentclass[]{article}
\usepackage[margin=1cm]{geometry}
\usepackage{tikz}
\usetikzlibrary{matrix,shapes,arrows,positioning}

\begin{document}
\begin{tikzpicture}[boxes/.style={draw, rectangle,%
                thick,minimum height=1cm, rounded corners,
                minimum width=1cm, black, text=black,
                text width=25mm, align=center},scale=2]
  \matrix (mat) [matrix of nodes, nodes=boxes, column sep=1cm, row sep=1cm] 
  {
              &   B. Some Text    &                &                  \\ 
 A. Some Text &                   &  D.Some Text   & E. Some Text     \\
              &   C. Some Text    &                &                  \\ 
  };  
\draw [very thick, black, ->] (mat-2-1.east)--(mat-1-2.west);  
\draw [very thick, black, ->] (mat-2-1.east)--(mat-3-2.west);
\draw [very thick, black, ->] (mat-3-2.east)--(mat-2-3.west);
\draw [very thick, black, ->] (mat-1-2.east)--(mat-2-3.west);
\draw [very thick, black, ->] (mat-2-3.east)--(mat-2-4.west);
\end{tikzpicture}
\end{document}

相关内容