1

I want to use special column separator. It works fine with tabularx package but not with the new tabularray package. Is it possible to do the same thing with 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 Answer 1

5

The tabularray package doesn't support using ! specifier in \multicolumn command at this moment (it makes the code look a little messy, isn't it?). You can use text key for vline option instead.

%  -*- 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} 

enter image description here

2
  • It's perfect. Also, I didn't know the \clap command. Thank you for this nice package!
    – jrivet
    Commented Jun 29, 2021 at 7:59
  • @jrivet Then you may accept this answer by clicking the check mark in the top left corner of the answer.
    – L.J.R.
    Commented Jun 29, 2021 at 8:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .