Graphics, Figures & TablesTables and Colors

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
ioctlvoid
Posts: 5
Joined: Fri Jul 29, 2011 5:20 am

Tables and Colors

Post by ioctlvoid »

I'm having a lot of trouble trying to color individual cells in a table with a specific background and foreground color.

See the attached picture for a depiction of what I'm trying to obtain with LaTeX.

This is what I have in LaTeX so far:

Code: Select all

\begin{table}[H]
\caption{Register segmentation}
\begin{center}
\begin{tabular}{ | c | c | c | c | c | c | c | c | c |}
\hline
\hline
\textbf{RAX} & 8 bits & 8 bits & 8 bits & 8 bits & 8 bits & 8 bits & 8 bits & 8 bits\\
\hline
\multicolumn{1}{|>{\color{red}\columncolor[Yellow]{0.8}}l||}{yellow color} & \multicolumn{1}{|>{\columncolor{Blue}}l|}{blue color} & 8 bits & bits & 8 bits & 8 bits & 8 bits & 8 bits & 8 bits\\
\hline
\textbf{EAX} & - & - & - & - & 8 bits & 8 bits & 8 bits & 8 bits\\
\hline
\textbf{AX} & - & - & - & - & - & - & 8 bits & 8 bits\\
\hline
\textbf{AH} & - & - & - & - & - & - & 8 bits & -\\
\hline
\textbf{AL} & - & - & - & - & - & - & - & 8 bits\\
\hline
\end{tabular}
\end{center}
\label{table1}
\end{table}
However, I get the following errors when parsing the file:

Code: Select all

! LaTeX Error: Undefined color model `Yellow'.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.434 ...lumncolor[Yellow]{0.8}}l||}{yellow color}
                                                   & \multicolumn{1}{|>{\col...

? 
! Emergency stop.
I do not get these errors when I simply use \rowcolor or just plain \textcolor.

What is wrong? Why do I get these errors? In my preamble I have:

Code: Select all

\usepackage[dvipsnames,usenames]{color}
\usepackage{array}
\usepackage{colortbl}
Attachments
table_5.png
table_5.png (10.29 KiB) Viewed 2751 times

Recommended reading 2024:

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

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

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Tables and Colors

Post by localghost »

Please always provide a minimal example that is compilable as is for everybody. Otherwise giving specific help becomes very difficult. Especially when a problem is more complicated.

The error message indicates that the color »Yellow« is not defined. Furthermore you are using the \multicolumn command not correctly. The below example generates the table in your attachment.

Code: Select all

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}                  % Enable Cork Encoding (Type 1 fonts)
\usepackage[tableposition=top]{caption}   % Customization of caption
\usepackage[dvipsnames,table]{xcolor}     % »table« option loads package »colortbl«
\usepackage{array}                        % Enhancements for tables

\begin{document}
  \begin{table}[!ht]
    \caption{Register segmentation}\label{tab:reg-seg}
    \centering
    \begin{tabular}{|>{\bfseries\columncolor{cyan!25}}c|c|c|c|c|c|c|>{\columncolor{yellow}}c|>{\columncolor{yellow}}c|}\hline
      \rowcolor{yellow}
      \cellcolor{cyan!25}RAX & 8 bits & 8 bits & 8 bits & 8 bits & 8 bits & 8 bits & 8 bits & 8 bits \\ \hline
      EAX &  ---   &  ---   &  ---   &  ---   & \cellcolor{yellow}8 bits & \cellcolor{yellow}8 bits & 8 bits & 8 bits \\ \hline
      AX  &  ---   &  ---   &  ---   &  ---   &  ---   &  ---   & 8 bits & 8 bits \\ \hline
      AH  &  ---   &  ---   &  ---   &  ---   &  ---   &  ---   & 8 bits &  \cellcolor{white}---   \\ \hline
      AL  &  ---   &  ---   &  ---   &  ---   &  ---   &  ---   & \cellcolor{white}---   & 8 bits \\ \hline
    \end{tabular}
  \end{table} 
\end{document}
Don't be irritated by possibly vanishing rules in the table. This is mostly a viewer problem. Zoom in to check that all rules are present. The printed output should be OK.


Best regards and welcome to the board
Thorsten
Post Reply