Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
    
\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
    
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
show 1 more comment

1 Answer

up vote 2 down vote accepted

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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