14

I have a table that is quite dense:

enter image description here

Any ideas how could make this easier to read, specifically in terms of distinguishing between different rows and columns? Was thinking Excel-style cell shading but not sure if this is possible let alone a good idea in LaTeX.

The code to generate the table is given below.

\begin{table}[htbp]
\caption{Proportion of trips (T), distance (D) and energy (E)
used by the three most
popular forms of transport in Yorkshire and the Humber.}
\begin{tabular}{lrrr|rrr|rrr|rrr}
\toprule
Dis. & \multicolumn{ 3}{c}{Car*} & \multicolumn{ 3}{c}{Walk} & \multicolumn{ 3}{c}{Bus} & \multicolumn{ 3}{c}{All modes} \\ 
(km) & \multicolumn{1}{l}{T} & \multicolumn{1}{l}{D} & \multicolumn{1}{l}{E} & \multicolumn{1}{l}{T} & \multicolumn{1}{l}{D} & \multicolumn{1}{l}{E} & \multicolumn{1}{l}{T} &
\multicolumn{1}{l}{D} & \multicolumn{1}{l}{E} & \multicolumn{1}{l}{T} & \multicolumn{1}{l}{D} & \multicolumn{1}{l}{E} \\ 
\midrule
0-2 & 1.2 & 0.1 & 0.2 & 3.5 & 0.4 & 0.0 & 0.2 & 0.0 & 0.0 & 16.8 & 0.6 & 0.2 \\
2-5 & 12.8 & 3.8 & 4.9 & 5.9 & 1.4 & 0.1 & 4.8 & 1.5 & 0.5 & 28.3 & 8.1 & 5.6 \\
5-10 & 15.5 & 10.4 & 13.4 & 0.4 & 0.3 & 0.0 & 3.8 & 2.5 & 0.9 & 23.4 & 15.7 & 14.6 \\
10-20 & 14.0 & 17.3 & 22.2 & 0.7 & 0.8 & 0.0 & 0.9 & 1.1 & 0.4 & 17.7 & 21.7 & 23.0 \\
20-50 & 7.9 & 21.1 & 27.0 & 0.0 & 0.0 & 0.0 & 0.3 & 0.8 & 0.3 & 10.0 & 26.5 & 27.7 \\
50+ & 3.0 & 22.3 & 28.6 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 3.8 & 27.5 & 28.8 \\
All & 54.6 & 75.0 & 96.4 & 10.6 & 2.9 & 0.2 & 10.1 & 5.9 & 2.1 & 100 & 100 & 100 \\
\bottomrule
\end{tabular}
\label{t:props}

{\footnotesize *Excludes car passengers}
\end{table}
  • I would vertically add more space between the rows with \renewcommand\arraystretch{} using a value greate than 1 as the argument. – Steven B. Segletes Oct 28 '13 at 9:54
  • 1
    I would also replace the vertical lines every three columns with a small gap, instead. – Steven B. Segletes Oct 28 '13 at 9:59
  • 2
    The purpose of the table is to report the data yes, but the point I'm trying to make - cars dominate more when distance and energy measures are used - could be lost in the "sea of numbers". In fact, the reviewer who is asking for the table to be changed said the following: "Table 3 could be made a bit more clear in terms of presentation. Visually it needs some sort of breaks to make it a bit easier to follow the rows and columns. As it stands it appears as a jumble of numbers and is tough on this academic's computer abused eyes." – RobinLovelace Oct 28 '13 at 10:02
  • 2
    You could divide it into three tables: one for time, one for distance and one for energy. – Andrew Swann Oct 28 '13 at 10:17
  • 5
    A minor typographic point: an en-dash, not a hyphen, should be used for ranges of numbers, so 0--2 rather than 0-2. – Torbjørn T. Oct 28 '13 at 10:37
13

I would also get rid of the vertical rules, but add some \cmidrules to clarify the structure of the table's header. Next, I'd use the S column type of the siunitx package to make sure the numbers are all aligned on their respective decimal markers. Separately, I would use the tabular* environment instead of the tabular environment to make the table as wide as the text block. Finally, I'd use double instead of single dashes in the first column to generate typographically correct en-dashes.

enter image description here

