다음 테이블 형식 환경에서 항목을 어떻게 정렬합니까?

다음 테이블 형식 환경에서 항목을 어떻게 정렬합니까?

나는 다음과 같은 의미에서 아래 내용을 순서대로 얻으려고 노력하고 있습니다. (a) 왼쪽의 검정색 텍스트(xx, yy, zz)는 오른쪽의 관련 테이블 셀을 기준으로 수직으로 정렬되어야 합니다. (b) 상자가 있는 왼쪽 열과 오른쪽 열 사이에 공간이 많지 않습니다. (c) 이것은 까다로운 작업입니다. 보시다시피 오른쪽의 가장 낮은 상자 세트에서 D와 E를 B와 C에 정렬하려고 하는데 어떤 이유로 tikz 그림이 "잘려집니다".

다음 답변을 찾은 후 tabularray를 사용하고 있음을 언급해야 합니다.셀의 텍스트를 세로 가운데에 맞추는 방법은 무엇입니까?

MWE는 다음과 같습니다.

\documentclass{article}

\usepackage{tabularray}
\usepackage{tikz}

\begin{document}

\begin{tblr}{
colspec = {X[l,m]X[l,m]},
rowsep = 0pt,
colsep = 0pt
}

zz: & something \\

yy: & \begin{tikzpicture}[cc/.style={fill=blue!20,rounded corners=2pt,thick,inner sep=4,outer sep=0,minimum width=18mm},cyellow/.style={align=center,fill=yellow!20,rounded corners=2pt,thick,inner sep=4,outer sep=0,minimum width=18mm},cgreen/.style={fill=green!20,rounded corners=2pt,thick,inner sep=4,outer sep=0,minimum width=18mm},corange/.style={fill=orange!20,rounded corners=2pt,thick,inner sep=4,outer sep=0,minimum width=18mm}]

\path  (0,0) node[cc] (A) {A} (2.3,0) node[cc] (B) {B} (4.6,0) node[cc] (C) {C};
\draw[->] (A)--(B);
\draw[->] (B)--(C);

\end{tikzpicture} \\

xx & \begin{tikzpicture}[cc/.style={fill=blue!20,rounded corners=2pt,thick,inner sep=4,outer sep=0,minimum width=18mm},cyellow/.style={align=center,fill=yellow!20,rounded corners=2pt,thick,inner sep=4,outer sep=0,minimum width=18mm},cgreen/.style={align=center,fill=green!20,rounded corners=2pt,thick,inner sep=4,outer sep=0,minimum width=18mm},corange/.style={align=center,fill=orange!20,rounded corners=2pt,thick,inner sep=4,outer sep=0,minimum width=18mm}]


\path (2.3,0) node[cyellow] (AA) {D} (4.6,0) node[cgreen] (BB) {E};
\draw[->] (AA)--(BB);

\end{tikzpicture}

\end{tblr}

\end{document}

답변1

이건 어때? 저는 일반 tabular환경을 사용했고, tikzpictures를 수학 모드로 두고 \vcenter편집했습니다. 결과

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tabular}{rl}
    zz: & something\\
    yy: & $\vcenter{\hbox{\begin{tikzpicture}[baseline=(current bounding box.center),cc/.style={fill=blue!20,rounded corners=2pt,thick,inner sep=4,outer sep=0,minimum width=18mm},cyellow/.style={align=center,fill=yellow!20,rounded corners=2pt,thick,inner sep=4,outer sep=0,minimum width=18mm},cgreen/.style={fill=green!20,rounded corners=2pt,thick,inner sep=4,outer sep=0,minimum width=18mm},corange/.style={fill=orange!20,rounded corners=2pt,thick,inner sep=4,outer sep=0,minimum width=18mm}]
        \path  (0,0) node[cc] (A) {A} (2.3,0) node[cc] (B) {B} (4.6,0) node[cc] (C) {C};
        \draw[->] (A)--(B);
        \draw[->] (B)--(C);
    \end{tikzpicture}}}$ \\
    xx: & $\vcenter{\hbox{\begin{tikzpicture}[cc/.style={fill=blue!20,rounded corners=2pt,thick,inner sep=4,outer sep=0,minimum width=18mm},cyellow/.style={align=center,fill=yellow!20,rounded corners=2pt,thick,inner sep=4,outer sep=0,minimum width=18mm},cgreen/.style={align=center,fill=green!20,rounded corners=2pt,thick,inner sep=4,outer sep=0,minimum width=18mm},corange/.style={align=center,fill=orange!20,rounded corners=2pt,thick,inner sep=4,outer sep=0,minimum width=18mm}]
        \path (2.3,0) node[cyellow] (AA) {D} (4.6,0) node[cgreen] (BB) {E};
        \draw[->] (AA)--(BB);
    \end{tikzpicture}}}$
