Fancy tables with TikZ
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.
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
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
Pingback: Fancy Table with TikZ « Thai LaTeX and MATLAB
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
Tikz so hard…
Pingback: tableaux tikz « Olivier Lemaire’s Blog – Tribulations d’un ingénieur
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.5baselineskip)$);
% 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}}}%
{scshapetextcolor{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}
Hi Olivier,
that’s a good idea, thank you for this contribution!
Stefan
Pingback: Pro PageranK » Archives du Blog » tableaux tikz
Pingback: Schicke Tabellen mit TikZ « Uwes kleines Technikblog
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
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
Hi Kevin,
I’ve edited the link, hope you can see it now.
Stefan
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?
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
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
Pingback: univision
How to change font size in above table?
Hello,
Is it possible to support multi-columns in the matrixtable environment?
Thanks
Amazing, thank you for publishing this!
Yes i am also interested in the multicolum question