Graphics, Figures & TablesTable with color and dcolumn

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
CSLehmann
Posts: 3
Joined: Tue Oct 16, 2012 2:12 pm

Table with color and dcolumn

Post by CSLehmann »

Dear all,

I want to make a table which
1) aligns the decimal input for which I use dcolumn
2) gives some color to some numbers

The code (see below) works, but it gives 20 errors. Anybody has a clue to get rid of the error messages?
Thanks a lot,

Stefan Lehmann

Code: Select all

\documentclass{book}
\usepackage{tabularx, multirow, booktabs}

\usepackage{xcolor}
\usepackage{tabu}
\usepackage{dcolumn}

\newcolumntype{d}[1]{D{.}{.}{#1}}
\makeatletter
\def\DC@endright{$\hfil\egroup\@dcolcolor\box\z@\box\tw@\dcolreset$}
\def\dcolcolor#1{\gdef\@dcolcolor{\color{#1}}}
\def\dcolreset{\dcolcolor{black}}
\dcolcolor{black}
\makeatother
    
\begin{document}
\begin{document}

\begin{tabu}{cd{3}}
 note & 1.32\\
 \color{red}note & 1.32 \\
 note & \dcolcolor{red} 1.3 \\
 \multicolumn{2}{r}{	\begin{tabular}{d{3}}	\dcolcolor{blue}{12.12} \end{tabular}  }\\
 note & 1.32\\
 note & \dcolcolor{red}-1.32\\
 \multicolumn{2}{r}{	\begin{tabular}{d{3}}	1.1	\end{tabular} } \\
 \textcolor{red}{note} & 1.5 \\
\end{tabu}

\end{document}
Last edited by CSLehmann on Tue Oct 16, 2012 3:33 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

mas
Posts: 226
Joined: Thu Dec 04, 2008 4:39 am

Table with color and dcolumn

Post by mas »

You should use the code tags to put your code so that it can be copied and compiled correctly.

Why are you using tabular for a single entry? Is it just a placeholder for some complex structure? Assuming otherwise, try this code. See if it suits your purpose:

Code: Select all

\documentclass{book}
\usepackage{siunitx}

\usepackage{xcolor}

\begin{document}

\begin{tabular}{cS}
note & 1.32\\
{\color{red}note} & 1.32 \\
note & {\color{red} 1.3 } \\
     & \color{blue} 12.12 \\
note & 1.32\\
note & \color{red}-1.32 \\
     & 1.1 \\
\textcolor{red}{note} & 1.5 \\
\end{tabular}

\end{document}
Regards.

OS: Debian/GNU Linux; LaTeX System : TeXLive; Editor : Vim
CSLehmann
Posts: 3
Joined: Tue Oct 16, 2012 2:12 pm

Table with color and dcolumn

Post by CSLehmann »

I tried

Code: Select all

 \usepackage {siunitx} 
but I get ! package siunitx error: support package expl3 is too old ...

and LaTex changes all the 'S' into 'c'
mas
Posts: 226
Joined: Thu Dec 04, 2008 4:39 am

Re: Table with color and dcolumn

Post by mas »

Looks like a version problem. I am using TeXLive 2012 and the version of siunitx is 2.5c. Which version of siunitx are you using?

Regards.

OS: Debian/GNU Linux; LaTeX System : TeXLive; Editor : Vim
CSLehmann
Posts: 3
Joined: Tue Oct 16, 2012 2:12 pm

Re: Table with color and dcolumn

Post by CSLehmann »

TeXnicCenter,

I will try TexLive today and see whether it helps.
Post Reply