2

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.

  • \hrulefill perhaps or that may be a bit low or you can use \rule to make any rule of any fixed length and height above the baseline – David Carlisle Apr 9 '13 at 10:31
  • perhaps the cancel package can be of use here (or perhaps tex.stackexchange.com/questions/20643?) – Sean Allred Apr 9 '13 at 10:45
  • \hrulefill does what I want it to, but it also messes up my cell colouring, where I've used \rowcolor – Danger Fourpence Apr 9 '13 at 10:46
  • 1
    I'd simply use -- or --- – egreg Apr 9 '13 at 10:50
  • @egreg I've tried those, they're too narrow for my liking – Danger Fourpence Apr 9 '13 at 11:01
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.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.