.png)
Com base nissoambiente tabular criado em tikz, eu estava tentando embrulhar um simples tabular
com o TikZ (provavelmente o tcolorbox poderia ser usado, mas a documentação parece um Everest para escalar para mim).
Meu problemático
O “longo” tabular
é separado em 4 blocos (neste exemplo, mais na realidade). Cada bloco será analisado em uma palestra. Ao final das 4 palestras o longa tabular
fará sentido como um todo.
Minha pergunta
O que devo fazer (tenho a sensação de que levei as coisas com o pé esquerdo) para digitar esta grande tabela apenas uma vez, mas na verdade usar cada bloco (mal separado entre \hline no exemplo, mas imagino que haja uma maneira muito melhor de fazer isso ), com o mesmo formato do original ?
MWE abaixo
\documentclass{standalone}
\usepackage[dvipsnames,table]{xcolor}
\usepackage{array}
\usepackage{environ}
\usepackage{tikz}
\usepackage{caption}
\newsavebox{\tablebox}
\definecolor{tablecolor}{named}{orange}
\NewEnviron{rndtable}[1]{%
\addtolength{\extrarowheight}{1ex}%
\rowcolors{2}{tablecolor!5}{tablecolor!20}%
\sffamily
\newcommand{\header}[1]{%
\multicolumn{1}{l}{%
\cellcolor{tablecolor}%
\color{white}%
\bfseries##1%
}%
}%
\savebox{\tablebox}{%
\begin{tabular}{#1}%
\BODY
\end{tabular}%
}%
%
\begin{tikzpicture}
\begin{scope}
\clip[rounded corners=1ex]
(0,-\dp\tablebox) rectangle (\wd\tablebox,\ht\tablebox);
\node at (0,-\dp\tablebox) [anchor=south west,inner sep=0pt]
{\usebox{\tablebox}};
\end{scope}
\draw[tablecolor,very thick,rounded corners=1ex]
(0,-\dp\tablebox) rectangle (\wd\tablebox,\ht\tablebox);
\end{tikzpicture}%
}
\newcolumntype{P}[1]{>{\raggedright\arraybackslash}p{#1}}
\begin{document}
\begin{rndtable}{r P{5cm}} %
\multicolumn{2}{l}{Block 2} \\ \hline
Block 1 Field 1 & Description that can be long, very long, even longer\\
Block 1 Field 2 & Description \\
Block 1 Field 3 & Description \\
Block 1 Field 4 & Description \\
\hline
Block 2 Field 1 & Description that can be long, very long, even longer\\
Block 2 Field 2 & Description \\
Block 2 Field 3 & Description \\
Block 2 Field 4 & Description \\
\hline
Block 3 Field 1 & Description that can be long, very long, even longer\\
Block 3 Field 2 & Description \\
Block 3 Field 3 & Description \\
Block 3 Field 4 & Description \\
\hline
Block 4 Field 1 & Description that can be long, very long, even longer\\
Block 4 Field 2 & Description \\
Block 4 Field 3 & Description \\
Block 4 Field 4 & Description \\
\hline
\end{rndtable}
\end{document}
Responder1
Uma abordagem – talvez deselegante – seria definir comandos para exibir os blocos. Com isso, você poderia fazer com que um comando carregasse a tabela inteira (como no MWE abaixo), ou ter um comando em cada tabela pequena e então criar a grande coletando esses comandos.
Veja tambémessa questão.
\documentclass{article}
\usepackage[dvipsnames,table]{xcolor}
\usepackage{array}
\usepackage{environ}
\usepackage{tikz}
\usepackage{caption}
\newsavebox{\tablebox}
\definecolor{tablecolor}{named}{orange}
\NewEnviron{rndtable}[1]{%
\addtolength{\extrarowheight}{1ex}%
\rowcolors{2}{tablecolor!5}{tablecolor!20}%
\sffamily
\newcommand{\header}[1]{%
\multicolumn{1}{l}{%
\cellcolor{tablecolor}%
\color{white}%
\bfseries##1%
}%
}%
\savebox{\tablebox}{%
\begin{tabular}{#1}%
\BODY
\end{tabular}%
}%
%
\begin{tikzpicture}
\begin{scope}
\clip[rounded corners=1ex]
(0,-\dp\tablebox) rectangle (\wd\tablebox,\ht\tablebox);
\node at (0,-\dp\tablebox) [anchor=south west,inner sep=0pt]
{\usebox{\tablebox}};
\end{scope}
\draw[tablecolor,very thick,rounded corners=1ex]
(0,-\dp\tablebox) rectangle (\wd\tablebox,\ht\tablebox);
\end{tikzpicture}%
}
\newcolumntype{P}[1]{>{\raggedright\arraybackslash}p{#1}}
\begin{document}
\newcommand{\block}[1]{
\ifcase#1\or% https://tex.stackexchange.com/questions/17676/conditional-cases-expression
\hline
Block 1 Field 1 & Description that can be long, very long, even longer\\
Block 1 Field 2 & Description \\
Block 1 Field 3 & Description \\
Block 1 Field 4 & Description \\
\or
\hline
Block 2 Field 1 & Description that can be long, very long, even longer\\
Block 2 Field 2 & Description \\
Block 2 Field 3 & Description \\
Block 2 Field 4 & Description \\
\or
\hline
Block 3 Field 1 & Description that can be long, very long, even longer\\
Block 3 Field 2 & Description \\
Block 3 Field 3 & Description \\
Block 3 Field 4 & Description \\
\or
\hline
Block 4 Field 1 & Description that can be long, very long, even longer\\
Block 4 Field 2 & Description \\
Block 4 Field 3 & Description \\
Block 4 Field 4 & Description \\
\else
block #1 not defined
\fi
}
\begin{rndtable}{r P{5cm}} %
\multicolumn{2}{l}{All Blocks} \\ \hline
\block{1}
\block{2}
\block{3}
\block{4}
\hline
\end{rndtable}
\vspace{\baselineskip}
\begin{rndtable}{r P{5cm}} %
\multicolumn{2}{l}{Block 2} \\ \hline
\block{2}
\hline
\end{rndtable}
\end{document}
Editar: Se você quiser dar um nome a cada bloco, você pode usar, por exemploetoolbox
\ifstrequal
comando de (§3.6.3 do manual).
\newcommand{\block}[1]{
\ifstrequal{#1}{block1}{%
Block 1 Field 1 & Description that can be long, very long, even longer\\
Block 1 Field 2 & Description \\
Block 1 Field 3 & Description \\
Block 1 Field 4 & Description
}{}\ifstrequal{#1}{block2}{%
Block 2 Field 1 & Description that can be long, very long, even longer\\
Block 2 Field 2 & Description \\
Block 2 Field 3 & Description \\
Block 2 Field 4 & Description
}{}\ifstrequal{#1}{block3}{%
Block 3 Field 1 & Description that can be long, very long, even longer\\
Block 3 Field 2 & Description \\
Block 3 Field 3 & Description \\
Block 3 Field 4 & Description
}{}\ifstrequal{#1}{block4}{%
Block 4 Field 1 & Description that can be long, very long, even longer\\
Block 4 Field 2 & Description \\
Block 4 Field 3 & Description \\
Block 4 Field 4 & Description
}
}
\begin{rndtable}{r P{5cm}} %
\multicolumn{2}{l}{All Blocks} \\ \hline
\block{block1} \\ \hline
\block{block2} \\ \hline
\block{block3} \\ \hline
\block{block4} \\
\end{rndtable}
\begin{rndtable}{r P{5cm}} %
\multicolumn{2}{l}{Block 2} \\ \hline
\block{block2} \\
\hline
\end{rndtable}