Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'd like to color the background of a single line of text in a some cells of a table. I need to obtain a result like this:

enter image description here

I have tried with \columncolor and \cellcolor but they don't leave me a white border. Here is my sample code:

\begin{tabular}{|l|l|l|}
    \hline
    ID: \cellcolor{gray}{0.9} & blabla &  blabla \\ \hline
    Title: & blabla & blabla \\ \hline
    State: & blabla & blabla\\ \hline
    Description: & blabla & blabla \\ \hline
    Type: & blabla  & blabla \\ \hline
    Priority: & blabla & blabla \\ \hline
\end{tabular}
share|improve this question
1  
Welcome to TeX.sx! A tip: You can use backticks ` to mark your inline code –  Corentin Dec 7 '12 at 10:21
    
possible duplicate of How do I fill table cells with a background color? –  Claudio Fiandrino Dec 7 '12 at 11:12
add comment

2 Answers

up vote 3 down vote accepted

enter image description here

\documentclass[12pt]{article} 

\usepackage{color}

\newcommand\celltitle[1]{{\fboxrule=0pt\fbox{\colorbox[gray]{0.9}{\makebox[3cm]{#1}}}}}

\begin{document}

\begin{tabular}{|l|l|l|}
    \hline
    \celltitle{ID:}  & blabla &  blabla \\ \hline
    \celltitle{Title:} & blabla & blabla \\ \hline
    \celltitle{State:} & blabla & blabla\\ \hline
    \celltitle{Description:} & blabla & blabla \\ \hline
    \celltitle{Type:} & blabla  & blabla \\ \hline
    \celltitle{Priority:} & blabla & blabla \\ \hline
\end{tabular}

\end{document}
share|improve this answer
add comment

Here is a simple adjustment of your code. It requires the packages color and colortbl. The key point is to define the colour using a \definecolor command.

\documentclass[12pt]{article} 

\usepackage{color,colortbl} 
\definecolor{Gray}{gray}{0.9}

\begin{document}

\begin{tabular}{|l|l|l|}
    \hline
    \cellcolor{Gray}ID:  & blabla &  blabla \\ \hline
    \cellcolor{Gray}Title: & blabla & blabla \\ \hline
    \cellcolor{Gray}State: & blabla & blabla\\ \hline
    \cellcolor{Gray}Description: & blabla & blabla \\ \hline
    \cellcolor{Gray}Type: & blabla  & blabla \\ \hline
    \cellcolor{Gray}Priority: & blabla & blabla \\ \hline
\end{tabular}

\end{document}
share|improve this answer
    
It doesn't give me the white border around the coulored text. –  ital Dec 7 '12 at 10:35
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.