\end{tabular}
\end{document}

답변2

(a) tikz 그림의 기준선을 설정합니다.
(b) Q대신 열 유형을 사용하십시오 X.
(c) A 아래에 보이지 않는 노드를 그려 B를 D와, C를 E와 정렬합니다.

시연하기 위해 상자 높이를 높였습니다.

\documentclass{article}

\usepackage{tabularray}
\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}
    
    \begin{tblr}{
            colspec = {Q[l,m] Q[l,m]},
            rowsep = 0pt,
            colsep = 0pt
        }
        
        zz: & something \\
        
        yy: & \begin{tikzpicture}[
            cc/.style={fill=blue!20,rounded corners=2pt,thick,inner sep=4,outer sep=0,minimum width=18mm,minimum height=10mm},
            cyellow/.style={align=center,fill=yellow!20,rounded corners=2pt,thick,inner sep=4,outer sep=0,minimum width=18mm},
            cgreen/.style={fill=green!20,rounded corners=2pt,thick,inner sep=4,outer sep=0,minimum width=18mm},
            corange/.style={fill=orange!20,rounded corners=2pt,thick,inner sep=4,outer sep=0,minimum width=18mm},
            baseline={(A.base)}
        ]
            
            \path  (0,0) node[cc] (A) {A} (2.3,0) node[cc] (B) {B} (4.6,0) node[cc] (C) {C};
            \draw[->] (A)--(B);
            \draw[->] (B)--(C);
            %\path node (yy) [left=of A, inner sep=0pt, rectangle, draw] {yy};
            
        \end{tikzpicture} \\
        
        xx & \begin{tikzpicture}[
            cc/.style={fill=blue!20,rounded corners=2pt,thick,inner sep=4,outer sep=0,minimum width=18mm},
            cyellow/.style={align=center,fill=yellow!20,rounded corners=2pt,thick,inner sep=4,outer sep=0,minimum width=18mm,minimum height=10mm},
            cgreen/.style={align=center,fill=green!20,rounded corners=2pt,thick,inner sep=4,outer sep=0,minimum width=18mm},
            corange/.style={align=center,fill=orange!20,rounded corners=2pt,thick,inner sep=4,outer sep=0,minimum width=18mm},
            invisible/.style={inner sep=4,outer sep=0,minimum width=18mm},
            baseline={(AA.base)}
        ]
            
            
            \path (0,0) node[invisible] {} (2.3,0) node[cyellow] (AA) {D} (4.6,0) node[cgreen] (BB) {E};
            \draw[->] (AA)--(BB);
            
        \end{tikzpicture}
        
    \end{tblr}
    
\end{document}

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

