表格阵列:我想创建一个列,在前面添加和附加一些代码以节省空间并避免重复,但我无法实现这种行为。
起初,我尝试(但失败了)创建一个新的列类型
\NewColumnType{t}[1]{Q[l,cmd=\adjustbox{valign=m}{\begin{tikzpicture} #1 \end{tikzpicture}}]}
之后,我尝试在该列中使用preto
&appto
,并取得了一些进展,但由于括号闭合失败,我无法插入\adjustbox{valign=m}{
,而且,我不知道如何为第 1 列但第一行指定该行为,我尝试使用单元格和列{1}{2-Z},但我对此很陌生,没有成功
\documentclass{article}
\usepackage{tabularray}
\usepackage{tikz}
\usepackage{lipsum}
\usetikzlibrary{shapes.geometric, arrows.meta, calc, patterns, patterns.meta, shadows}
\usepackage{chemplants}
\begin{document}
\begin{longtblr}[
caption = {Materiales identificados},
label = {table:materiales_identificados}
]{
colspec = {c X},
hlines,
vlines,
row{odd} = {bg=red!20!green!20!blue!20},
row{1} = {
bg = red!80!green!20!blue!20,
font = \large\bfseries
},
rowhead = 1,
rows = {
valign = m
},
column{1} = {
preto = {\begin{tikzpicture}},
appto = {\end{tikzpicture}}
}
}
Simbología & descripción \\
%
\pic [scale = 1] at (0, 0) {centrifugal pump};
& \textbf{Bomba centrífuga}: \lipsum[1][1]
\end{longtblr}
\end{document}
我怎样才能实现第一列第一行的这种行为使用 tabularray?
\adjustbox{valign=m}{
\begin{tikzpicture}
#1
\end{tikzpicture}
}
答案1
cell{2-Z}{1} = {cmd=\adjusttikzpic}
\adjusttikzpic
对第一列的内容(第一个单元格除外) 执行,\adjusttikzpic
其中定义如下:
\NewDocumentCommand{\adjusttikzpic}{m}{%
\adjustbox{valign=m}{%
\begin{tikzpicture}
#1
\end{tikzpicture}%
}
}
完整代码:
\documentclass{article}
\usepackage{tabularray}
\usepackage{tikz}
\usepackage{lipsum}
\usetikzlibrary{shapes.geometric, arrows.meta, calc, patterns, patterns.meta, shadows}
\usepackage{chemplants}
\usepackage{adjustbox} % for \adjustbox
\NewDocumentCommand{\adjusttikzpic}{m}{% define \adjusttikzpic command
\adjustbox{valign=m}{%
\begin{tikzpicture}
#1
\end{tikzpicture}%
}
}
\begin{document}
\begin{longtblr}[
caption = {Materiales identificados},
label = {table:materiales_identificados}
]{
colspec = {c X},
hlines,
vlines,
row{odd} = {bg=red!20!green!20!blue!20},
row{1} = {
bg = red!80!green!20!blue!20,
font = \large\bfseries
},
rowhead = 1,
rows = {
valign = m
},
cell{2-Z}{1} = {cmd=\adjusttikzpic}, % executing \adjusttikzpic for the content of the first column (except for the first cell)
}
Simbología & Descripción \\
%
\pic [scale = 1] at (0, 0) {centrifugal pump};
& \textbf{Bomba centrífuga}: \lipsum[1][1]
\end{longtblr}
\end{document}