Latex tables

I wrote my Master’s Thesis in Latex since it allows me to focus on the content of the paper rather than on how it looks. Having the content it is possible to change the output style by changing the Latex code. Recently, I faced a problem of creating tables with background color. After some time Googleing I found some information. On its basis a created table I wanted (look below).

Latex table

The Latex code for the document containing page with such a output looks as follows:


\documentclass{article}

\usepackage[english]{babel}
\usepackage{colortbl}

\begin{document}

\section{Table test}

\begin{tabular}{|l|p{8cm}|}

\hline

\multicolumn{1}{| >{\columncolor[rgb]{0.8,0.8,0.8}}r|}{Id} &
UC01 \\

\hline

\multicolumn{1}{| >{\columncolor[rgb]{0.8,0.8,0.8}}r|}{Title} &
Delivering a list of LOs\\

\hline

\multicolumn{1}{| >{\columncolor[rgb]{0.8,0.8,0.8}}r|}{Description} &
Providing a list of existing Learning Objects created from
the informal knowledge stored in the repository.\\

\hline

\multicolumn{1}{| >{\columncolor[rgb]{0.8,0.8,0.8}}r|}{Actors} &
A02, A03 \\

\hline

\multicolumn{1}{| >{\columncolor[rgb]{0.8,0.8,0.8}}r|}{Initial occurence}
& Claim for list of LOs.\\

\hline

\multicolumn{1}{| >{\columncolor[rgb]{0.8,0.8,0.8}}r|}{
Exceptional occurence}
 &  Unsuccesful connection to the repository\\

\hline

\multicolumn{1}{| >{\columncolor[rgb]{0.8,0.8,0.8}}r|}{Related use cases} &
UC07, UC17\\

\hline

\end{tabular}

\end{document}


So whenever You use tables with coloured cells:

  • inlcude colortbl package
  • use \multicolumn{1}{| >{\columncolor[rgb]{0.8,0.8,0.8}}r|}{Id}, where in first bracket you define the number of columns this applies to, in the second the color and in the last the content of the cell(s)

Enjoy this Post?

Your vote will help me grow this site and provide even more information

6 Responses to “Latex tables”


  1. 1 Ana Romero

    Thnak you very much! :D I was also working on use cases hahaha

  2. 2 Zeid

    Hello,
    nice tips, thanks. Would you know how we can change the color of the borders of a table in LaTeX? Have you tried this before?

    thanks

  3. 3 Jarosław Dobrzański

    Unfortunately I haven’t tried that. I hope Google will me more of the help :)

  4. 4 christos

    hi,

    thax for posting. exactly what i was looking for.

    can you add an explanation how the rgb code works? must be a value between 0 and 1. i only found either hex or decimal numbers as reverences to the color. how do i get the right number for a specific color, if i got the hex number or decimal number?

    cheers

  5. 5 Patricia

    Thanks a lot!!!!

  6. 6 richard

    you can also use \columncolor{red} for example. For some reason the color model of RGB does not work (enabling values of 0-255) and it also breaks the printing of cells in a multirow cell. In other words yet more latex hack and pain. I could never have believed something so painfully necessary as colored columnds and rows could be implemented so painfully. In addition, the comments about latex separating content from presentation are ludicrous : its one of the most presentation orientated content management forums I have ever seen.

Leave a Reply




Switch to our mobile site