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'm interested in learning about some nice-looking table samples. Colors can make a huge difference, and just providing some color to headers, background, or borders can dramatically change presentation. Any samples you're proud to share?

(BTW here's a sample I like, but unfortunately, not TeX...)

enter image description here

share|improve this question
3  
big-list? CW? But, +1 for the idea. –  kan May 4 '13 at 11:07
3  
Great question! I kind of given up on tables in LaTeX, as they tend to be pretty ugly and hard to maintain most of the time. Almost all examples/how-tos about tables produce results which are kind of embarrasing... just look at the first answer, it is ridiculous! But maybe someone will come along and shows how to do "beautiful" and easy to maintain tables. –  Simon Lehmann May 4 '13 at 13:01
2  
That green is hard to read. Also, more vspacing may make it look better. –  User 17670 May 4 '13 at 18:59
7  
If you want to make a beautiful table that you can actually enjoy with your family and friends, you start by acquiring specimens of fine hardwood, and then apply those woodworking skills. –  Kaz May 5 '13 at 2:52
2  
Some very nice css tables are here (Perhaps somebody could "transform" those to LaTeX) –  moose May 8 '13 at 19:47

9 Answers 9

I think its worth mentioning the combination tcolorbox-tabularx, which provides an easy way to draw (possibly very much) fancy tables.

Some examples:

\documentclass{article}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tcolorbox}
\usepackage{tabularx}
\usepackage{array}
\usepackage{colortbl}
\tcbuselibrary{skins}

\newcolumntype{Y}{>{\raggedleft\arraybackslash}X}

\tcbset{tab1/.style={fonttitle=\bfseries\large,fontupper=\normalsize\sffamily,
colback=yellow!10!white,colframe=red!75!black,colbacktitle=Salmon!40!white,
coltitle=black,center title,freelance,frame code={
\foreach \n in {north east,north west,south east,south west}
{\path [fill=red!75!black] (interior.\n) circle (3mm); };},}}

\tcbset{tab2/.style={enhanced,fonttitle=\bfseries,fontupper=\normalsize\sffamily,
colback=yellow!10!white,colframe=red!50!black,colbacktitle=Salmon!40!white,
coltitle=black,center title}}

\begin{document}

\begin{tcolorbox}[tab2,tabularx={X||Y|Y|Y|Y||Y}]
Group & One     & Two     & Three    & Four     & Sum      \\\hline\hline
Red   & 1000.00 & 2000.00 &  3000.00 &  4000.00 & 10000.00 \\\hline
Green & 2000.00 & 3000.00 &  4000.00 &  5000.00 & 14000.00 \\\hline
Blue  & 3000.00 & 4000.00 &  5000.00 &  6000.00 & 18000.00 \\\hline\hline
Sum   & 6000.00 & 9000.00 & 12000.00 & 15000.00 & 42000.00
\end{tcolorbox}

\begin{tcolorbox}[tab2,tabularx={X||Y|Y|Y|Y||Y},title=My table,boxrule=0.5pt]
Group & One     & Two     & Three    & Four     & Sum      \\\hline\hline
Red   & 1000.00 & 2000.00 &  3000.00 &  4000.00 & 10000.00 \\
Green & 2000.00 & 3000.00 &  4000.00 &  5000.00 & 14000.00 \\
Blue  & 3000.00 & 4000.00 &  5000.00 &  6000.00 & 18000.00 \\\hline\hline
Sum   & 6000.00 & 9000.00 & 12000.00 & 15000.00 & 42000.00
\end{tcolorbox}

\begin{tcolorbox}[tab1,tabularx={X||YYYY||Y}]
Group & One     & Two     & Three    & Four     & Sum      \\\hline\hline
Red   & 1000.00 & 2000.00 &  3000.00 &  4000.00 & 10000.00 \\
Green & 2000.00 & 3000.00 &  4000.00 &  5000.00 & 14000.00 \\
Blue  & 3000.00 & 4000.00 &  5000.00 &  6000.00 & 18000.00 \\\hline\hline
Sum   & 6000.00 & 9000.00 & 12000.00 & 15000.00 & 42000.00
\end{tcolorbox}

\end{document}

enter image description here

The are endless customization possibilities, and everything is a matter of writing a custom tcb style that suits your needs. The examples (with some modifications) are taken from the tcolorbox manual, section /tcb/tabularx.

share|improve this answer
17  
My dentist has one of those table s similar to the last one in the waiting room. For documents it's a no-go in my opinion. –  percusse May 4 '13 at 12:34
11  
@percusse Well, it depends. Today the word "document" is used in many ways... I see lots of financial reports with extremely fancy tables (much more than that of your dentist - I just remembered one with a deep blue skyline background!) and many people seem to like them so that they're sometimes required. That's why I usually suspend judgment on matters of taste and beauty and just discuss possibilities. –  dcmst May 4 '13 at 12:44
24  
To quote from the booktabs documentation: 1. Never, ever use vertical lines. 2. Never use double lines. I tend to agree. –  Tom Bombadil May 4 '13 at 12:48
24  
@TomBombadil I find the "Never, ever" part to really be nonsense. –  dcmst May 4 '13 at 13:19
7  
@dcmst Maybe it's harsh to say "Never, ever", but I honestly haven't seen any case where it would produce a nice result. It is highly distasteful imho, as are all the tables above –  Xavier May 4 '13 at 18:02

