Formatting table border and text alignment in LaTeX table
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}
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}
In my opinion, this second version looks much better, but I understand the original requirement for the thesis.
Yo can use the solution from How can I reproduce this table with thick lines? to obtain the thick lines.
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}
hhline
provides the means to achieve a double-line border, at the loss of eye-candy. Here's a start for your table:
\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):
Centred decimal alignment is achievable using some boxing techniques (provided by \padfour
, \padthree
and \padtwo
) and dcolumn
's D
-column specification:
\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.