7

I have the following table in the .tex file:

\documentclass{article}
\usepackage{booktabs}
\begin{document}

\begin{table}[htbp]
  \centering
  \caption{Distribution of Number of Injured Non-Motorists by Injury Severity Level}
    \begin{tabular}{rcccccc}
    \toprule
    \textbf{Injury Severity } & \multicolumn{2}{c}{\textbf{Pedestrian}} & \multicolumn{2}{c}{\textbf{Bicyclist}} & \multicolumn{2}{c}{\textbf{All Non-Motorists}} \\
    \midrule
    Possible injury & 1700  & 67.70\% & 502   & 59.40\% & 2202  & 65.60\% \\
    Non-Incapacitating injury & 523   & 20.80\% & 259   & 30.70\% & 782   & 23.30\% \\
    Incapacitating injury & 250   & 10.00\% & 84    & 9.90\% & 334   & 9.90\% \\
    Fatal injury & 39    & 1.50\% & 0     & 0.00\% & 39    & 1.20\% \\
    \textbf{Total} & \textbf{2512} & \textbf{100.00\%} & \textbf{845} & \textbf{100.00\%} & \textbf{3357} & \textbf{100.00\%} \\
    \bottomrule
    \end{tabular}%
  \label{tab:dvar}%
\end{table}%

\end{document}

This gives me the following table: Table using Latex code

However, I want it in this specific format for my thesis:

Required formatting

Please note that the outer borders are 2 lines while the inner borders are single line. Also, the numbers are to be aligned along the decimal point.

Can anyone please help me out here?

0

3 Answers 3

7

You can use the tabu package which offers you ready to use features to control the attributes (thickness, color) of the rules; alignment at the decimal separator can be achieved using the dcolumn package:

\documentclass{article}
\usepackage{xcolor}
\usepackage{dcolumn}
\usepackage{tabu}

\newcolumntype{A}{D{.}{.}{2.3}}

\begin{document}

\begin{table}[htbp]
  \centering
  \caption{Distribution of Number of Injured Non-Motorists by Injury Severity Level}
    \extrarowsep=_3pt^3pt
     \begin{tabu}to\linewidth{|[2pt gray]r|c|A|c|A|c|A|[1.5pt gray]}
    \tabucline[1.5pt gray]-
    \bfseries Injury Severity  & \multicolumn{2}{c|}{\textbf{Pedestrian}} & \multicolumn{2}{c|}{\textbf{Bicyclist}} & \multicolumn{2}{c|[1.5pt gray]}{\textbf{All Non-Motorists}} \\
    \tabucline[1.5pt gray]-
    Possible injury & 1700  & 67.70\% & 502   & 59.40\% & 2202  & 65.60\% \\
    Non-Incapacitating injury & 523   & 20.80\% & 259   & 30.70\% & 782   & 23.30\% \\\hline
    Incapacitating injury & 250   & 10.00\% & 84    & 9.90\% & 334   & 9.90\% \\\hline
    Fatal injury & 39    & 1.50\% & 0     & 0.00\% & 39    & 1.20\% \\
    \tabucline[1.5pt gray]-
    \bfseries Total & \bfseries 2512 & \multicolumn{1}{c|}{\bfseries 100.00\%} & \bfseries 845 & \multicolumn{1}{c|}{\bfseries 100.00\%} & \bfseries 3357 & \multicolumn{1}{c|[1.5pt gray]}{\bfseries 100.00\%} \\
    \tabucline[1.5pt gray]-
    \end{tabu}%
 \label{tab:dvar}%
\end{table}%

\end{document}

enter image description here

Just for comparison purposes, the same table without the vertical rules and some of the horizontal ones:

\documentclass{article}
\usepackage{xcolor}
\usepackage{dcolumn}
\usepackage{tabu}

\newcolumntype{A}{D{.}{.}{2.3}}

\begin{document}

