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.

Both the Booktabs documentation and the Small Guide to Making Nice Tables provide some nice rules-of-thumb for making professional-looking tables (e.g., no double rules, no vertical rules, etc.)

Q: What are the "rules" about alternating row-coloring?

The former discusses the functionality for alternating row-coloring. The latter provides some example tables from The Economist which show some row-coloring. Neither say when it is/isn't a good idea though.

Personally, I think alternating row-coloring is nice. It's easier to find things (especially when tables are wide). But I'd rather not do it if it's considered bad practice.

I created the table below which I think looks pretty good (sans weird vertical alignment in the math, which is the subject of my question Vertical spacing in tables with math). But I'm open to criticism.

mytable

share|improve this question
    
I think every typographical rule needs a personal touch. In my opinion the combination of booktabs and alternating row colors looks good. –  Marco Daniel Nov 5 '11 at 17:17
add comment

3 Answers 3

up vote 30 down vote accepted

Zebra stripes – as they’re called – may sometimes be better than nothing, but it’s still bad table design. See this discussion on Edward Tufte’s Web forum, which references a chapter in his book Envisioning Information (which doesn’t actually have any dicussion on zebra stripes in tables, but is still a wonderful book).

The problem zebra stripes tries to solve is that cell contents of neighbouring columns are too far apart, making it difficult to follow the content along rows. Here’s my list of suggestions for improving a table where you think you need zebra stripes, roughly in order.

  1. Abbreviate the column headers. Often the content cells contain little information, e.g., a two-digit number, but the wide column header cells make the column much too wide.
  2. If you can’t abbreviate the column header, split it into two (or more) rows.
  3. Slightly rotate the column headers, perhaps 20 degrees, so they don’t take up much horizontal space. How to do this is LaTeX is a separate question. :)
  4. Sometimes you can actually just get rid of the entire header row, as the meaning of each column is obvious.
  5. Add extra space between rows, so that the rows actually feel like separate rows. You usually don’t need much extra space.
  6. Add small, vertically centred horizontal leader dots between or inside the cells. This is especially useful if some of the cells are empty. How to best do this in LaTeX is of course also a separate question.
  7. A combination of some or all of the above.

If, and only if, the above doesn’t help, i.e., you need long column headings, with narrow or empty content cells, large intercolumn space, and you need to conserve vertical space, then you may consider using zebra stripes, knowing that it’s still bad table design. Luckily, there are actually a few tricks you can use to reduce the damage:

  1. Use spans of rows with the same colour, which look much better than simply alternating zebra stripes. For example, colour rows 1–3 light blue, rows 4–6 white, rows 6–9 light blue, rows 10–12 white, etc. This greatly reduces the problem of seemingly flickering rows. When using three rows, it’s easy to recognise the first, middle and last row in each ‘group’, and much harder to ‘get lost’ (i.e., read the wrong row when moving between columns) than when using simply alternating row colours. Groups of five also work well.
  2. Note that the important thing here is grouping of rows into three or five rows. And you don’t actually need colours for that! Just separate the groups with some vertical whitespace or a very faint or dotted lightly coloured horizontal line.
  3. Make the two background colours very light or similar. The blue one used in your example is too dark, IMHO. But when lightening the colour, do print the document to make sure the light blue colour is still visibly different from white, as many printers aren’t very good at printing very light colours.

The largest problem with the grouping above is that you visually imply a logical grouping that just doesn’t exist. That’s one good reason to avoid zebra stripes. And, as shown earlier in my answer, they aren’t even necessary, so do avoid them if you appreciate good table design.

share|improve this answer
    
