0

I want to create a table with Text aligned around the separator "V-" and color it using \rowcolor. The normal column separator @{V-} doesn't work with \rowcolors, thus I'm searching for a way to do it in another way. Is it possible to use the neat S column of the siunitx package? I tried it with

\usepackage[input-decimal-markers={V-}]{siunitx}

and

\usepackage[input-signs={V-}]{siunitx}

but it throws errors.

MWE:

\documentclass{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[table]{xcolor}
\usepackage{siunitx}
\begin{document}
with @{V-}:\\
\rowcolors{1}{black!10}{}
\begin{tabular}{|r@{V-}l|}
\hline
C & CV-\\\hline
CC & CV-\\\hline
h1C & V-\\\hline
\end{tabular}

with c and tabcolsep=0pt:\\
\setlength{\tabcolsep}{0pt}
\rowcolors{1}{black!10}{}
\begin{tabular}{|rcl|}
\hline
C & V- & CV-\\\hline
CC & V- & CV-\\\hline
h1C & V- & V-\\\hline
\end{tabular}
\end{document}

So far, the version with tabcolsep=0pt works best, but the table is quite ugly without any separator spaces. If I just use S, siunitx of course says “Invalid numerical input '-'.” Any ideas?

PS: I've read 205041 and 289298, but they don't answer my question.

Edit: I don't need to use siunitx, if anybody knows a different solution…

dessert
  • 568
  • 294579 seems to be the same problem, but involving matrices. Unfortunately, so does the brilliant solution of @egreg there – I don't think I can use this in any way, or can I? – dessert Mar 11 '16 at 17:49

2 Answers2

1

You can use the standard separator @{V-} in {NiceTabular} of nicematrix and you will have the expected output if you use the tools of nicematrix for the colors of the rows (a command \rowcolors{black!10}{} at the beginning of the array).

\documentclass{scrartcl}
\usepackage{xcolor}
\usepackage{nicematrix}

\begin{document} \begin{NiceTabular}{|r@{V-}l|}[color-inside] \hline \rowcolors{black!10}{} C & CV-\\hline CC & CV-\\hline h1C & V-\\hline \end{NiceTabular}

\end{document}

Output of the above code

F. Pantigny
  • 40,250
0

Even after several time trying I could not resolve the issue using siunitx, but I found a way using dcolumn and want to share my solution (which is more like a workaround though):

\documentclass{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[table]{xcolor}
\usepackage{booktabs}
\usepackage{dcolumn}
\begin{document}
\rowcolors{2}{black!10}{}
\begin{tabular}{lD{-}{\mbox{-}}{-1}}
\toprule
some things & \multicolumn{1}{c}{random root shapes} \\
\midrule
something & \mbox{CV}-\mbox{CV-} \\
something & \mbox{CCV}-\mbox{CV-} \\
something & \mbox{h1CV}-\mbox{V-} \\
\bottomrule
\end{tabular}
\end{document}

output

The reason for all the mboxing is that dcolumn sets the cell in math mode. The boxes prevent this and make it possible to enter other occurences of the alignment sign inside the cell.

dessert
  • 568