1

While using the packages colortbl, dcolumn for the scenario described in MWE, I am getting the below error message:

enter image description here

MWE:

\documentclass{article}

\usepackage{colortbl}
\usepackage{dcolumn}
\usepackage{color}

\def\tabpre{@{\extracolsep{\fill}}|p{5pc}|c|D{.}{.}{2,2}|c|}

\begin{document}

\begin{center}
\begin{tabular*}{\textwidth}{\tabpre}\hline
1aa&bb&cc&cc\\\hline
2aa&bb&cc&cc\\\hline
\end{tabular*}
\end{center}

...some text...

\begin{center}
\begin{tabular*}{\textwidth}{\tabpre}\hline
1aa&bb&4.00&cc\\\hline
2aa&bb&10.01&cc\\\hline
\end{tabular*}
\end{center}

\end{document}

Any suggestions.

9
  • 2
    d{2,2} doesn't exist. Check the documentation of dcolumn about the right syntax. Jul 4, 2023 at 13:47
  • 3
    array package tabular do not expand macros in the tabular preamble so you can not use \def\tabpre` Jul 4, 2023 at 14:23
  • 1
    Using @{\extracolsep{\fill}} makes sense only when using a tabular* environment. It's of no relevance when using a tabular environment.
    – Mico
    Jul 4, 2023 at 15:37
  • 2
    use \newcolumntype\tabpre. Jul 4, 2023 at 15:58
  • 3
    as Ulrike says. Jul 4, 2023 at 15:59

1 Answer 1

2

You can use \newcolumntype to store a tabular preamble:

\documentclass{article}

\usepackage{colortbl}
\usepackage{dcolumn}
\usepackage{color}

\newcolumntype\tabpre{@{\extracolsep{\fill}}|p{5pc}|c|D{.}{.}{2,2}|c|}

\begin{document}

\begin{center}
\begin{tabular*}{\textwidth}{\tabpre}\hline
1aa&bb&cc&cc\\\hline
2aa&bb&cc&cc\\\hline
\end{tabular*}
\end{center}

...some text...

\begin{center}
\begin{tabular*}{\textwidth}{\tabpre}\hline
1aa&bb&4.00&cc\\\hline
2aa&bb&10.01&cc\\\hline
\end{tabular*}
\end{center}

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .