My Master's Thesis Problems and solutions encountered…

4Apr/100

Beautiful LaTeX table

The trouble with writing your Thesis in LaTex is that it's someties difficult to make things beautiful, because it's so relatively hard to change formats, colors and such. Making a table can also be a bit time-consuming, but it's really not _that_ difficult.

I needed a table for my chapter on Requirements, and I wanted something special: I wanted that every second row was a different color and that the top and bottom line where thicker that the others. Below you can see a picture of the table:

Beautiful LaTeX table

First, you have to add the following code in your Preamble.tex:

 \usepackage[table]{xcolor}

The code for the table is as follows:


\begin{center}
\rowcolors{1}{white}{gray}
\begin{tabular}{  p{3cm}  |  p{8cm} }
\bottomrule
\textbf{Name} & \textbf{Description}\\  \hline

        Text & Text  \\ \hline
        Text & Text  \\ \hline
        Text & Text  \\ \hline
        Text & Text  \\ \hline
        Text & Text. \\ \hline
        Text & Text  \\ \hline

\bottomrule
\end{tabular}
\end{center}


And that's it!

Short explanation.

You have to notice two things: First,

\rowcolors{1}{white}{gray}



is what adds color to every second row. Second, it's the

 \bottomrule


that makes the first and the last line thicker.

Also, you'll notice that the rows in the picture are not gray. This is because I have defined a new color and used instead, as I really didn't like any of the deafult colors. New colors are defined it the Preable.tex like this:

\definecolor{orange}{RGB}{253,245,230}

As you can see, you can define a color by knowing the RGB-values. In this example, I have named the color "orange", which I then write in the table code: It will say

\rowcolors{1}{white}{orange}

instead of

\rowcolors{1}{white}{gray}

Adding new colors is not at all necessary. You can always use the deafult colors, so the last part is completely optional.

Filed under: LaTeX No Comments