답변3

  • 중고 arrows.meta˛체인 and포지셔닝` Ti케이Z 라이브러리
  • 일반적인 tikz 스타일 정의
  • 짧은 코드 ...
\documentclass{article}

\usepackage{tabularray}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                chains, 
                positioning}

\begin{document}

\tikzset{        
node distance = 0mm and 5mm,
  start chain = going right,
     N/.style = {fill=#1!20, rounded corners=2pt, anchor=base,
                 inner ysep=4mm, inner xsep=0mm, minimum width=18mm, 
                 on chain},
     N/.default = blue,
every edge/.append style = {-Straight Barb,}
        }
        
       
\begin{tblr}{colspec = {Q[l,m] Q[r,m, wd=64mm]},
              colsep = 1mm, rowsep  = 0pt}

zz: &   \SetCell{l} something \\
yy: &   \tikz[baseline=1pt]
        {\node[N] (a)   {A}; 
         \node[N] (b)   {B}; 
         \node[N] (c)   {C};
         \draw  (a) edge (b)    (b) edge (c);
         }  \\
xx: &    \tikz[baseline=1pt]
        {\node[N=yellow] (a)   {D};
         \node[N=green]  (b)   {E};
         \draw  (a) edge (b);
         }
\end{tblr}

\end{document}

편집하다: 또는 매크로를 사용하여 조금 더 짧은 코드를 만들 수 있습니다 join.

\documentclass{article}

\usepackage{tabularray}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                chains,
                positioning}

\begin{document}

\tikzset{
node distance = 0mm and 5mm,
  start chain = going right,
     N/.style = {fill=#1!20, rounded corners=2pt, anchor=base,
                 inner ysep=4mm, inner xsep=0mm, minimum width=18mm,
                 on chain},
     N/.default = blue,
every join/.style = {-Straight Barb}    % <---
        }


\begin{tblr}{colspec = {Q[l,m] Q[r,m, wd=64mm]},
              colsep = 1mm, rowsep  = 0pt}

zz: &   \SetCell{l} something \\
yy: &   \tikz[baseline=1pt]
        {\node[N] (a)   {A};
         \node[N, join] {B};  % <---
         \node[N, join] {C};  % <---
         }  \\
xx: &    \tikz[baseline=1pt]
        {\node[N=yellow]        {D};
         \node[N=green, join]   {E};    % <---
         }
\end{tblr}
\end{document}

두 경우 모두 동일한 결과를 얻습니다.

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

부록: 내 [질문에 @Qrrbrbirlbel 답변을 사용하여2라이브러리를 사용하여 가능한 솔루션은 graphs다음과 같습니다.

\documentclass{article}

\usepackage{tabularray}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                graphs}

\begin{document}
    \begin{table}
    \centering
\tikzset{
     N/.style = {fill=#1!20, rounded corners=2pt, alias=N,
                 inner ysep=4mm, inner xsep=0mm, outer sep=0pt,
                 minimum width=18mm},
   N/.default = blue,
        }
\tikzgraphsset{
    branch right sep=5mm,
    every graph/.append style = {path, ->, /tikz/>=Straight Barb}}

\begin{tblr}{colspec = {Q[r] Q[r,wd=64mm]},
              colsep = 1mm, rowsep  = 0pt}
zz: &   \SetCell{l} something \\
yy: &   \tikz[baseline=(N.base)]    \graph{A[N],    B[N],   C[N]};  \\
xx: &   \tikz[baseline=(N.base)]    \graph{D[N=yellow], E[N=green]};
\end{tblr}
    \end{table}
\end{document}

컴파일 결과는 이전과 거의 동일합니다.

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

답변4

{NiceTabular}다음은 of nicematrix(및 화살표의 경우 Tikz)를 사용한 솔루션입니다 .

\documentclass{article}
\usepackage{nicematrix,tikz}

\begin{document}

\NewDocumentCommand{\Fill}{m}{\Block[fill=#1,rounded-corners]{}}

\begin{NiceTabular}{rw{c}{2cm}cw{c}{2cm}cw{c}{2cm}}[cell-space-limits=3mm]
   xx: & something \\
   yy: & \Fill{blue!15} A && \Fill{blue!15} B && \Fill{blue!15} C  \\
   xx: &   && \Fill{yellow!15} D && \Fill{green!15} E \\
\CodeAfter
   \begin{tikzpicture} [->]
   \draw (2.5-|3) -- (2.5-|4) ;
   \draw (2.5-|5) -- (2.5-|6) ;
   \draw (3.5-|5) -- (3.5-|6) ;
   \end{tikzpicture}
\end{NiceTabular}

\end{document}

평소와 같이 nicematrix여러 가지 편집이 필요합니다.

위 코드의 출력

관련 정보