Tabellen mit Pfeilverbindungen programmgesteuert darstellen

Tabellen mit Pfeilverbindungen programmgesteuert darstellen

Ich muss eine Reihe von Abbildungen wie die folgende erstellen.

Ich bin sicher, dass dies in LaTeX möglich ist. Ich bin mir jedoch nicht sicher, ob es möglich ist, eine Funktion zu erstellen, die die Zahlen programmgesteuert aus den Einträgen der Tabellen und den Verbindungen erstellt.

Ich habe den folgenden Code ausprobiert:

\documentclass[tikz,border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}[
    box/.style={rectangle, draw=black, minimum height=1cm, minimum width=2cm, align=left},
    arrow/.style={-latex}
]
  % Boxes
  \node[box] (box1) {XXXXX\\xxxxx1\\xxxxx2\\xxxxx3\\xxxxx4};
  \node[box, right=2cm of box1] (box2) {YYYYY\\yyyyy1\\yyyyy2\\yyyyy3\\yyyyy4};
  \node[box, right=2cm of box2] (box3) {ZZZZZ\\zzzzz1\\zzzzz2\\zzzzz3\\zzzzz4\\zzzzz5};
  
  % Arrows
  \draw[arrow] (box2) -- (box1);
  \draw[arrow] (box3) -- (box2);

\end{tikzpicture}
\end{document}

Ich stelle mir vor, dass die gewünschte Funktion diese Eingabe erhält:

{{
table XXXXX,
xxx1
xxx2,
xxx3,
},
{
table YYYYY,
yyy1
yyy2,
yyy3,
},
{
connections:
XXXXX:1 -> YYYYY:2
}}

Die Anzahl der Tabellen kann variieren, ebenso wie die Anzahl der Tabelleneinträge. Im obigen Beispiel ist Zeile 1 der Tabelle XXXXXmit Zeile 2 der Tabelle verbunden YYYYY, wobei die Pfeilausrichtung durch gegeben ist ->.

Dank im Voraus!

Bildbeschreibung hier eingeben

Antwort1

Hier ist eine erste Skizze, die {NiceTabular}verwendet nicematrix.

\documentclass{article}
\usepackage{nicematrix,tikz}
\usetikzlibrary{arrows.meta}

\ExplSyntaxOn

% The following counter will count the occurrences of the command \Draw
\int_new:N \g__PaulS_int

\cs_new_protected:Npn \__PaulS_arrow:n #1 { \__PaulS_arrow_aux:w #1 \q_stop }

\cs_new_protected:Npn \__PaulS_arrow_aux:w #1 - #2 -> #3 - #4 \q_stop
  { 
    \int_compare:nNnTF { #1 } < { #3 } 
      { \draw [-LaTeX] (#1-#2.5-|#1-2) -- (#3-#4.5-|#3-1) ; }
      { \draw [-LaTeX] (#1-#2.5-|#1-1) -- (#3-#4.5-|#3-2) ; }
  }

\NewDocumentCommand { \Draw } { m m } 
  {
    \group_begin:
    \int_gincr:N \g__PaulS_int
    % the following counter will count the tables
    \int_zero_new:N \l__PaulS_int
    \clist_map_inline:nn { #1 }
      {
        \int_incr:N \l__PaulS_int
        \begin { NiceTabular } 
          [ 
            t , 
            name = PaulS - \int_use:N \g__PaulS_int - \int_use:N \l__PaulS_int
          ] 
          { c }
        \bfseries 
        \clist_use:nn { ##1 } { \\ }
        % we draw the rules in the current table 
        \CodeAfter
          \begin { tikzpicture }
            \draw (1-|1) rectangle (last-|last) ; 
            \draw (2-|1) -- (2-|last) ; 
          \end { tikzpicture }
        \end { NiceTabular }
        \hspace { 1cm }
      }
    % now, we draw the arrows
      \begin{tikzpicture} 
        [ 
          remember~picture, 
          overlay , 
          name~prefix = PaulS - \int_use:N \g__PaulS_int -
        ]
      \clist_map_function:nN { #2 } \__PaulS_arrow:n 
    \end{tikzpicture}
    \group_end:
  }

% the following lines are not necesssary with recent versions of LaTeX
\cs_set:Nn \int_if_zero:nT { \int_compare:nNnT { #1 } = 0 { #2 } }
\cs_set:Nn \int_if_zero:nTF { \int_compare:nNnT { #1 } = 0 { #2 } { #3 } }

\ExplSyntaxOff

\begin{document}

\NiceMatrixOptions{cell-space-limits=3pt}

\Draw 
  {
    { table XXXXX, xxx1 xxx2, xxx3 } ,
    { table YYYYY, yyy1 yyy2, yyy3 } , 
    { table ZZZ, zz1 zzz2, zzz4 , zzz5 } 
  }
  { 1-1->2-2 , 2-3->1-3 , 2-1->3-3 }

\end{document}

Sie benötigen mehrere Kompilierungen (aufgrund der Verwendung von TikZ-Knoten mit dem Schlüssel remember picture).

Ausgabe des obigen Codes

verwandte Informationen