Generalhelp with shading cells in a table

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
azuki
Posts: 12
Joined: Fri May 02, 2008 7:22 pm

help with shading cells in a table

Post by azuki »

Hi everyone,

I'm a complete beginner in LaTeX and I've run into some trouble with creating a table. I have a table where I've aligned my numbers on the decimal point (using @{.} to represent a "decimal column"). I'd like to shade certain cells gray but when I do this, the .dvi file will turn out alright, but the .pdf file will replace the digits to the left of the decimal with a "(".

Here's some sample code

Code: Select all

\documentclass[12pt,Bold,letterpaper]{article}
\usepackage{colortbl}
\begin{document}
\begin{table}[htbp]
 \caption[Short.]
 {Caption.}
 \label{tab:table1}
   \renewcommand{\thefootnote}{\fnsymbol{footnote}}
  \begin{center}
    \begin{tabular}{lr@{.}lr@{.}lr@{.}lr@{.}lr@{.}lr@{.}lc} 
      \hline\hline
\multicolumn{1}{c}{A} & \multicolumn{2}{c}{B} & \multicolumn{2}{c}{C} & \multicolumn{2}{c}{D} & \multicolumn{2}{c}{E} & \multicolumn{2}{c}{F} & \multicolumn{2}{c}{G}  & H\\
      \hline

\emph{Line} &\cellcolor[gray]{0.9} \textbf{0} &\cellcolor[gray]{0.9}\textbf{235\footnotemark[1]} & 0&213\footnotemark[1]   & 0&216\footnotemark[1]   & 0&172   & 0&095 & 1&020 & blah\\
\emph{Line} & -0 & 235 & 0&213\footnotemark[1]   & 0&216\footnotemark[1]   & 0&172   & -0&095 & 1&020 & blah\\
      \hline
    \end{tabular}
  \end{center}
\footnotemark[1]Significant
\end{table}
\end{document}
I'd like to shade the cell with the number 0.235

I've tried getting rid of the boldface and the footnote to see if that was the problem, but it's the same result. Oddly, if I just shade the cell with the "0" (and leave out the shading of "235", it will be alright for the 0. But if I just shade the "235" but not the "0", I get the same problem. And, finally, if I don't use the decimal centered alignment, then everything seems ok (so this will be my last resort).

Any suggestions? Thanks for any help!

Recommended reading 2024:

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

NEW: TikZ book now 40% off at Amazon.com for a short time.

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

help with shading cells in a table

Post by gmedina »

One possible alternative is to use the dcolumn package. Refer to its documentation.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
azuki
Posts: 12
Joined: Fri May 02, 2008 7:22 pm

help with shading cells in a table

Post by azuki »

Thanks Gmedina - the dcolumn package is a much better way of getting decimal alignment.
However, I'm still coming across some problems. It seems that when I use it in conjunction with "boldface", it messes up the alignment. Here's my newest code:

Code: Select all

\documentclass[12pt,Bold,letterpaper]{article}
\usepackage{colortbl}
\usepackage{dcolumn}
\newcolumntype{.}{D{.}{.}{1.3}}
\begin{document}
\begin{table}[htbp]
\caption[Short.]
{Caption.}
\label{tab:table1}
   \renewcommand{\thefootnote}{\fnsymbol{footnote}}
  \begin{center}
    \begin{tabular}{lD{.}{.}{1.3}D{.}{.}{1.3}D{.}{.}{1.3}D{.}{.}{1.3}D{.}{.}{1.3}cc}
      \hline\hline
\multicolumn{1}{c}{A} & \multicolumn{1}{c}{B} & \multicolumn{1}{c}{C} & \multicolumn{1}{c}{D} & \multicolumn{1}{c}{E} & \multicolumn{1}{c}{F} & G  & H\\
      \hline

\emph{Line} &\cellcolor[gray]{0.9} \textbf{0.235\footnotemark[1]} & 0.213\footnotemark[1]   & 0.216\footnotemark[1]   & 0.172   & 0.095 & 1.020 & blah\\
\emph{Line} & -0.235 & 0.213\footnotemark[1]   & 0.216\footnotemark[1]   & 0.172   & -0.095 & 1.020 & blah\\
      \hline
    \end{tabular}
  \end{center}
\footnotemark[1]Significant
\end{table}
\end{document}
If I take out the boldface, the alignment is as I want it, but I'd also like to use the bold. I've tried increasing the "decimal places" in front of the decimal, but by the time it's aligned properly, it ends up being a really wide column. Thanks for any suggestions!
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

help with shading cells in a table

Post by Stefan Kottwitz »

Hi azuki,

splitting the \textbf would work:

Code: Select all

\textbf{0}.\textbf{235\footnotemark[1]}
Of course the dot will not be bold.

Stefan
LaTeX.org admin
azuki
Posts: 12
Joined: Fri May 02, 2008 7:22 pm

Re: help with shading cells in a table

Post by azuki »

Ah, at last, finally something that works. It's too bad that I have to split the numbers up just for the values I want bolded, especially since I have a pretty long table, but as long as something works, it will do! Thanks every one for your help!
Post Reply