화살표 연결을 사용하여 프로그래밍 방식으로 테이블 그리기

화살표 연결을 사용하여 프로그래밍 방식으로 테이블 그리기

아래와 같은 수치를 많이 생성해야 합니다.

LaTeX에서는 이것이 가능하다고 확신합니다. 내가 확신할 수 없는 것은 테이블의 항목과 연결이 주어지면 프로그래밍 방식으로 그림을 생성하는 함수를 생성하는 것이 가능한지 여부입니다.

다음 코드를 시도했습니다.

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

나는 원하는 기능이 이 입력을 받는 것이라고 상상합니다.

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

테이블 수와 테이블 항목 수는 다양할 수 있습니다. 위의 예에서 table 의 행 1은 XXXXXtable 의 행 2에 연결되며 YYYYY화살표 방향은 로 지정됩니다 ->.

미리 감사드립니다!

여기에 이미지 설명을 입력하세요

답변1

{NiceTabular}다음은 를 사용한 첫 번째 스케치입니다 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}

여러 가지 컴파일이 필요합니다(키와 함께 TikZ 노드를 사용하기 때문에 remember picture).

위 코드의 출력

관련 정보