+1 for colouring spans of rows. Looks much better. –  Jukka Suomela Nov 6 '11 at 11:19
1  
Lots of food for thought. I appreciate the answer. I'm a little surprised that coloring by group is considered "the solution" by Tufte. When I see coloring by group it makes me think that there is some defining characteristic shared by the colored group. I think I prefer a dotted horizontal rule every 3-5 rows shown in an example from one of your links. –  lowndrul Nov 12 '11 at 19:14
1  
@brianjd Tufte does not condone zebra stripes at all. As he says on the forum post I referenced, ‘Strips are merely bureaucratic or designer chartjunk; good typography can always organize a table, no stripes needed.’ Sorry if I were unclear in my answer, perhaps giving the impression that (some types of) zebra stripes are a good idea. I have now edited it, adding some more information, along with several suggestions for avoiding zebra stripes. –  Karl Ove Hufthammer Nov 15 '11 at 17:04
2  
As a dyslectic I must say I disagree strongly. Especially in science (this is Tex after all) there is plenty of tables where zebra stripes are a fantastically strong tool to prevent straying from rows. Remember there's people out that that can't read without a ruler, because they lose track of which line they're on. Getting your fancy on is always nice, but clarity is king. –  Lodewijk Oct 3 '12 at 7:51
    
I wouldn't go so far as to say poor design, it depends on the choice of colours / shading, a very very subtle zebra line (say white and white!98!black) is good in my opinion. –  Nicholas Hamilton May 16 '13 at 0:48
add comment

I would agree that row colour is a great addition to tables, since it is much more subtle than horizontal rules. And by subtle I refer to the use of a colour that is not too bold - using a shade of black or grey is best since it has dual purpose in colour (on-screen) and black-and-white environments (printing).

When alternately colouring rows of a table and using a heading colour (perhaps darker), start colouring the second row of the table body rather than the first:

enter image description here

Perhaps, playing devil's advocate, here is an example of where row colours may cause problems. The concern is consistency and aesthetics:

enter image description here

For example, do you colour rows only from column 2-4? Or do you colour each "Approach" group (in this case it trivially defaults to only colouring rows 3-4 in the table body)? Or do you colour the first column with the same row colour and keep the row colours as-is?

\documentclass{article}
\usepackage{booktabs}% http://ctan.org/pkg/booktabs
\usepackage{colortbl}% http://ctan.org/pkg/colortbl
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\usepackage{xcolor}% http://ctan.org/pkg/xcolor
\usepackage{graphicx}% http://ctan.org/pkg/graphicx

\colorlet{tableheadcolor}{gray!25} % Table header colour = 25% gray
\newcommand{\headcol}{\rowcolor{tableheadcolor}} %
\colorlet{tablerowcolor}{gray!10} % Table row separator colour = 10% gray
\newcommand{\rowcol}{\rowcolor{tablerowcolor}} %
    % Command \topline consists of a (slightly modified) \toprule followed by a \heavyrule rule of colour tableheadcolor (hence, 2 separate rules)
\newcommand{\topline}{\arrayrulecolor{black}\specialrule{0.1em}{\abovetopsep}{0pt}%
            \arrayrulecolor{tableheadcolor}\specialrule{\belowrulesep}{0pt}{0pt}%
            \arrayrulecolor{black}}
    % Command \midline consists of 3 rules (top colour tableheadcolor, middle colour black, bottom colour white)
\newcommand{\midline}{\arrayrulecolor{tableheadcolor}\specialrule{\aboverulesep}{0pt}{0pt}%
            \arrayrulecolor{black}\specialrule{\lightrulewidth}{0pt}{0pt}%
            \arrayrulecolor{white}\specialrule{\belowrulesep}{0pt}{0pt}%
            \arrayrulecolor{black}}
    % Command \rowmidlinecw consists of 3 rules (top colour tablerowcolor, middle colour black, bottom colour white)
\newcommand{\rowmidlinecw}{\arrayrulecolor{tablerowcolor}\specialrule{\aboverulesep}{0pt}{0pt}%
            \arrayrulecolor{black}\specialrule{\lightrulewidth}{0pt}{0pt}%
            \arrayrulecolor{white}\specialrule{\belowrulesep}{0pt}{0pt}%
            \arrayrulecolor{black}}
    % Command \rowmidlinewc consists of 3 rules (top colour white, middle colour black, bottom colour tablerowcolor)
