Como alinho as coisas no seguinte ambiente tabular?

Como alinho as coisas no seguinte ambiente tabular?

Estou tentando colocar o que está abaixo em ordem no sentido de: (a) o texto em preto à esquerda (xx, yy, zz) deve estar alinhado verticalmente em relação à célula relevante da tabela à direita; (b) não há tanto espaço entre a coluna da esquerda e a coluna da direita com as caixas; (c) esta é complicada: como você pode ver, no conjunto inferior de caixas à direita, estou tentando alinhar D e E com B e C, mas por algum motivo, a imagem tikz fica "cortada".

Devo mencionar que estou usando tabularray depois de encontrar a seguinte resposta:Como centralizar verticalmente o texto das células?

Aqui está o 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}

Responder1

E quanto a isso? Usei um tabularambiente normal, coloquei os tikzpictures no modo matemático e \vcenteros editei. Resultado

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

Responder2

(a) Defina a linha de base das imagens tikz.
(b) Use Qo tipo de coluna em vez de X.
(c) Desenhe um nó invisível abaixo de A para alinhar B com D e C com E.

Aumentei a altura da caixa apenas para demonstrar.

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

insira a descrição da imagem aqui

Responder3

  • arrows.meta˛posicionamento de correntes usadas` andTikBibliotecas Z
  • definição de estilo tikz comum
  • Código curto ...
\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}

Editar: ou um código um pouco mais curto usando a joinmacro:

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

Em ambos os casos você obtém o mesmo resultado:

insira a descrição da imagem aqui

Termo aditivo: Usando a resposta @Qrrbrbirlbel na minha [pergunta2a solução possível usando graphsbiblioteca pode ser:

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

O resultado da compilação é quase o mesmo de antes.

insira a descrição da imagem aqui

Responder4

Aqui está uma solução com {NiceTabular}of nicematrix(e Tikz para as setas).

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

Como de costume, nicematrixvocê precisa de várias compilações.

Saída do código acima

informação relacionada