创建此图

创建此图

我寻求帮助来编制这样的图表:

在此处输入图片描述

热切的尝试,

 \begin{tikzpicture}[>=latex]
 \tikzstyle{rect}=[draw=black, 
                   square, 
                   minimum width=100pt, 
                   minimum height = 50pt, 
                   align=center]
  \node[rect] (a) {1};
  \node[rect,below right=of a] (e) {5};
  \node[rect,right=of a] (b) {2};
    \node[rect,right=of b] (c) {3};
    \node[rect,right=of c] (d) {4};
\draw[->] (a.east)--(b.west)node[midway,yshift=12mm]
\draw[->] (a.south)--(e.west)node[midway,sloped, below,xshift=-2mm]
\draw[->] (b.south)--(e.north)node[midway, xshift=6mm];
\draw[->] (b.east)--(c.west)node[midway, yshift=12mm];
\draw[->] (c.south)--(e.east)node[midway,sloped, below,xshift=-2mm];
\draw[->] (d.south)--(e.east)node[midway,sloped, below,xshift=-2mm];
    \end{tikzpicture}
    \end{figure}

@Zarko 非常感谢您的帮助,太棒了!

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta,
            calc, chains, 
            positioning}

\begin{document}
    \begin{tikzpicture}[
node distance = 7mm and 9mm,
  start chain = A going right,
   box/.style = {draw, minimum size=7mm,
                 align=center, on chain},
every edge/.style = {draw, -Straight Barb, semithick, shorten >=1mm, shorten <=1mm}
                        ]
\foreach \i in {this is really long, short, s, this is medium}
    \node[box] {\i}; % used at first image    node names: A-\i
%   \node[box] {\i\\}; % used at second image
\node[box,below=of $(A-2.south)!0.5!(A-3.south)$]   {it stretches quite a bit};
%\node[box,below=of $(A-2.south)!0.5!(A-3.south)$]   {5\\};
%
\draw[transform canvas={yshift=1mm}]
    (A-1) edge (A-2) ;
    \draw[transform canvas={yshift=0mm}]
    (A-2) edge (A-3)    (A-3) edge (A-4);
\draw[transform canvas={yshift=-1mm}]
            (A-2) edge (A-1);
\draw   (A-1.south) edge (A-5)  (A-2.south) edge (A-5)
        (A-3.south) edge (A-5)  (A-4.south) edge (A-5);
    \end{tikzpicture}
\end{document}

有没有办法让格式保持不变,尽管单词的长度不同?

答案1

像这样:

在此处输入图片描述

或这个:

在此处输入图片描述

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta,
                calc, chains, 
                positioning}

\begin{document}
    \begin{tikzpicture}[
node distance = 7mm and 9mm,
  start chain = A going right,
   box/.style = {draw, minimum size=7mm,
                 align=center, on chain},
every edge/.style = {draw, -Straight Barb, semithick, shorten >=1mm, shorten <=1mm}
                        ]
\foreach \i in {1,...,4}
    \node[box] {\i}; % used at first image    node names: A-\i
%   \node[box] {\i\\}; % used at second image
\node[box,below=of $(A-2.south)!0.5!(A-3.south)$]   {5};
%\node[box,below=of $(A-2.south)!0.5!(A-3.south)$]   {5\\};
%
\draw[transform canvas={yshift=1mm}]
    (A-1) edge (A-2)    (A-2) edge (A-3)    (A-3) edge (A-4);
\draw[transform canvas={yshift=-1mm}]
    (A-4) edge (A-3)    (A-3) edge (A-2)    (A-2) edge (A-1);
\draw   (A-1.south) edge (A-5)  (A-2.south) edge (A-5)
        (A-3.south) edge (A-5)  (A-4.south) edge (A-5);
    \end{tikzpicture}
\end{document}

对于第二幅图,请考虑注释的代码行。请参阅代码中的注释。

笔记:

  • tikzszyle已弃用,而是使用tikzset或定义图片元素样式作为选项,\tikzpicture如上面的 MWE 中所做的那样
  • 对于节点放置使用库chainspositioning, where the first four nodes are drawn in the\foraech` 循环
  • 前四个节点之间的箭头随着画布变换而移动。

答案2

您可以使用 Graphwiz 和 dot2tex Python 脚本转换器来制作此类图形。dot2texi 包允许您使用 -shell-escape 或 -enable-write18 编译选项从 tex 源代码中调用 dot2tex。以下是可以生成此图形的源代码。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usepackage{dot2texi}

\begin{document}
  \begin{dot2tex}
     digraph
     { nodesep=.5;
       node [shape=square];
       {rank=same "1" "2" "3" "4"}
       "1"->"2"->"3"->"4"->"3"->"2"->"1" ;
       {"1";"2";"3";"4"}-> "5";
      }
  \end{dot2tex}
\end{document}

如果是单个单词,则不强制引用节点。你可以命名节点或者“foo”显示, 但“foo 栏“必须加引号。

您需要来自 Python 存储库的 Python 和 dot2tex Python 脚本。

查看 Graphviz 和 dot2texi 文档。

pdflatex-shell-escape dot2tex-mwe.tex

相关内容