Trazar tablas mediante programación con conexiones de flecha

Trazar tablas mediante programación con conexiones de flecha

Necesito producir un montón de figuras como la que se muestra a continuación.

Estoy seguro de que se puede lograr en LaTeX. De lo que no estoy seguro es si es posible crear una función que, dadas las entradas de las tablas y las conexiones, produzca las figuras mediante programación.

He probado el siguiente código:

\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}

Me imagino que la función deseada recibe esta entrada:

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

El número de tablas puede variar, así como el número de entradas de la tabla. En el ejemplo anterior, la fila 1 de la tabla XXXXXse conecta con la fila 2 de la tabla YYYYY, con la orientación de la flecha dada por ->.

¡Gracias de antemano!

ingrese la descripción de la imagen aquí

Respuesta1

Aquí hay un primer boceto que {NiceTabular}utiliza 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}

Necesita varias compilaciones (debido al uso de nodos TikZ con la clave remember picture).

Salida del código anterior

información relacionada