\newcommand{\rowmidlinewc}{\arrayrulecolor{white}\specialrule{\aboverulesep}{0pt}{0pt}%
            \arrayrulecolor{black}\specialrule{\lightrulewidth}{0pt}{0pt}%
            \arrayrulecolor{tablerowcolor}\specialrule{\belowrulesep}{0pt}{0pt}%
            \arrayrulecolor{black}}
    % Command \rowmidlinew consists of 1 white rule
\newcommand{\rowmidlinew}{\arrayrulecolor{white}\specialrule{\aboverulesep}{0pt}{0pt}%
            \arrayrulecolor{black}}
    % Command \rowmidlinec consists of 1 tablerowcolor rule
\newcommand{\rowmidlinec}{\arrayrulecolor{tablerowcolor}\specialrule{\aboverulesep}{0pt}{0pt}%
            \arrayrulecolor{black}}
    % Command \bottomline consists of 2 rules (top colour
\newcommand{\bottomline}{\arrayrulecolor{white}\specialrule{\aboverulesep}{0pt}{0pt}%
            \arrayrulecolor{black}\specialrule{\heavyrulewidth}{0pt}{\belowbottomsep}}%
\newcommand{\bottomlinec}{\arrayrulecolor{tablerowcolor}\specialrule{\aboverulesep}{0pt}{0pt}%
            \arrayrulecolor{black}\specialrule{\heavyrulewidth}{0pt}{\belowbottomsep}}%

\begin{document}

\renewcommand{\arraystretch}{1.5}
\begin{tabular}{llll}
  \topline
  \headcol Approach & Estimator & ME & MAE \\
  \midline
  & $\widehat{JV}_{\text{na\"ive}}$ & 4.37e-07 & 4.37e-07 \\
  \rowcol \smash{\raisebox{1em}{Na\"ive}} & $\widetilde{JV}_{\text{na\"ive}}$ & 3.88e-07 & 3.88e-07 \\
  & $\widehat{JV}$ & 1.33e-06 & 1.33e-06 \\
   \rowcol \smash{\raisebox{1em}{Regular}} & $\widetilde{JV}$ & 1.20e-06 & 1.20e-06 \\
  \bottomlinec
\end{tabular}

\end{document}

The above code includes a number of additional line definitions based on \specialrule from booktabs. It allows for specifying a colour for the table header (tableheadcolor) and table body row (tablerowcolor), depending on whether your row is coloured or not and/or ending/beginning with a coloured row or not.

As similar, perhaps less manual approach, is obtainable using tabu or tikz/pgf for that matter.

share|improve this answer
    
I used your coloring suggestion (although, for a presentation, I prefer colors related to the colortheme instead of grays). Combining your advice with @Karl Ove Hufthammer above, coloring the GROUPS would be the best choice. Thank you! –  lowndrul Nov 6 '11 at 0:38
    
is there a way to obtain the same but with an alternative to \cmidrule? –  Rave May 29 '12 at 20:05
    
@Rave: Are you perhaps referring to the following usage/correction: How do I eliminate the vertical realignment when using \arrayrulecolor with \cmidrule? –  Werner May 29 '12 at 20:12
    
Yes with little modifications... Thx a lot. –  Rave May 29 '12 at 22:56
add comment

IMHO it improves readability a lot if you add alternating colors to tables. Of course the choice of colors matters a lot, you will probably choose soft tones, which leave the text readable and blend well into the general 'color scheme' of the document.

I'd like to quote here from the TikZ/PGF manual (the quote actually is taken from somewhere else :) ):

The only mistakes in typography are things done is ignorance.

share|improve this answer
11  
Perhaps more of a comment than an answer. –  Joseph Wright Nov 15 '11 at 17:06
add comment

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.