我想使用特殊的列分隔符。它与 tabularx 包配合使用很好,但与新的表格数组包。可以使用 tabularray 做同样的事情吗?
\documentclass[]{article}
\usepackage[table]{xcolor}
\usepackage{tabularx,tabularray}
\usepackage{chemmacros}
\begin{document}
%%% Tabularx %%%
\newcolumntype{Y}{>{\centering\arraybackslash}X}
\renewcommand{\arraystretch}{1.2}
\begin{tabularx}{\linewidth}{%
|l|*{4}{>{\centering\arraybackslash}X|}
}
\hline
\multicolumn{1}{|l!{:}}{Equation } &
\multicolumn{1}{c!{\makebox[0cm]{\ch{+}}}}{\ch{CH4}} &
\multicolumn{1}{c!{\makebox[0cm]{\ch{->}}}}{\ch{2 O2}} &
\multicolumn{1}{c!{\makebox[0cm]{+}}}{\ch{CO2}} &
\ch{2 H2O}
\\
\hline
Initial & $n_1$ & $n_2$ & 0 & 0
\\
\hline
Final & \cellcolor{red!20}$n_1-x$ & $n_2-2x$ & $x$ & $2x$
\\
\hline
\end{tabularx}
%%% Tabularray %%%
\begin{tblr}{%
vlines,hlines,
colspec={lX[c]X[c]X[c]X[c]},
cell{2}{2}={red9},
}
%%% don't work %%%
%\multicolumn{1}{|l!{:}}{Equation } &
%\multicolumn{1}{c!{\makebox[0cm]{\ch{+}}}}{\ch{CH4}} &
%\multicolumn{1}{c!{\makebox[0cm]{\ch{->}}}}{\ch{2 O2}} &
%\multicolumn{1}{c!{\makebox[0cm]{+}}}{\ch{CO2}} &
%\ch{2 H2O}
%\\
Initial & $n_1$ & $n_2$ & 0 & 0
\\
Final & $n_1-x$ & $n_2-2x$ & $x$ & $2x$
\\
\end{tblr}
\end{document}
答案1
这tabularray
目前,包不支持!
在命令中使用说明符(这会让代码看起来有点混乱,不是吗?)。您可以改用选项的键。\multicolumn
text
vline
% -*- coding: utf-8 -*-
\documentclass[]{article}
\usepackage[table]{xcolor}
\usepackage{tabularx,tabularray}
\usepackage{chemmacros}
\begin{document}
Tabularx:\smallskip
\newcolumntype{Y}{>{\centering\arraybackslash}X}
\renewcommand{\arraystretch}{1.2}
\begin{tabularx}{\linewidth}{%
|l|*{4}{>{\centering\arraybackslash}X|}
}
\hline
\multicolumn{1}{|l!{:}}{Equation } &
\multicolumn{1}{c!{\makebox[0cm]{\ch{+}}}}{\ch{CH4}} &
\multicolumn{1}{c!{\makebox[0cm]{\ch{->}}}}{\ch{2 O2}} &
\multicolumn{1}{c!{\makebox[0cm]{+}}}{\ch{CO2}} &
\ch{2 H2O}
\\
\hline
Initial & $n_1$ & $n_2$ & 0 & 0
\\
\hline
Final & \cellcolor{red!20}$n_1-x$ & $n_2-2x$ & $x$ & $2x$
\\
\hline
\end{tabularx}
\bigskip
Tabularray:\smallskip
\begin{tblr}{%
vlines, hlines,
colspec = {lX[c]X[c]X[c]X[c]},
cell{3}{2} = {red9},
vline{2} = {1}{ text = \clap{:} },
vline{3} = {1}{ text = \clap{\ch{+}} },
vline{4} = {1}{ text = \clap{\ch{->}} },
vline{5} = {1}{ text = \clap{\ch{+}} },
}
Equation & \ch{CH4} & \ch{2 O2} & \ch{CO2} & \ch{2 H2O} \\
Initial & $n_1$ & $n_2$ & 0 & 0 \\
Final & $n_1-x$ & $n_2-2x$ & $x$ & $2x$ \\
\end{tblr}
\end{document}