I also favour the guidance given by booktabs, and generally prefer simple, unadorned tables. However, it may be that you want to draw attention to say the highest value for a given row --- e.g., a table of your teaching evaluation scores. (That is, a document that might be able to be 'louder' than something you'd want to put in a book.) In this case, perhaps some colour would be appropriate for an electronic form, but you'd rather just have bold for a printed version. Etc., etc.

Here is a simplified version of what I have done before (meant for fontspec-reliant engines):

\documentclass[12pt, oneside, landscape]{memoir}

\newif\ifblackandwhite
% \blackandwhitetrue


\usepackage{fontspec}%
\defaultfontfeatures{Ligatures=TeX}%
\setmainfont[%
   Numbers        = OldStyle ,
   ItalicFont     = LinLibertineOI ,
   BoldItalicFont = LinLibertineOBI ,
   BoldFont       = LinLibertineOB ,
]{LinLibertineO}%


\usepackage[hmargin=2cm,vmargin=2.5cm]{geometry}
\usepackage{etoolbox}
\usepackage{longtable}%
\AtBeginEnvironment{longtable}{%
  \addfontfeature{RawFeature=+tnum;-onum}%  <--- requires LuaTeX
}

\usepackage{pdflscape}
\usepackage[svgnames]{xcolor}
\usepackage{colortbl}%
  \newcommand{\myrowcolour}{\rowcolor[gray]{0.925}}
\usepackage{booktabs}

\ifblackandwhite
  \newcommand{\cheading}[2]{\textbf{#1\hfill #2}}
  \newcommand{\highest}[1]{\textbf{#1}}% == highest score for question
\else
  \newcommand{\cheading}[2]{\textcolor{Maroon}{\textbf{#1\hfill #2}}}
  \newcommand{\highest}[1]{\textcolor{Maroon}{\textbf{#1}}}%
\fi



\begin{document}
\thispagestyle{empty}
\parindent0pt
%

\cheading{Fake Course Evaluation Summary for \textsc{course
    1234y}}{Sept.\ 2010 --- May 2011}

\begin{longtable}{@{}l rr rr rr rr rr rr}
% pairs: absolute number (percentage)

\toprule%
 \centering%
 & \multicolumn{2}{c}{{{\bfseries Excellent}}}
 & \multicolumn{2}{c}{{{\bfseries Very Good}}}
 & \multicolumn{2}{c}{{{\bfseries Good}}}
 & \multicolumn{2}{c}{{{\bfseries Average}}}
 & \multicolumn{2}{c}{{{\bfseries Poor}}}
 & \multicolumn{2}{c}{{{\bfseries Very Poor}}} \\


\cmidrule[0.4pt](r{0.125em}){1-1}%
\cmidrule[0.4pt](lr{0.125em}){2-3}%
\cmidrule[0.4pt](lr{0.125em}){4-5}%
\cmidrule[0.4pt](lr{0.125em}){6-7}%
\cmidrule[0.4pt](lr{0.125em}){8-9}%
\cmidrule[0.4pt](lr{0.125em}){10-11}%
\cmidrule[0.4pt](l{0.25em}){12-13}%
% \midrule
\endhead


Some question about the Instructor or Course & 2 & (7.14) & 4 &
(14.29) & \highest{12} & \highest{(42.86)} & 4
& (14.29) & 6 & (21.43) & 0 & (0.00) \\

\myrowcolour%
Some question about the Instructor or Course & 3 & (10.71) &
\highest{15} & \highest{(53.57)} & 5 & (17.86) & 5 & (17.86) & 0 &
(0.00) & 0 & (0.00) \\

Some question about the Instructor or Course & 4 & (14.29) & 8 &
(28.57) & \highest{15}
& \highest{(53.57)} & 1 & (3.57) & 0 & (0.00) & 0 & (0.00) \\

\myrowcolour%
Some question about the Instructor or Course & 3 & (10.71) & 8 &
(28.57) & \highest{10} & \highest{(35.71)}
& 5 & (17.86) & 2 & (7.14) & 0 & (0.00) \\

Some question about the Instructor or Course & 6 & (21.43) &
\highest{9} & \highest{(32.14)}
& 4 & (14.29) & \highest{9} & \highest{(32.14)} & 0 & (0.00) & 0 & (0.00) \\

\myrowcolour%
Some question about the Instructor or Course & \highest{10} &
\highest{(35.71)} & \highest{10} & \highest{(35.71)}
& 3 & (10.71) & 5 & (17.86) & 0 & (0.00) & 0 & (0.00) \\

Some question about the Instructor or Course & \highest{12} &
\highest{(42.86)} & \highest{12} & \highest{(42.86)} & 3
& (10.71) & 1 & (3.57) & 0 & (0.00) & 0 & (0.00) \\

\myrowcolour%
Some question about the Instructor or Course & \highest{12} &
\highest{(42.86)} & 3 & (10.71) & 7
& (25.00) & 5 & (17.86) & 1 & (3.57) & 0 & (0.00) \\

Some question about the Instructor or Course & \highest{10} &
\highest{(35.71)} & 6 & (21.43) & 6 & (21.43) & 6 & (21.43)
& 1 & (3.57) & 0 & (0.00) \\

\myrowcolour%
Some question about the Instructor or Course & 5 & (17.86) & 5 &
(17.86) & \highest{12} & \highest{(42.86)} & 2 & (7.14)
& 3 & (10.71) & 1 & (3.57)\\

Some question about the Instructor or Course & 3 & (10.71) & 8 &
(28.57) & \highest{11} & \highest{(39.29)} & 3 & (10.71) & 3 & (10.71)
& 0 & (0.00) \\

\myrowcolour%
Some question about the Instructor or Course & \highest{18} &
\highest{(64.29)}
& 5 & (17.86) & 3 & (10.71) & 1 & (3.57) & 1 & (3.57) & 0 & (0.00) \\

Some question about the Instructor or Course & \highest{15} &
\highest{(53.57)}
& 7 & (25.00) & 2 & (7.14) & 2 & (7.14) & 2 & (7.14) & 0 & (0.00) \\

\myrowcolour%
Some question about the Instructor or Course & 3 & (10.71) &
\highest{13} & \highest{(46.43)} & 4 & (14.29) & 6 & (21.43) & 2
& (7.14) & 0 & (0.00) \\

\bottomrule

\end{longtable}

\end{document}

Remarks: Uncomment \blackandwhitetrue if you want to disable colour. And the \addfontfeature command in \AtBeginEnvironment requires the fontspec package.

example table

share|improve this answer
3  
While I like the overall layout of this table, I'm disturbed by the fact that bold digits are wider that normal digits, and therefore all digits are not aligned in nice, tidy columns. –  adl May 8 '13 at 18:41
    
@adl -- This was a concern of mine as well, but I tried colour without the bold and it just didn't look right to me; worse, if you want a black and white version, there is no good way to make the numbers you are interested in stand out; highlighting individual cell backgrounds, e.g., looks terrible. Remember, too, this is an idea I endorse for less formal documents where you are trying to make something stand out ... plus, given the right-alignment, numbers unaligned only on the lefthand side doesn't seem that severe. Of course, to each their own, etc., etc. –  jon May 8 '13 at 18:57
2  
Did you try \npboldmath from the numprint package? It does not seem to work with all fonts, but I have fixed alignment of bold digits in tables with that in the past. –  adl May 8 '13 at 19:53
    
@adl -- (Sorry for the late response; things got busy.) Thanks for the suggestion. I did not know of this package. It doesn't seem to work well with this font (after a quick test): either it switches the font to CM or the parentheses end up sticking out on the right-hand side instead of the left, but I can see the potential. And I will keep it in mind for the future. Also, if you post a modified/improved example using the package, I'd vote for it! –  jon May 12 '13 at 0:37

There seems to be a general consensus that booktabs is the way to go, if you want to have a beautifully typeset table. The result is really elegant, but to some it might appear somewhat... Spartan.

Here are a few examples I gathered from the web:

and last but not least, some contributions from our very own site:

And just for completeness' sake, there is the tabu package. I only list it because I subscribe to the opinion that 'beauty is in the eye of the beholder'. Keep in mind, though, that I neither like the results in the documentation (and the documentation itself is IMHO an eye-sore) nor do I recommend using it - it's been reported to be buggy.

(EDIT: A little pun: Using tabu is taboo. :))


Finally, a little example (from a homework on Fourier series and transformation):

Code

\documentclass{article}
\usepackage{amsfonts}
\usepackage{booktabs}
\usepackage{siunitx}

\begin{document}

\begin{tabular}{SSSSSSSS} \toprule
    {$m$} & {$\Re\{\underline{\mathfrak{X}}(m)\}$} & {$-\Im\{\underline{\mathfrak{X}}(m)\}$} & {$\mathfrak{X}(m)$} & {$\frac{\mathfrak{X}(m)}{23}$} & {$A_m$} & {$\varphi(m)\ /\ ^{\circ}$} & {$\varphi_m\ /\ ^{\circ}$} \\ \midrule
    1  & 16.128 & +8.872 & 16.128 & 1.402 & 1.373 & -146.6 & -137.6 \\
    2  & 3.442  & -2.509 & 3.442  & 0.299 & 0.343 & 133.2  & 152.4  \\
    3  & 1.826  & -0.363 & 1.826  & 0.159 & 0.119 & 168.5  & -161.1 \\
    4  & 0.993  & -0.429 & 0.993  & 0.086 & 0.08  & 25.6   & 90     \\ \midrule
    5  & 1.29   & +0.099 & 1.29   & 0.112 & 0.097 & -175.6 & -114.7 \\
    6  & 0.483  & -0.183 & 0.483  & 0.042 & 0.063 & 22.3   & 122.5  \\
    7  & 0.766  & -0.475 & 0.766  & 0.067 & 0.039 & 141.6  & -122   \\
    8  & 0.624  & +0.365 & 0.624  & 0.054 & 0.04  & -35.7  & 90     \\ \midrule
    9  & 0.641  & -0.466 & 0.641  & 0.056 & 0.045 & 133.3  & -106.3 \\
    10 & 0.45   & +0.421 & 0.45   & 0.039 & 0.034 & -69.4  & 110.9  \\
    11 & 0.598  & -0.597 & 0.598  & 0.052 & 0.025 & 92.3   & -109.3 \\ \bottomrule
\end{tabular}

\end{document}

Output

enter image description here

share|improve this answer
    
I just dug up an example I once did, are you okay with me adding it to your post? –  Tom Bombadil May 4 '13 at 14:00
    
@TomBombadil: Sure! Be my guest! :) –  Count Zero May 4 '13 at 14:18
4  
+1 for the observation that the tabu package documentation is an eyesore. –  Charles Staats May 4 '13 at 14:59
    
@MarcvanDongen It aligns on the decimalpoint. Probably using the columntype S from siunitx. –  Munken May 8 '13 at 8:06
    
@MarcvanDongen It aligns the ones, the tens etc –  Munken May 11 '13 at 20:18

One often-quoted typographer, Robert Bringhurst, says about tables in his book The Elements of Typographic Style, pp. 70–71:

Edit tables with the same attention given to text, and set them as text to be read.

...

  1. All text should be horizontal, or in the rare cases oblique. Setting column heads vertically as a space-saving measure is quite feasible if the text is in Japanese or Chinese, but not if it is written in the Latin alphabet.
  2. Letterforms too small or too condensed for comfortable reading are not part of the solution.
  3. There should be a minimum amount of furniture (rules, boxes, dots and other guiderails for traveling through typographic space) and a maximum amount of information.
  4. Rules, tint blocks or other guides and dividers, where they are necessary at all, should run in the predominant reading direction: vertically in the case of lists, indices and some numerical tables, and horizontally otherwise.
  5. A rule located at the edge of a table, separating the first or final column from the adjacent empty space, ordinarily serves no function.
  6. A table, like any other text in multiple columns, must contain within itself an adequate amount of white space.

On that third point, Edward Tufte has coined the term “data-ink ratio” to mean (reconstructed from The Visual Display of Quantitative Information, p. 93):

enter image description here

Following that, you can usually replace any rules you use in tables with just whitespace. Likewise, when displaying larger amounts of data in a table, instead of “zebra-striping” rows, you can add vertical whitespace (or background color) between groups of rows of, for example, 3 or 5 (provided the rows are evenly divisible) to make it easier to follow the information.

Here's an example set in baselinegrid I've made for a cheatsheet for a game (It's in plain XeTeX-format, so compile with xetex):

\def\mainfont{Myriad Pro}
\font\bodyfont="\mainfont:mapping=tex-text;+onum" at 8bp \let\tenrm\bodyfont
\font\boldfont="\mainfont/B" at 8bp \let\tenbf\boldfont
\bodyfont

\baselineskip=10bp
\smallskipamount=\baselineskip
\medskipamount=2\baselineskip
\setbox\strutbox=\hbox{%
  \vrule height .7\baselineskip depth .3\baselineskip width 0pt}

\newcount\rowcount

\def\headersfor#1{
  \noalign{\global\rowcount=0 \medbreak}
  \bf #1& LVL& LDR& ATT& DEF& INI& SPD& HP& DMG\crcr
  \noalign{\nobreak\smallskip}}

\def\cr{\crcr\noalign{\maybeskip}}

\def\maybeskip{\ifnum\rowcount=2 \global\rowcount=0 \smallbreak
  \else \global\advance\rowcount by 1 \fi}

\halign{#\hfil\strut&& \quad\hfil#\crcr
  \headersfor{Orc}
  Goblin&         2& 35&  16& 10& 4& 2& 20&  2--4\cr
  Furious Goblin& 2& 40&  14& 14& 6& 3& 38&  3--8\cr
  Orc&            3& 60&  16& 17& 4& 2& 65&  7--10\cr
  Catapult&       3& 120& 33& 15& 4& 2& 80&  5--9\cr
  Veteran Orc&    4& 140& 25& 25& 6& 3& 110& 15--20\cr
  Shaman&         4& 200& 24& 32& 5& 3& 160& 15--18\cr
  \headersfor{Neutral}
  Thorn-Hunter&   1& 8&    4&  1& 2& 3& 5&   1--2\cr
  Thorn-Warrior&  1& 8&    4&  3& 4& 3& 8&   1--3\cr
  Fire Dragonfly& 1& 9&    3&  1& 5& 3& 6&   1--3\cr
  Lake Dragonfly& 1& 9&    3&  1& 6& 4& 6&   1--3\cr
  Devilfish&      1& 12&   6&  4& 6& 3& 10&  1--3\cr
  Venomous Spider&1& 12&   5&  1& 4& 3& 10&  2--3\cr
  Cave Spider&    1& 14&   4&  4& 2& 3& 14&  2--4\cr
  Hyena&          2& 20&   8&  8& 4& 3& 14&  3--4\cr
  Pirate&         2& 25&   8&  4& 4& 3& 20&  3--5\cr
  Swamp Snake&    2& 28&  12&  8& 4& 2& 25&  3--5\cr
  Fire Spider&    2& 30&  12& 12& 6& 3& 27&  4--5\cr
  Snake&          2& 30&  14&  8& 5& 2& 28&  3--6\cr
  % ...
}
\bye

enter image description here

share|improve this answer
5  
Looks quite nice and +1 for references to Bringhurst and Tufte. However, I am not sure if I like using grouping instead of 'zebra-striping', as it might read as if those rows grouped together have something in common... and at least for me, it does not separate each row enough. –  Simon Lehmann May 5 '13 at 18:02
    
Thanks @Simon. I think I remember either Bringhurst or Tufte giving that grouping tip, but I couldn't find a reference to that. –  morbusg May 6 '13 at 9:13

Not a beautiful table yet but I would like some help to make it beautiful :) Here is my attempt at recreating OP's table.

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage[margin=1in]{geometry}
\usepackage{tabularx}
\usepackage{enumitem}

\setlist{nolistsep}
\definecolor{green}{HTML}{66FF66}
\definecolor{myGreen}{HTML}{009900}

\renewcommand{\familydefault}{\sfdefault}
\renewcommand{\arraystretch}{1.5}

\begin{document}

\begin{center}
\begin{tabularx}{\textwidth}[t]{XX}
\arrayrulecolor{green}\hline
\textbf{\textcolor{myGreen}{Goal 1 Eradicate Extreme Poverty}} & \\
\hline
Target 1.A Halve, between 1990 and 2015, the proportion of the people whose income is less than \$1 a day. & 
\begin{minipage}[t]{\linewidth}%
\begin{itemize}
\item[1.1] Proportion of population below \$1 purchasing power parity (PPP) a day$^a$
\item[1.2] Poverty Gap ratio [incidence x depth of poverty]
\item[1.3] Share of the poorest quintile in national consumption
\end{itemize} 
\end{minipage}\\

\arrayrulecolor{black}\hline

Target 1.B Achieve full and productive employment and decent work for all, including women and young people &
\begin{minipage}[t]{\linewidth}%
\begin{itemize}
\item[1.4] Growth of GDP per person employed 
\item[1.5] Employment to population ratio
\item[1.6] Proportion of employed people living below \$1 (PP) a day
\item[1.7] Proportion of own-account and contribution family workers in total employment
\end{itemize} 
\end{minipage}\\

\hline

Target 1.C Halve, between 1990 and 2015, the proportion of people who suffer from hunger &
\begin{minipage}[t]{\linewidth}%
\begin{itemize}
\item[1.8] Prevalence of underweight children under five years of age
\item[1.9] Proportion of population below minimum level of dietary energy consumption
\end{itemize}
\end{minipage}\\

\arrayrulecolor{green}\hline
\textbf{\textcolor{myGreen}{Goal 2 Achieve universal primary education}} \\
\hline

Target 2.A Ensure that by 2015 children everywhere, boy and girls alike, will be able to complete a full course of primary schooling. &
\begin{minipage}[t]{\linewidth}%
\begin{itemize}
\item[2.1] Net enrollment ratio in primary education
\item[2.2] Proportion of pupils starting grade 1 who reach last grade of primary education
\item[2.3] Literacy rate of 15- to 24-year-olds, women and men
\end{itemize}
\end{minipage}\\

\hline
\multicolumn{2}{l}{%
\textbf{\textcolor{myGreen}{Goal 3 Promote gender equality and empower women}}} \\
\hline

Target 3.A Eliminate gender disparity in primary and secondary education, preferably by 2005, and in all levels of education no later than 2015 &
\begin{minipage}[t]{\linewidth}%
\begin{itemize}
\item[3.1] Ratios of girls to boys in primary, secondary and tertiary education
\item[3.2] Share of women in wage employment in the non-agricultural sector.
\end{itemize} 
\end{minipage}
\end{tabularx}
\end{center}

\end{document}

enter image description here

share|improve this answer
1  
Can't read the green. –  User 17670 May 4 '13 at 18:56
    
@User17670 I have updated the table. The picture is not high quality but if you compile it yourself, the headers are readable. –  Jeel Shah May 4 '13 at 19:31
    
@gekkostate I made some changes to your code. Hope that's fine. :) –  hpesoj626 May 8 '13 at 2:58
    
@hpesoj626 Even better! Thanks! –  Jeel Shah May 8 '13 at 3:07

There's always the ''obvious'' solution: use TikZ! (Note that I wasn't going for beauty, but for possibility)

Code

\documentclass[parskip]{scrartcl}
\usepackage[margin=15mm]{geometry}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{matrix}

\begin{document}

\pgfdeclarelayer{background}
\pgfsetlayers{background,main}

\begin{tikzpicture}
    \matrix (magic) [matrix of nodes,nodes={minimum width=3cm,minimum height=1cm,draw,very thin},draw,inner sep=0]
    {   |[fill=red!70]|8 & 1 & 6 \\
        3 & |[left color=cyan,right color=orange]| 5 & 7 \\
        4 & 9 & |[text=red,blue]|2 \\
    };
    \draw[thick,violet] (magic-2-1.east) to[out=180,in=270,looseness=0.5] (magic-2-1.north) to[out=270,in=0,looseness=0.5] (magic-2-1.west) to[out=0,in=90,looseness=0.5] (magic-2-1.south) to[out=90,in=180,looseness=0.5] (magic-2-1.east);
    \draw[rounded corners=2pt,densely dashed,green!50!gray] ($(magic-1-2.center)+(-0.15,-0.25)$) rectangle ($(magic-1-3.center)+(0.15,0.25)$);

\end{tikzpicture}

\end{document}

Output

enter image description here

Wasn't there a CW checkbox somewhere? I can't seem to find it.


TikZ tables are particularly useful when you need to include images in the table cells. Here a short example (needs several PNG images to compile):

\documentclass[9pt]{article}
\usepackage{tikz}
\newcommand{\orb}[2][0.15]{
  \node[minimum width=13mm] {
    \includegraphics[scale=#1]{orb-#2.png}
  };
}
\begin{document}
\begin{tikzpicture}
  \matrix[row sep=1mm, column sep=2mm] (orbs) {
  \node {0}; &            &                 & \orb[0.09]{s} \\
  \node {1}; &            & \orb{py}        & \orb[0.12]{pz}  & \orb{px} \\
  \node {2}; & \orb{dxy}  & \orb[0.14]{dyz} & \orb{dz2}       & \orb{dxz} & \orb{dx2-y2} \\
             & \node{-2}; & \node{-1};      & \node{0};       & \node{1}; & \node{2}; \\
  };
  \node[anchor=south, rotate=90, xshift=5mm] at (orbs.west) {angular momentum $\ell$};
  \node[anchor=north] at (orbs.south) {magnetic quantum number $m$};
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
    
I would like to add another short example of a TikZ table. As it is a common wiki, should I just append it to your post or should I post it separately? –  alexurba May 4 '13 at 18:02
    
@alexurba: It's CW, so you're very welcome to add! –  Tom Bombadil May 4 '13 at 21:31
12  
TikZ is becoming like Excel: no matter what the task to be accomplished is, someone will try using it. :) –  Federico Poloni May 5 '13 at 16:25

I really like the showcase of tables contained in Axel Reichert's tabsatz; a tutorial on typesetting tables. The document is in German, but fortunately for those of us who don't read German, the code is understandable for everyone. The .tex document is also available for everyone to see the actual code used.

I will simply copy here two of the examples in the document using mainly just array, booktabs and dcolumn:

\documentclass[a4,portrait,semrot]{seminar}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage[skip=4pt]{caption}
\usepackage{booktabs}
\usepackage{dcolumn}
\usepackage{units}
\usepackage{array}

\pagestyle{empty}
\renewcommand{\printlandscape}{\special{landscape}}
\slideframe{none}
\centerslidesfalse
\slidesmag{3}
\setlength{\slideheight}{183mm}
\setlength{\slidewidth}{264mm}

\makeatletter
\newcommand{\armultirow}[3]{%
  \multicolumn{#1}{#2}{%
    \begin{picture}(0,0)%
      \put(0,0){%
        \begin{tabular}[t]{@{}#2@{}}%
          #3%
        \end{tabular}%
      }%
    \end{picture}%
  }%
}%

\newcolumntype{f}{>{$}l<{$}}
\newcolumntype{n}{l}
\newcolumntype{N}{>{\scriptsize}l}
\newcolumntype{v}[1]{>{\raggedright\hspace{0pt}}p{#1}}
\newcolumntype{V}[1]{>{\scriptsize\raggedright\hspace{0pt}}p{#1}}
%
% array.sty, dcolumn.sty
\newcolumntype{B}[1]{>{\boldmath\DC@{.}{,}{#1}}l<{\DC@end}}
\newcolumntype{d}[1]{>{\DC@{.}{,}{#1}}l<{\DC@end}}
\newcolumntype{i}[1]{>{\DC@{.}{,}{#1}\mathnormal\bgroup}l<{\egroup\DC@end}}
\newcolumntype{s}[1]{>{\DC@{.}{,}{#1}\mathsf\bgroup}l<{\egroup\DC@end}}
%
% array.sty, rotating.sty
\newcolumntype{R}[1]{%
  >{\begin{turn}{90}\begin{minipage}{#1}\scriptsize\raggedright\hspace{0pt}}l%
  <{\end{minipage}\end{turn}}%
}
%
% array.sty, tabularx.sty
\newcolumntype{x}{>{\scriptsize\raggedright\hspace{0pt}}X}
\makeatother
\begin{document}

\begin{slide*}
  \begin{table}
    \centering
    \caption{Minuskelziffern}
    \label{tab:minuskelziffern}
    \begin{tabular}{@{}v{7em}i{4.0}i{3.0}i{5.0}n@{}}
      \toprule
        &
        \multicolumn{4}{N@{}}{Diese also Sachen} \\
      \cmidrule(l){2-5}
        &
        \multicolumn{1}{V{5.5em}}{Blick linken sonst endlich} &
        \multicolumn{1}{V{5.5em}}{auf nicht weit Soll des} &
        \multicolumn{1}{V{5em}}{gleich man kann ist} &
        \multicolumn{1}{V{5em}@{}}{weil Sache zu einem} \\
        &
        &
        \multicolumn{1}{N}{\unit{\%}} \\
      \cmidrule(r){1-1}\cmidrule(lr){2-2}\cmidrule(lr){3-3}\cmidrule(lr){4-4}%
        \cmidrule(l){5-5}
        \armultirow{1}{@{}v{7em}}{Um hier sonst damit Platz ist gegeben} &
          1991 & 20 & 45637 & \oldstylenums{657} unter  \\
        & 1992 & 47 & 47916 & \oldstylenums{645} linken \\
        & 1993 & 65 & 22848 & \oldstylenums{347} nein   \\
      \addlinespace
        \armultirow{1}{@{}v{7em}}{Durch gehört wollen und} &
          1994 &  87 & 46475 & \oldstylenums{957} einem  \\
        & 1995 &  95 & 94356 & \oldstylenums{8363} Sache \\
        & 1996 & 100 & 84646 & \oldstylenums{93635} nein \\
      \cmidrule(r){1-1}\cmidrule(lr){2-2}\cmidrule(lr){3-3}\cmidrule(lr){4-4}%
        \cmidrule(l){5-5}
        &
        \multicolumn{4}{N@{}}{Gerade langt hinauf sonst nicht gleich
          man} \\
      \cmidrule(r){1-1}\cmidrule(l){2-5}
        \armultirow{1}{@{}v{7em}}{Um hier damit Platz hat} &
          1796 &   4 & 46032 & \oldstylenums{56} scheidet \\
        & 1896 &  25 & 38937 & \oldstylenums{746} linken  \\
        & 1996 & 100 & 83458 & \oldstylenums{48746} eine  \\
      \bottomrule
    \end{tabular}
  \end{table}
\end{slide*}

\begin{slide*}
  \begin{table}
    \centering
    \footnotesize
    \caption{Kathodenfallableiter}
    \label{tab:kathoden}
    \begin{tabular}{@{}nd{1.1}*{3}{d{1.2}}d{1.1}d{3.2}@{}}
      \toprule
        \multicolumn{1}{@{}N}{Typenbezeichnung} &
        \multicolumn{5}{N}{Spannungsschutz für Netze} &
        \multicolumn{1}{N@{}}{Preis} \\
        &
        \multicolumn{5}{N}{Leiterspannung an der Einbaustelle} \\
      \cmidrule(lr){2-6}
        &
        \multicolumn{2}{V{6.5em}}{Nicht geerdeter Sternpunkt} &
        \multicolumn{2}{V{6.5em}}{Starr geerdeter Sternpunkt} &
        \multicolumn{1}{V{4em}}{Nenn"-spannung} \\
      \cmidrule(lr){2-3}\cmidrule(lr){4-5}
        &
        \multicolumn{1}{V{4.5em}}{Normale Leiterspannung} &
        \multicolumn{1}{V{4.5em}}{Zulässiger Bereich} &
        \multicolumn{1}{V{4.5em}}{Normale Leiterspannung} &
        \multicolumn{1}{V{4.5em}}{Zulässiger Bereich} \\
        &
        \multicolumn{1}{N}{\unit{kV}} &
        \multicolumn{1}{N}{\unit{kV}} &
        \multicolumn{1}{N}{\unit{kV}} &
        \multicolumn{1}{N}{\unit{kV}} &
        \multicolumn{1}{N}{\unit{kV}} &
        \multicolumn{1}{N}{DM} \\
      \cmidrule(r){1-1}\cmidrule(lr){2-2}\cmidrule(lr){3-3}\cmidrule(lr){4-4}%
        \cmidrule(lr){5-5}\cmidrule(lr){6-6}\cmidrule(l){7-7}
        H 484--1   & 1   & 1.15 & 1.25 & 1.45 & 1   & 220.$---$ \\
        H 484--1,5 & 1.5 & 1.8  & 1.9  & 2.2  & 1.5 & 233.$---$ \\
        H 484--2   & 2   & 2.3  & 2.5  & 2.9  & 2   & 252.$---$ \\
        H 484--2,5 & 3   & 2.9  & 3.1  & 3.6  & 2.5 & 261.$---$ \\
        H 484--3   & 3.5 & 3.5  & 3.8  & 4.3  & 3   & 264.$---$ \\
      \bottomrule
    \end{tabular}
  \end{table}
\end{slide*}

\end{document}

enter image description here

enter image description here

share|improve this answer
7  
As one of those who read german: what is table 1? Some kind of Dada poem? –  Tom Bombadil May 5 '13 at 8:42
    
@TomBombadil Maybe a variation on Lorem Ipsum –  Felix Dombek May 5 '13 at 15:33
    
@TomBombadil I am not one of those who read German. No idea what table 1 is about; it looks nice, though. –  Gonzalo Medina May 5 '13 at 19:54
3  
I usually do read German (it is my mother tongue at least ;) ), but I can't make any sense of it -- Dada poem seems to capture it quite nicely ;). I have to agree that it looks nice, though. –  rainer May 6 '13 at 14:16
    
About the second table, Kathodenfallableiter. It's... interesting. I like it as well, except for the left alignments. Be honest, do you find it functional? I mean the numbers made it work, thus it would break with any other numbers unless you change the unit dimensions in the column headings. On second thought, I kind of believe it's not that much of a good example. It "just" looks nice at first. –  henry Apr 4 at 18:22

An interesting and simple gallery is presented at Wikibooks - LaTeX/Tables

BTW, my contribution is:

\documentclass{beamer}
\usepackage{booktabs}

\begin{document}

\frame{
\frametitle{Simple Table}

\begin{center} 

\begin{tabular}{cccc}
\toprule
  Dec        & Bin               & Octal         & Hexa \\
\midrule  
    33       &  \alert{100001}   &  \alert{41}   &  \alert{21} \\
\midrule
\alert{117}  & 1110101           & \alert{165}   & \alert{75} \\
\midrule
\alert{451}  & \alert{111000011} &   703         & \alert{1C3} \\
\midrule
\alert{431}  & \alert{110101111} & \alert{657}   &   1AF \\
\bottomrule
\end{tabular}

\end{center}

}

\end{document}

Result:

enter image description here

share|improve this answer
24  
Er... Most of the examples there look really awful :-( –  Stephan Lehmke May 4 '13 at 12:06
13  
For me it looks like a gallery of what is possible - NOT a gallery of what is beautiful. –  Hans-Peter E. Kristiansen May 4 '13 at 12:30
5  
No vertical lines + booktabs is the way to go :) –  Jubobs May 4 '13 at 12:55

I spend today much time to layout a table and I am pleased with the result. As some other answers I also use mainly the booktabs package and added some color. The main point is that I use pgfplotstable for typeset the table. Wich makes it very easy to reuse the defined style or to change the style later without touching the actual table. The table itself is that by this lines:

\pgfplotstabletypeset[normal,
    columns/eg/.style={
        column name={$E_{\textup{g}}$ (\si{\electronvolt})},
        dec sep align
    }
]{ %
    Material        & Symbol &  eg  & Type \\
    \topmidheader{5}{Elements}
    diamond         & C      & 5.46 & i \\
    ...
    \midheader{5}{IV-IV Compounds}
    silicon carbide & SiC 3C & 2.36 & i \\
    ...
    aluminium nitride & AlN  & 6.2  & d \\
}

Most of the styling is done by the style normal I defined before. The first line gives the header and the commands \topmidheader and \midheader define subheadings. The first argument (here 5) is the column count, note, that pgfplotstable adds an extra column for each numerical column. The column style eg is there for two reasons (1) it is not possible to have math and other complex stuff inside of a header cell and (2) we define that the numbers are align to the decimal point.

And here comes the full code:

\documentclass{article}

\usepackage{unicode-math}
\setmainfont[Mapping=tex-text, Numbers=OldStyle]{TeX Gyre Pagella}
\setmathfont[math-style=ISO]{TeX Gyre Pagella Math}

\usepackage{siunitx}
\usepackage{xcolor}
\usepackage{booktabs,colortbl, array}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.8}

\definecolor{rulecolor}{RGB}{0,71,171}
\definecolor{tableheadcolor}{gray}{0.92}
% Following is taken from Werner: http://tex.stackexchange.com/a/33761/3061
% and modified for my needs
%
% Command \topline consists of a (slightly modified)
% \toprule followed by a \heavyrule rule of colour tableheadcolor
% (hence, 2 separate rules)
\newcommand{\topline}{ %
        \arrayrulecolor{rulecolor}\specialrule{0.1em}{\abovetopsep}{0pt}%
        \arrayrulecolor{tableheadcolor}\specialrule{\belowrulesep}{0pt}{0pt}%
        \arrayrulecolor{rulecolor}}
% Command \midline consists of 3 rules (top colour tableheadcolor, middle colour black, bottom colour white)
\newcommand{\midtopline}{ %
        \arrayrulecolor{tableheadcolor}\specialrule{\aboverulesep}{0pt}{0pt}%
        \arrayrulecolor{rulecolor}\specialrule{\lightrulewidth}{0pt}{0pt}%
        \arrayrulecolor{white}\specialrule{\belowrulesep}{0pt}{0pt}%
        \arrayrulecolor{rulecolor}}
% Command \bottomline consists of 2 rules (top colour
\newcommand{\bottomline}{ %
        \arrayrulecolor{white}\specialrule{\aboverulesep}{0pt}{0pt}%
        \arrayrulecolor{rulecolor} %
        \specialrule{\heavyrulewidth}{0pt}{\belowbottomsep}}%


\newcommand{\midheader}[2]{%
        \midrule\topmidheader{#1}{#2}}
\newcommand\topmidheader[2]{\multicolumn{#1}{c}{\textsc{#2}}\\%
                \addlinespace[0.5ex]}

\pgfplotstableset{normal/.style ={%
        header=true,
        string type,
        font=\addfontfeature{Numbers={Monospaced}}\small,
        column type=l,
        every odd row/.style={
            before row=
        },
        every head row/.style={
            before row={\topline\rowcolor{tableheadcolor}},
            after row={\midtopline}
        },
        every last row/.style={
            after row=\bottomline
        },
        col sep=&,
        row sep=\\
    }
}

\begin{document}
    \begin{table}
        \centering
        \caption{The bandgab of some semiconductors.}
        \pgfplotstabletypeset[normal,
                columns/eg/.style={
                column name={$E_{\textup{g}}$ (\si{\electronvolt})},
                dec sep align
        }
        ]{ %
        Material        & Symbol &  eg  & Type \\
        \topmidheader{5}{Elements}
        diamond         & C      & 5.46 & i \\
        silicon         & Si     & 1.12 & i \\
        germanium       & Ge     & 0.67 & i \\
        selenium        & Se     & 1.74 & d \\
        \midheader{5}{IV-IV Compounds}
        silicon carbide & SiC 3C & 2.36 & i \\
        silicon carbide & SiC 4H & 3.28 & i \\
        silicon carbide & SiC 6H & 3.03 & i \\
        \midheader{5}{III-V Compounds}
        indium phosphide& InP    & 1.27 & d \\
        indium arsenide & InAs   & 0.355& d \\
        gallium nitride & GaN    & 3.37 & d \\
        gallium arsenide& GaAs   & 1.42 & d \\
        aluminium nitride & AlN  & 6.2  & d \\
        }
\end{table}
\end{document}

enter image description here

The values are token from wikipedia.

share|improve this answer
    
Love this one, thanks! But I don't see how you would, let's say, align only the third column to the right e.g. –  anderstood Aug 8 at 3:15

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.