\begin{table}[htbp]
  \centering
  \caption{Distribution of Number of Injured Non-Motorists by Injury Severity Level}
    \extrarowsep=_3pt^3pt
     \begin{tabu}to\linewidth{rcAcAcA}
    \tabucline[1.5pt gray]-
    \bfseries Injury Severity  & \multicolumn{2}{c}{\textbf{Pedestrian}} & \multicolumn{2}{c}{\textbf{Bicyclist}} & \multicolumn{2}{c}{\textbf{All Non-Motorists}} \\
    \tabucline[1.5pt gray]-
    Possible injury & 1700  & 67.70\% & 502   & 59.40\% & 2202  & 65.60\% \\
    Non-Incapacitating injury & 523   & 20.80\% & 259   & 30.70\% & 782   & 23.30\% \\
    Incapacitating injury & 250   & 10.00\% & 84    & 9.90\% & 334   & 9.90\% \\
    Fatal injury & 39    & 1.50\% & 0     & 0.00\% & 39    & 1.20\% \\
    \tabucline[1.5pt gray]-
    \bfseries Total & \bfseries 2512 & \multicolumn{1}{c}{\bfseries 100.00\%} & \bfseries 845 & \multicolumn{1}{c}{\bfseries 100.00\%} & \bfseries 3357 & \multicolumn{1}{c}{\bfseries 100.00\%} \\
    \tabucline[1.5pt gray]-
    \end{tabu}%
 \label{tab:dvar}%
\end{table}%

\end{document}

enter image description here

In my opinion, this second version looks much better, but I understand the original requirement for the thesis.

4

hhline provides the means to achieve a double-line border, at the loss of eye-candy. Here's a start for your table:

enter image description here

\documentclass{article}
\usepackage{tabularx,hhline}% http://ctan.org/pkg/{tabularx,hhline}
\begin{document}

\begin{table}[htbp]
  \centering
  \caption{Distribution of Number of Injured Non-Motorists by Injury Severity Level}
  \begin{tabularx}{\linewidth}{||l*{6}{|r}||}
    \hhline{|t:=======:t|}
    \textbf{Injury Severity } & \multicolumn{2}{c|}{\textbf{Pedestrian}} & \multicolumn{2}{c|}{\textbf{Bicyclist}} & \multicolumn{2}{c||}{\textbf{All Non-Motorists}} \\
    \hhline{|:=|==|==|==:|}
    Possible injury & 1700  & 67.70\% & 502   & 59.40\% & 2202  & 65.60\% \\
    Non-Incapacitating injury & 523   & 20.80\% & 259   & 30.70\% & 782   & 23.30\% \\
    Incapacitating injury & 250   & 10.00\% & 84    & 9.90\% & 334   & 9.90\% \\
    Fatal injury & 39    & 1.50\% & 0     & 0.00\% & 39    & 1.20\% \\
    \hhline{||-------||}
    \textbf{Total} & \textbf{2512} & \textbf{100.00\%} & \textbf{845} & \textbf{100.00\%} & \textbf{3357} & \textbf{100.00\%} \\
    \hhline{|b:=======:b|}
  \end{tabularx}
  \label{tab:dvar}
\end{table}

\end{document}

See the hhline documentation for the format used increating double lines and their intersections. The following is taken directly from the documentation (p 2):

enter image description here

Centred decimal alignment is achievable using some boxing techniques (provided by \padfour, \padthree and \padtwo) and dcolumn's D-column specification:

enter image description here