\documentclass{article}
\usepackage{booktabs,siunitx}
\usepackage[margin=1in,a4paper]{geometry} % set margins and paper size as appropriate for your document
\newcommand{\mcc}[1]{\multicolumn{1}{c}{#1}} % short for multicolumn-centered
\begin{document}
\begin{table}
\caption{Proportion of trips (T), distance (D) and energy (E) used by the three most
popular forms of transport in Yorkshire and the Humber.} \label{t:props}

\smallskip
\begin{tabular*}{\textwidth}{@{} l @{\extracolsep{\fill}} 
     *{9}{S[table-format=2.1]}   *{3}{S[table-format=3.1]} @{}}
\toprule
Distance & \multicolumn{3}{c}{Car*} & \multicolumn{3}{c}{Walk} 
         & \multicolumn{3}{c}{Bus}  & \multicolumn{3}{c@{}}{All modes} \\
\cmidrule(lr){2-4} \cmidrule(lr){5-7} \cmidrule(lr){8-10} \cmidrule(l){11-13} 
(km) & \mcc{T} & \mcc{D} & \mcc{E} & \mcc{T} & \mcc{D} & \mcc{E} & 
       \mcc{T} & \mcc{D} & \mcc{E} & \mcc{T} & \mcc{D} & \mcc{E} \\
\midrule
0--2   &  1.2 &  0.1 &  0.2 &  3.5 & 0.4 & 0.0 &  0.2 & 0.0 & 0.0 & 16.8 &  0.6 &  0.2 \\
2--5   & 12.8 &  3.8 &  4.9 &  5.9 & 1.4 & 0.1 &  4.8 & 1.5 & 0.5 & 28.3 &  8.1 &  5.6 \\
5--10  & 15.5 & 10.4 & 13.4 &  0.4 & 0.3 & 0.0 &  3.8 & 2.5 & 0.9 & 23.4 & 15.7 & 14.6 \\
10--20 & 14.0 & 17.3 & 22.2 &  0.7 & 0.8 & 0.0 &  0.9 & 1.1 & 0.4 & 17.7 & 21.7 & 23.0 \\
20--50 &  7.9 & 21.1 & 27.0 &  0.0 & 0.0 & 0.0 &  0.3 & 0.8 & 0.3 & 10.0 & 26.5 & 27.7 \\
50+    &  3.0 & 22.3 & 28.6 &  0.0 & 0.0 & 0.0 &  0.0 & 0.0 & 0.0 &  3.8 & 27.5 & 28.8 \\
All    & 54.6 & 75.0 & 96.4 & 10.6 & 2.9 & 0.2 & 10.1 & 5.9 & 2.1 &  100 &  100 &  100 \\ 
\bottomrule
\end{tabular*}
{\footnotesize *Excludes car passengers}
\end{table}
\end{document}
  • I, too, prefer the use of the S-column type from siunitx (and the use of booktabs). – Svend Tveskæg Oct 29 '13 at 3:47
9

Here's another approach, which is to use a 'heatmap', letting pgfplotstable do the beautification - the clever parts of this code come from Christian Feuersänger's answer to Drawing heatmaps using TikZ

screenshot

Unfortunately I wasn't able to combine this idea with decimal alignment- perhaps a guru will be able to help with this.

% arara: pdflatex
% !arara: indent: {overwrite: yes, trace: on}
\documentclass{article}
\usepackage{geometry}
\usepackage{colortbl}
\usepackage{pgfplotstable}
\usepackage{booktabs}

\pgfplotstableset{
    /color cells/min/.initial=0,
    /color cells/max/.initial=1000,
    /color cells/textcolor/.initial=,
    %
    % Usage: 'color cells={min=<value which is mapped to lowest color>, 
    %   max = <value which is mapped to largest>}
    color cells/.code={%
        \pgfqkeys{/color cells}{#1}%
        \pgfkeysalso{%
            postproc cell content/.code={%
                %
                \begingroup
                %
                % acquire the value before any number printer changed
                % it:
                \pgfkeysgetvalue{/pgfplots/table/@preprocessed cell content}\value
                \ifx\value\empty
                \endgroup
                \else
                \pgfmathfloatparsenumber{\value}%
                \pgfmathfloattofixed{\pgfmathresult}%
                \let\value=\pgfmathresult
                %
                % map that value:
                \pgfplotscolormapaccess
                [\pgfkeysvalueof{/color cells/min}:\pgfkeysvalueof{/color cells/max}]
                {\value}
                {\pgfkeysvalueof{/pgfplots/colormap name}}%
                % now, \pgfmathresult contains {<R>,<G>,<B>}
                % 
                % acquire the value AFTER any preprocessor or
                % typesetter (like number printer) worked on it:
                \pgfkeysgetvalue{/pgfplots/table/@cell content}\typesetvalue
                \pgfkeysgetvalue{/color cells/textcolor}\textcolorvalue
                %
                % tex-expansion control
                % see https://tex.stackexchange.com/questions/12668/where-do-i-start-latex-programming/27589#27589
                \toks0=\expandafter{\typesetvalue}%
                \xdef\temp{%
                    \noexpand\pgfkeysalso{%
                        @cell content={%
                            \noexpand\cellcolor[rgb]{\pgfmathresult}%
                            \noexpand\definecolor{mapped color}{rgb}{\pgfmathresult}%
                            \ifx\textcolorvalue\empty
                            \else
                            \noexpand\color{\textcolorvalue}%
                            \fi
                            \the\toks0 %
                        }%
                    }%
                }%
                \endgroup
                \temp
                \fi
            }%
        }%
    }
}

\begin{document}

\pgfplotstabletypeset[
    every head row/.style={before row={\toprule
        Distance & \multicolumn{3}{c}{Car} & \multicolumn{3}{c}{Bus}&\multicolumn{3}{c}{Walk}& \multicolumn{3}{c}{Total}\\} ,after row=\midrule},
        columns/interval/.style={string type,column name=(km),column type={l}},
        columns/carT/.style={color cells={min=0,max=28.6},column name=T, },
        columns/carD/.style={color cells={min=0,max=28.6},column name=D, },
        columns/carR/.style={color cells={min=0,max=28.6},column name=R},
        columns/busT/.style={color cells={min=0,max=28.6},column name=T, },
        columns/busD/.style={color cells={min=0,max=28.6},column name=D, },
        columns/busR/.style={color cells={min=0,max=28.6},column name=R},
        columns/walkT/.style={color cells={min=0,max=28.6},column name=T, },
        columns/walkD/.style={color cells={min=0,max=28.6},column name=D, },
        columns/walkR/.style={color cells={min=0,max=28.6},column name=R},
        columns/totalT/.style={color cells={min=0,max=28.6},column name=T, },
        columns/totalD/.style={color cells={min=0,max=28.6},column name=D, },
        columns/totalR/.style={color cells={min=0,max=28.6},column name=R},
        col sep=&,
        row sep=\\,
        every last row/.style={after row=\bottomrule},
        /pgfplots/colormap={whiteblue}{rgb255(0cm)=(255,255,255); rgb255(1cm)=(0,0,188)},
    ]
    {
        interval & carT  & carD& carR &  busT  & busD    & busR&  walkT & walkD  & walkR & totalT & totalD & totalR \\ 
        {0--2}   &  1.2 &  0.1 &  0.2 &  3.5   & 0.4     & 0.0 &  0.2   & 0.0    & 0.0   & 16.8 &  0.6 &  0.2  \\ 
        {2--5}   & 12.8 &  3.8 &  4.9 &  5.9   & 1.4     & 0.1 &  4.8   & 1.5    & 0.5   & 28.3 &  8.1 &  5.6  \\ 
        {5--10}  & 15.5 & 10.4 & 13.4 &  0.4   & 0.3     & 0.0 &  3.8   & 2.5    & 0.9   & 23.4 & 15.7 & 14.6  \\ 
        {10--20} & 14.0 & 17.3 & 22.2 &  0.7   & 0.8     & 0.0 &  0.9   & 1.1    & 0.4   & 17.7 & 21.7 & 23.0  \\ 
        {20--50} &  7.9 & 21.1 & 27.0 &  0.0   & 0.0     & 0.0 &  0.3   & 0.8    & 0.3   & 10.0 & 26.5 & 27.7  \\ 
        {50+}    &  3.0 & 22.3 & 28.6 &  0.0   & 0.0     & 0.0 &  0.0   & 0.0    & 0.0   &  3.8 & 27.5 & 28.8  \\ 
    }

\end{document}
  • Very neat solution - great to know that's possible. Will add an edit at some point showing the solution that I finally used, not all of which was LaTeX based. Cheers. – RobinLovelace Oct 30 '13 at 9:31
9

As I suggested in my comments, I would add vertical gap in between the lines and replace the vertical lines with gaps. You didn't specify what \documentclass you were using, so I didn't know how much margin you had to work with, so I show two versions below. The first fits within the default article column width (which is quite narrow to my estimation), and shown with the \dotfill. The second is slightly wider, showing how the appearance can be enhanced, if you have more width with which to work.

\documentclass{article}
\usepackage{booktabs}
\renewcommand\arraystretch{1.2}
\begin{document}

\begin{table}[htbp]
\caption{Proportion of trips (T), distance (D) and energy (E)
used by the three most
popular forms of transport in Yorkshire and the Humber.}
%\footnotesize
\setlength\tabcolsep{0.9ex}\begin{tabular}{lrrrcrrrcrrrcrrr}
\toprule
Dis. & \multicolumn{ 3}{c}{Car*} && \multicolumn{ 3}{c}{Walk} && \multicolumn{3}{c}{Bus} && \multicolumn{ 3}{c}{All modes} \\ 
(km) & \multicolumn{1}{c}{T} & \multicolumn{1}{c}{D} & \multicolumn{1}{c}{E} && \multicolumn{1}{c}{T} & \multicolumn{1}{c}{D} & \multicolumn{1}{c}{E} && \multicolumn{1}{c}{T} &
\multicolumn{1}{c}{D} & \multicolumn{1}{c}{E} && \multicolumn{1}{c}{T} & \multicolumn{1}{c}{D} & \multicolumn{1}{c}{E} \\ 
\midrule
0-2 & 1.2 & 0.1 & 0.2 && 3.5 & 0.4 & 0.0  && 0.2 & 0.0 & 0.0 && 16.8 & 0.6 & 0.2 \\
2-5 & 12.8 & 3.8 & 4.9 && 5.9 & 1.4 & 0.1 && 4.8 & 1.5 & 0.5 && 28.3 & 8.1 & 5.6 \\
5-10 & 15.5 & 10.4 & 13.4 && 0.4 & 0.3 & 0.0 && 3.8 & 2.5 & 0.9 && 23.4 & 15.7 & 14.6 \\
10-20 & 14.0 & 17.3 & 22.2 && 0.7 & 0.8& 0.0 && 0.9 & 1.1 & 0.4 && 17.7 & 21.7 & 23.0 \\
20-50 & 7.9 & 21.1 & 27.0 && 0.0 & 0.0 & 0.0 && 0.3 & 0.8 & 0.3 && 10.0 & 26.5 & 27.7 \\
50+ & 3.0 & 22.3 & 28.6 && 0.0 & 0.0 & 0.0 && 0.0 & 0.0 & 0.0 && 3.8 & 27.5 & 28.8 \\
All & 54.6 & 75.0 & 96.4 && 10.6 & 2.9 & 0.2 && 10.1 & 5.9 & 2.1 && 100 & 100 & 100 \\ 
\bottomrule
\end{tabular}
\label{t:props}

{\footnotesize *Excludes car passengers}
\end{table}
\noindent X\dotfill X

\begin{table}[htbp]
\caption{Proportion of trips (T), distance (D) and energy (E)
used by the three most
popular forms of transport in Yorkshire and the Humber.}
%\footnotesize
\setlength\tabcolsep{1.1ex}\begin{tabular}{lrrrcrrrcrrrcrrr}
\toprule
Dis. & \multicolumn{ 3}{c}{Car*} && \multicolumn{ 3}{c}{Walk} && \multicolumn{3}{c}{Bus} && \multicolumn{ 3}{c}{All modes} \\ 
(km) & \multicolumn{1}{c}{T} & \multicolumn{1}{c}{D} & \multicolumn{1}{c}{E} && \multicolumn{1}{c}{T} & \multicolumn{1}{c}{D} & \multicolumn{1}{c}{E} && \multicolumn{1}{c}{T} &
\multicolumn{1}{c}{D} & \multicolumn{1}{c}{E} && \multicolumn{1}{c}{T} & \multicolumn{1}{c}{D} & \multicolumn{1}{c}{E} \\ 
\midrule
0-2 & 1.2 & 0.1 & 0.2 && 3.5 & 0.4 & 0.0  && 0.2 & 0.0 & 0.0 && 16.8 & 0.6 & 0.2 \\
2-5 & 12.8 & 3.8 & 4.9 && 5.9 & 1.4 & 0.1 && 4.8 & 1.5 & 0.5 && 28.3 & 8.1 & 5.6 \\
5-10 & 15.5 & 10.4 & 13.4 && 0.4 & 0.3 & 0.0 && 3.8 & 2.5 & 0.9 && 23.4 & 15.7 & 14.6 \\
10-20 & 14.0 & 17.3 & 22.2 && 0.7 & 0.8& 0.0 && 0.9 & 1.1 & 0.4 && 17.7 & 21.7 & 23.0 \\
20-50 & 7.9 & 21.1 & 27.0 && 0.0 & 0.0 & 0.0 && 0.3 & 0.8 & 0.3 && 10.0 & 26.5 & 27.7 \\
50+ & 3.0 & 22.3 & 28.6 && 0.0 & 0.0 & 0.0 && 0.0 & 0.0 & 0.0 && 3.8 & 27.5 & 28.8 \\
All & 54.6 & 75.0 & 96.4 && 10.6 & 2.9 & 0.2 && 10.1 & 5.9 & 2.1 && 100 & 100 & 100 \\ 
\bottomrule
\end{tabular}
\label{t:props}

{\footnotesize *Excludes car passengers}
\end{table}

\end{document}

enter image description here

8

I think the other answers give you wonderful looking tables. A few folks may benefit from a different visual, perhaps a bar chart, as shown below.

The wonderful pgfplots package is extremely powerful, and allows us to read the data with very minimal adjustment to your code.

\pgfplotstableread[row sep=\\,col sep=&]{
    interval & carT  & carD    & carR    &  busT    & busD    & busR    &  walkT    & walkD    & walkR    & totalT     & totalD     & totalR     \\
    0--2   &  1.2 &  0.1 &  0.2 &  3.5 & 0.4 & 0.0 &  0.2 & 0.0 & 0.0 & 16.8 &  0.6 &  0.2 \\
    2--5   & 12.8 &  3.8 &  4.9 &  5.9 & 1.4 & 0.1 &  4.8 & 1.5 & 0.5 & 28.3 &  8.1 &  5.6 \\
    5--10  & 15.5 & 10.4 & 13.4 &  0.4 & 0.3 & 0.0 &  3.8 & 2.5 & 0.9 & 23.4 & 15.7 & 14.6 \\
    10--20 & 14.0 & 17.3 & 22.2 &  0.7 & 0.8 & 0.0 &  0.9 & 1.1 & 0.4 & 17.7 & 21.7 & 23.0 \\
    20--50 &  7.9 & 21.1 & 27.0 &  0.0 & 0.0 & 0.0 &  0.3 & 0.8 & 0.3 & 10.0 & 26.5 & 27.7 \\
    50+    &  3.0 & 22.3 & 28.6 &  0.0 & 0.0 & 0.0 &  0.0 & 0.0 & 0.0 &  3.8 & 27.5 & 28.8 \\
    }\mydata

I have used the subcaption package to provide figure (a), (b), and (c), but that's just personal preference.

table 1: car

table 2: bus

table 3: walk

Complete code

% arara: pdflatex
% !arara: indent: {overwrite: yes}
\documentclass{article}
\usepackage{subcaption}

\usepackage{pgfplots}

\begin{document}

\pgfplotstableread[row sep=\\,col sep=&]{
    interval & carT  & carD    & carR    &  busT    & busD    & busR    &  walkT    & walkD    & walkR    & totalT     & totalD     & totalR     \\
    0--2   &  1.2 &  0.1 &  0.2 &  3.5 & 0.4 & 0.0 &  0.2 & 0.0 & 0.0 & 16.8 &  0.6 &  0.2 \\
    2--5   & 12.8 &  3.8 &  4.9 &  5.9 & 1.4 & 0.1 &  4.8 & 1.5 & 0.5 & 28.3 &  8.1 &  5.6 \\
    5--10  & 15.5 & 10.4 & 13.4 &  0.4 & 0.3 & 0.0 &  3.8 & 2.5 & 0.9 & 23.4 & 15.7 & 14.6 \\
    10--20 & 14.0 & 17.3 & 22.2 &  0.7 & 0.8 & 0.0 &  0.9 & 1.1 & 0.4 & 17.7 & 21.7 & 23.0 \\
    20--50 &  7.9 & 21.1 & 27.0 &  0.0 & 0.0 & 0.0 &  0.3 & 0.8 & 0.3 & 10.0 & 26.5 & 27.7 \\
    50+    &  3.0 & 22.3 & 28.6 &  0.0 & 0.0 & 0.0 &  0.0 & 0.0 & 0.0 &  3.8 & 27.5 & 28.8 \\
    }\mydata

\begin{figure}[!htb]
    \begin{subfigure}{\textwidth}
        \begin{tikzpicture}
            \begin{axis}[
                    ybar,
                    bar width=.5cm,
                    width=\textwidth,
                    height=.5\textwidth,
                    legend style={at={(0.5,1)},
                        anchor=north,legend columns=-1},
                    symbolic x coords={0--2,2--5,5--10,10--20,20--50,50+},
                    xtick=data,
                    nodes near coords,
                    nodes near coords align={vertical},
                    ymin=0,ymax=35,
                    %xlabel={Car},
                    ylabel={\%},
                ]
                \addplot table[x=interval,y=carT]{\mydata};
                \addplot table[x=interval,y=carD]{\mydata};
                \addplot table[x=interval,y=carR]{\mydata};
                \legend{Trips, Distance, Energy}
            \end{axis}
        \end{tikzpicture}
        \caption{Car}
    \end{subfigure}
    \begin{subfigure}{\textwidth}
        \begin{tikzpicture}
            \begin{axis}[
                    ybar,
                    bar width=.5cm,
                    width=\textwidth,
                    height=.5\textwidth,
                    legend style={at={(0.5,1)},
                        anchor=north,legend columns=-1},
                    symbolic x coords={0--2,2--5,5--10,10--20,20--50,50+},
                    xtick=data,
                    nodes near coords,
                    nodes near coords align={vertical},
                    ymin=0,ymax=35,
                    %xlabel={Bus},
                    ylabel={\%},
                ]
                \addplot table[x=interval,y=busT]{\mydata};
                \addplot table[x=interval,y=busD]{\mydata};
                \addplot table[x=interval,y=busR]{\mydata};
                \legend{Trips, Distance, Energy}
            \end{axis}
        \end{tikzpicture}
        \caption{Bus}
    \end{subfigure}
    \begin{subfigure}{\textwidth}
        \begin{tikzpicture}
            \begin{axis}[
                    ybar,
                    bar width=.5cm,
                    width=\textwidth,
                    height=.5\textwidth,
                    legend style={at={(0.5,1)},
                        anchor=north,legend columns=-1},
                    symbolic x coords={0--2,2--5,5--10,10--20,20--50,50+},
                    xtick=data,
                    nodes near coords,
                    nodes near coords align={vertical},
                    ymin=0,ymax=35,
                    %xlabel={Walk},
                    ylabel={\%},
                ]
                \addplot table[x=interval,y=walkT]{\mydata};
                \addplot table[x=interval,y=walkD]{\mydata};
                \addplot table[x=interval,y=walkR]{\mydata};
                \legend{Trips, Distance, Energy}
            \end{axis}
        \end{tikzpicture}
        \caption{Walk}
    \end{subfigure}
\end{figure}
\end{document}
  • I think this a great idea. While the tables may make it difficult to find some relationships, graphs are a great way to make relationships easily apparent. Maybe the OP can add this to an appendix or something or just use this instead of a table! – Jeel Shah Oct 29 '13 at 6:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.