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.

When using package colortbl, the command \hdotsfor fails (partially), leaving too much white space before and after the dotted part. The mwe

\documentclass{book}
\usepackage{colortbl}
\usepackage{amsmath}
\begin{document}    
\[
\begin{pmatrix}
    1&a_{11}&\dots&a_{1n}\\
    \hdotsfor{4}\\
    1&a_{r1}&\dots&a_{rn}
    \end{pmatrix} = r.
\]
\end{document}

produces

hdostsfor fails

Removing the package colortbl makes everything right:

hdotsfor is OK

I understand this may be related to \leaders and/or glue, which are explicitly mentioned in colortbl's documentation, so maybe this is a feature and not a bug.

Question: is there an easy workaround, bar removing colortbl?

share|improve this question
4  
there are only features, never bugs in my packages! (should be easy enough to make a compatible hdots, will look) –  David Carlisle Apr 16 '12 at 12:05
    
@DavidCarlisle: I thought so, thanks a lot for taking the time on this one! –  Koji Apr 16 '12 at 12:06

2 Answers 2

up vote 12 down vote accepted

Since \hdotsfor is only really designed for the AMS alignments, and colortbl colouring doesn't really work for them, I think the simplest is to add

\makeatletter

\def\hdots@for#1#2{\multicolumn{#2}c%
  {\m@th\dotsspace@1.5mu\mkern-#1\dotsspace@
   \xleaders\hbox{$\m@th\mkern#1\dotsspace@.\mkern#1\dotsspace@$}%
           \hskip\z@\@plus 1filll
   \mkern-#1\dotsspace@}%
   }
\makeatother

to your preamble after loading amsmath that makes these stretch with filll rather than fill glue which means that in the battle of elasticity with the colortbl the dots win.

If you wanted a version of \hdotfill that worked even if there was a colortbl panel behind it then it would require a bit more work.

share|improve this answer
    
This is good enough for me, I don't think I'll (ever) need a colored background to a \hdotsfor... :) –  Koji Apr 16 '12 at 12:20

The same answer of @DavidCarlisle but using etoolbox and its command \patchcmd to patch (replace) code in amsmath.sty

\usepackage{etoolbox}
\makeatletter
\patchcmd{\hdots@for}{\hfill}{\hskip\z@\@plus 1filll}{}{}
\makeatother

This must be put after of amsmath too.

share|improve this answer

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.