\documentclass{article}
\usepackage{tabularx,dcolumn,hhline}% http://ctan.org/pkg/{tabularx,dcolumn,hhline}
\newcommand{\padfour}[1]{\setbox0=\hbox{0000}\makebox[\wd0][r]{#1}}%
\newcommand{\padthree}[1]{\setbox0=\hbox{000}\makebox[\wd0][r]{#1}}%
\newcommand{\padtwo}[1]{\setbox0=\hbox{00}\makebox[\wd0][r]{#1}}%
\begin{document}

\begin{table}[htbp]
  \centering
  \caption{Distribution of Number of Injured Non-Motorists by Injury Severity Level}
  \begin{tabularx}{\linewidth}{||l*{3}{|c|D{.}{.}{2.3}}||}
    \hhline{|t:=======:t|}
    \textbf{Injury Severity } & \multicolumn{2}{c|}{\textbf{Pedestrian}} & \multicolumn{2}{c|}{\textbf{Bicyclist}} & \multicolumn{2}{c||}{\textbf{All Non-Motorists}} \\
    \hhline{|:=|==|==|==:|}
    Possible injury           & \padfour{1700} & 67.70\% & \padthree{502} & 59.40\% & \padfour{2202} & 65.60\% \\
    Non-Incapacitating injury & \padfour {523} & 20.80\% & \padthree{259} & 30.70\% & \padfour {782} & 23.30\% \\
    Incapacitating injury     & \padfour {250} & 10.00\% & \padthree {84} &  9.90\% & \padfour {334} &  9.90\% \\
    Fatal injury              & \padfour  {39} &  1.50\% & \padthree  {0} &  0.00\% & \padfour  {39} &  1.20\% \\
    \hhline{||-------||}
    \textbf{Total} & \textbf{2512} & \multicolumn{1}{c|}{\bfseries 100.00\%} & \textbf{845} & \multicolumn{1}{c|}{\bfseries 100.00\%} & \textbf{3357} & \multicolumn{1}{c||}{\bfseries 100.00\%} \\
    \hhline{|b:=======:b|}
  \end{tabularx}
  \label{tab:dvar}
\end{table}

\end{document}

dcolumn does not enjoy the use of \textbf in the final row, so you have to use a \bfseries approach.

3
  • How did you achieve the decimal alignment? Excellent response.. But as you noted - it is a bit of a sore sight :(
    – sriramn
    Oct 28, 2012 at 3:01
  • @RazorXsr: A traditional r column specification. However, I've added some more alignment option by using boxes of fixed width. Gonzalo's answer with tabu is most likely the way to go.
    – Werner
    Oct 28, 2012 at 3:05
  • @GonzaloMedina: Right. dcolumn doesn't enjoy \textbf{<stuff>}, but is fine with \multicolumn{1}{c|}{\bfseries <stuff>} - thanks. I'm beginning to like tabu more and more... :)
    – Werner
    Oct 28, 2012 at 3:50
4

Yo can use the solution from How can I reproduce this table with thick lines? to obtain the thick lines.

enter image description here

Code:

\documentclass{article}
%\usepackage{booktabs}
\usepackage{array}

    %https://tex.stackexchange.com/questions/41758/how-can-i-reproduce-this-table-with-thick-lines
    \makeatletter
    \newcommand{\thickhline}{%
        \noalign {\ifnum 0=`}\fi \hrule height 1pt
        \futurelet \reserved@a \@xhline
    }
    \newcolumntype{"}{@{\vrule width 1pt}}
    \makeatother

\begin{document}



\begin{table}[htbp]
  \centering
  \caption{Distribution of Number of Injured Non-Motorists by Injury Severity Level}
    \begin{tabular}{"r|c|c|c|c|c|c"}
    \thickhline%\toprule
    \textbf{Injury Severity} & \multicolumn{2}{c|}{\textbf{Pedestrian}} & \multicolumn{2}{c|}{\textbf{Bicyclist}} & \multicolumn{2}{c"}{\textbf{All Non-Motorists}} \\
    \thickhline%\midrule
    Possible injury & 1700  & 67.70\% & 502   & 59.40\% & 2202  & 65.60\% \\
    Non-Incapacitating injury & 523   & 20.80\% & 259   & 30.70\% & 782   & 23.30\% \\\hline
    Incapacitating injury & 250   & 10.00\% & 84    & 9.90\% & 334   & 9.90\% \\\hline
    Fatal injury & 39    & 1.50\% & 0     & 0.00\% & 39    & 1.20\% \\\thickhline
    \textbf{Total} & \textbf{2512} & \textbf{100.00\%} & \textbf{845} & \textbf{100.00\%} & \textbf{3357} & \textbf{100.00\%} \\\thickhline
    %\bottomrule
    \end{tabular}%
  \label{tab:dvar}%
\end{table}%

\end{document}
2
  • Hi @peter... I think the image is a bit fuzzy but I want double lined border, not thick lines.
    – sriramn
    Oct 28, 2012 at 2:46
  • 1
    Damm, other solutions already so no point in me providing the same thing.. But I think that you have gone from a good table, to a, well... not so good... Just my opinion... Oct 28, 2012 at 2:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .