Fancy tables with TikZ
August 26th, 2009 by Stefan Kottwitz
Today I wanted to create a table for a presentation and I remembered a suggestion made by Kjell Magne Fauske in comp.text.tex in August 2008, to use TikZ to create tables with rounded corners. I’ve investigated this idea further to achieve a colorful table layout in a shape that’s unusual for LaTeX. Here’s the result, displaying a ranking of Linux distributions produced by DistroWatch.com:
Click on the image to see it bigger, for a complete view open the pdf presentation.
The table has been put into a TikZ node, both at the top and at the bottom of the table I’ve used rectangles with rounded corners and some shading. A third rectangle is used to overlay parts of the other two rectangles.
The complete source code:
\documentclass{beamer} \usetheme{default} \usepackage{amsmath} \usepackage{tabularx} \usepackage{booktabs} \usepackage{colortbl} \usepackage{tikz} \usetikzlibrary{calc} \pgfdeclarelayer{background} \pgfdeclarelayer{foreground} \pgfsetlayers{background,main,foreground} \setbeamertemplate{background canvas}[vertical shading]% [top=blue!1,bottom=blue!30] \setbeamertemplate{navigation symbols}{} \newcommand*\up{\textcolor{green}{% \ensuremath{\blacktriangle}}} \newcommand*\down{\textcolor{red}{% \ensuremath{\blacktriangledown}}} \newcommand*\const{\textcolor{darkgray}% {\textbf{--}}} \begin{document} \begin{frame}[bg=lightgray] \textbf{\Large Linux distribution ranking, 26th August 2009} \begin{center} \begin{tikzpicture} \node (tbl) { \begin{tabularx}{.6\textwidth}{cXrcc} \arrayrulecolor{purple} \textbf{Rank} & \textbf{Distribution} & \textbf{Hits} & \\ 1 & Ubuntu\rule{0pt}{2.5ex} & 2114 & \down \\ \midrule 2 & Fedora & 1451 & \up \\ \midrule 3 & Mint & 1297 & \const \\ \midrule 4 & OpenSUSE & 1228 & \up \\ \midrule 5 & Debian & 910 & \down \\ \midrule 6 & Mandriva & 907 & \up \\ \midrule 7 & PCLinuxOS & 764 & \up \\ \midrule 8 & Puppy & 738 & \up \\ \midrule 9 & Sabayon & 671 & \up \\ \midrule 10 & Arch & 625 & \down \\[0.5ex] \end{tabularx}}; \begin{pgfonlayer}{background} \draw[rounded corners,top color=red,bottom color=black, draw=white] ($(tbl.north west)+(0.14,0)$) rectangle ($(tbl.north east)-(0.13,0.9)$); \draw[rounded corners,top color=white,bottom color=black, middle color=red,draw=blue!20] ($(tbl.south west) +(0.12,0.5)$) rectangle ($(tbl.south east)-(0.12,0)$); \draw[top color=blue!1,bottom color=blue!20,draw=white] ($(tbl.north east)-(0.13,0.6)$) rectangle ($(tbl.south west)+(0.13,0.2)$); \end{pgfonlayer} \end{tikzpicture} \end{center} \small Data by DistroWatch.com, spanning over the last 6 months, hits per day. \end{frame} \end{document}
It’s just a draft, some lengths have been adjusted to fit in order to demonstrate using TikZ with tables in a quick way.
This entry was posted on Mittwoch, August 26th, 2009 at 21:08 and is filed under pgf/TikZ, Figures and Tables, Graphics. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.






