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.
Asked
Active
Viewed 5,077 times
2
Danger Fourpence
- 1,077
1 Answers
2
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.

barbara beeton
- 88,848
egreg
- 1,121,712
\hrulefillperhaps or that may be a bit low or you can use\ruleto make any rule of any fixed length and height above the baseline – David Carlisle Apr 09 '13 at 10:31\hrulefilldoes what I want it to, but it also messes up my cell colouring, where I've used\rowcolor– Danger Fourpence Apr 09 '13 at 10:46--or---– egreg Apr 09 '13 at 10:50