davidcarlisle / dpctex

Assorted TeX packages
94 stars 30 forks source link

[colortbl] "breaks" '\hdotsfor' command #2

Open vp1981 opened 8 years ago

vp1981 commented 8 years ago

Hello, I noticed that colortbl "breaks" '\hdotsfor' command from amsmath package. Please consider the following two examples.

First example without package 'colortbl':

\documentclass{article}

\usepackage{amsmath}

\begin{document}

This is an example borrowed from the amsmath package documentation:
\begin{equation}
  \begin{pmatrix}
    D_1t&-a_{12}t_2&\dots&-a_{1n}t_n\\
    -a_{21}t_1&D_2t&\dots&-a_{2n}t_n\\
    \hdotsfor[2]{4}\\
    -a_{n1}t_1&-a_{n2}t_2&\dots&D_nt
  \end{pmatrix}
\end{equation}

\end{document}

Second example, with package 'colortbl'

\documentclass{article}

\usepackage{colortbl}
\usepackage{amsmath}

\begin{document}

This is an example borrowed from the amsmath package documentation:
\begin{equation}
  \begin{pmatrix}
    D_1t&-a_{12}t_2&\dots&-a_{1n}t_n\\
    -a_{21}t_1&D_2t&\dots&-a_{2n}t_n\\
    \hdotsfor[2]{4}\\
    -a_{n1}t_1&-a_{n2}t_2&\dots&D_nt
  \end{pmatrix}
\end{equation}

\end{document}

The second example shows that '\hdotsfor' command works differently when the 'colortbl' package is used.

davidcarlisle commented 8 years ago

Hmm yes, colortbl does document that any commands that add stretchable glue to an array cell need adjusting, however I agree it isn't obvious that colortbl is being used here (it modifies the underlying array/tabular implementation so affects all arrays even if they do not use colour) I'll see what I can do

davidcarlisle commented 8 years ago

colortbl already had some AtBeginDocument clauses fixing up specific package incompatibilities, I think that here something like this should work, I have added it to the test document but would be added to colortbl.sty in a real fix

\documentclass{article}

\usepackage{colortbl}

\makeatletter
\AtBeginDocument{%
\ifx\hdots@for\@undefined\else
\def\hdots@for#1#2{\multicolumn{#2}c%
  {\m@th\dotsspace@1.5mu\mkern-#1\dotsspace@
   \hskip\stretch{-.5}%
   \xleaders\hbox{$\m@th\mkern#1\dotsspace@.\mkern#1\dotsspace@$}%
           \hfill
   \hskip\stretch{-.5}%
   \mkern-#1\dotsspace@}%
   }%
\fi
}
\makeatother

\usepackage{amsmath}

\begin{document}

This is an example borrowed from the amsmath package documentation:
\begin{equation}
  \begin{pmatrix}
    D_1t&-a_{12}t_2&\dots&-a_{1n}t_n\\
    -a_{21}t_1&D_2t&\dots&-a_{2n}t_n\\
    \hdotsfor[2]{4}\\
    -a_{n1}t_1&-a_{n2}t_2&\dots&D_nt
  \end{pmatrix}
\end{equation}

\end{document}
vp1981 commented 8 years ago

Thank you, that '\AtBeginDocument' magic works fine.