August 26th, 2009 at 21:31
Hi,
very nice for use in presentations. especially the use of gradient colours fillings make it look like it jumped right of some financial magazine
August 27th, 2009 at 09:24
This is a very interesting piece of code, well at least for me…
Aside from the LaTeX code, I would have liked a little more color contrast between the background and the foreground.
Also,the table header is red-to-black gradient, but the text being black as well makes it less readable.
Regards
August 27th, 2009 at 09:55
[…] blog TeXblog: Fancy tables with TikZSome TeX Developments: TeX Live on WindowsSome TeX Developments: LaTeX and Dalton TransactionsSome […]
August 27th, 2009 at 18:04
Hi Maratonda,
Like you I’m not satisfied with contrast and color, but decided to finish the post without making more adjustments because that experiment was already sufficient for me.
For my own presentations I’m usually choosing more decent colors and I’m preferring sober beamer themes.
Best regards,
Stefan
August 28th, 2009 at 12:16
Tikz so hard…
März 8th, 2010 at 23:27
[…] un commentaire » Fancy Table Version *.pdf ici. L’idée de ce tableau vient d’ici. J’ai simplement fait une fonction qui permet de l’utiliser comme un tableau Latex […]
März 8th, 2010 at 23:29
I think that would be interesting to do a new environment out of it. What do you think ?
Would you mind if I show the following example on my blog here: http://olivierlemaire.wordpress.com/2010/03/08/tableaux-tikz/?
%% the new environment
\newsavebox{\dataTableContent} % Box
\newenvironment{dataTable}[1] % \new environment
{%
\begin{lrbox}{\dataTableContent}%
\begin{tabular}{#1}}%
%
{%
\end{tabular}
\end{lrbox}
\begin{tikzpicture}
\node [inner xsep=0pt] (tbl){\usebox{\dataTableContent}};
\begin{pgfonlayer}{background}
% table
\draw[rounded corners=1pt,top color=gray!1,bottom color=gray!30,draw=black]
(tbl.north east) rectangle (tbl.south west);
% top line
\draw[rounded corners=1pt,top color=gray!10!black,bottom color=gray!50!black,draw=black]%
($(tbl.north west)$) rectangle ($(tbl.north east)-(0,1.5\baselineskip)$);
% bottom rule
\draw[rounded corners=0.25pt,fill=gray,draw=black]%
(tbl.south west) rectangle ($(tbl.south east)+(0,0.05)$);
\end{pgfonlayer}
\end{tikzpicture}}
%
%
%% Use of the environment
\begin{table}
\begin{center}
\begin{dataTable}%
{@{\hspace{2ex}} c @{\hspace{6ex}} l @{\hspace{6ex}} c @{\hspace{2ex}}}%
{\scshape\textcolor{white}{Rank}}
{Distribution}}
{\textsc{h.p.d.}}}\\ \midrule[0pt]
1 & Ubuntu & 2231 \\ \midrule
2 & Fedora & 1617 \\ \midrule
3 & Mint & 1438 \\ \midrule
4 & openSUSE & 1325 \\ \midrule
5 & Mandriva & 1054 \\ \midrule
6 & Debian & 978 \\ \midrule
7 & Puppy & 792 \\ \midrule
8 & Sabayon & 782 \\ \midrule
9 & PCLinuxOS & 779 \\ \midrule
10 & Arch & 729
\end{dataTable}
\end{center}
\caption{Source \url{http://distrowatch.com/index.php}}
\end{table}
März 11th, 2010 at 20:10
Hi Olivier,
that’s a good idea, thank you for this contribution!
Stefan
April 10th, 2010 at 02:31
[…] Idée originale… […]
April 27th, 2010 at 06:43
[…] Hier ein schönes Beispiel, wie man sehr bunte Tabellen mit LaTeX und TikZ erstellen kann: http://texblog.net/latex-archive/graphics/tikz-table/ […]
April 29th, 2010 at 21:36
Since I’ve noticed Uwes link, here’s another approach, using the tikz matrix feature. Though it’s a quick draft, I want to separate the formatting from the content, so the table in the document looks like
The output is:
My definition of the table environment was
The benefit of the separate definition is that if you use several tables in a presentation and you would like to modify the appearance, you just need to change one definition to affect the whole document.
The complete example code can be seen here.
Stefan
Juni 22nd, 2010 at 10:34
Hi Stefan
The link to the example code doesn’t seem to be working - I just get the blog’s page-furniture. Is there an alternative location? Thanks.
Kevin
Juni 22nd, 2010 at 23:30
Hi Kevin,
I’ve edited the link, hope you can see it now.
Stefan
Januar 5th, 2011 at 14:16
Hi!
I love your example, thank you very much for this. I have one question however: I would like to use other colours like LightBlue (from the xcolors package), but this doesn’t work. Why?
Juni 8th, 2011 at 15:13
Hi
A very nice and useful table. I still have a question. Is it possible to put a two lines heading.
I’ve tried to use parbox inside the cell and that gives two lines but then text exceeds the size (height) of the heading line.
\pbox{3cm}{first line \\ second line}
Any idea? thanks
Juni 8th, 2011 at 19:34
You could raise the vertical size of the rectangles, I just chose values. For example:
I raised 0.9 to 1.5 and 0.6 to 1.
Stefan
Dezember 6th, 2011 at 13:56
univision…
[…]Fancy tables with TikZ - TeXblog - Typography with TeX and LaTeX[…]…
März 23rd, 2012 at 04:12
How to change font size in above table?
April 17th, 2012 at 09:32
Hello,
Is it possible to support multi-columns in the matrixtable environment?
Thanks
November 28th, 2012 at 16:30
Yes i am also interested in the multicolum question