[Tex/LaTex] How to fill a table cell with a dash in tabular

tables

I have a basic table in the tabular environment, and I want to fill a cell with a dash, to show that there is nothing to go in that cell. I've tried just using dash, but can't get one that's long enough or connected.

Best Answer

Here I define a \longdash command, by default it's (slightly less) than an em-dash; it has an optional argument: \longdash[4] is (slightly less than) four en-dashes.

\documentclass{article}
\usepackage{booktabs,xcolor,colortbl}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\longdash}{ O{2} }
 {
  --\prg_replicate:nn { #1 - 1 } { \negthinspace -- }
 }
\ExplSyntaxOff


\begin{document}
\begin{tabular}{ccc}
\toprule
Foo & Bar column & Baz column \\
\midrule
123 & 456 & 789 \\
\rowcolor{red!20}%
\longdash & 42 & \longdash[2] \\
\rowcolor{green!20}%
\longdash & \longdash[3] & \longdash[4] \\
\bottomrule
\end{tabular}
\end{document}

Filling with \rowcolor involved seems tricky and, in my opinion, not desirable. However, I would recommend simply using an em-dash for this.

enter image description here

Related Question