# Double lines and centered stars in a table

I have a table, but I have a problem with formatting it:

\begin{table}[H]
\centering % used for centering table
\begin{tabular}{p{5cm} c c c c}

\\
Case & Entscheidungsbäume & Neuronale Netze & kNN & SVM \\
\hline\hline % inserts single horizontal line
\\
Accuracy in general & ** & *** & ** & **** \\ \hline
Speed of learning with
respect to number of
attributes and the number of
instances  & *** &* & **** & * \\ \hline
Speed of classification  &**** & **** & * & ****  \\ \hline
Tolerance to missing values  & *** & * & * & **  \\ \hline
Tolerance to irrelevant
attributes  & *** & * & ** & ****  \\ \hline
Tolerance to noise  & ** & ** & *& ** \\ \hline
\end{tabular}
\caption{Nonlinear Model Results} % title of Table
\label{table:nonlin} % is used to refer this table in the text
\end{table}

• I want to have a double thick line instead of a double normal line at the top and one thick line at the bottom.
• I want to have stars exactly in the middle of each cell.

A solution that uses tabularx and a macro \stars that takes as argument the number of stars and places them vertically centred. It requires the multido package;

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{caption}
\captionsetup{font = footnotesize, labelfont = sc}
\usepackage{booktabs, tabularx}
\usepackage{multido}
\usepackage{ragged2e}
\renewcommand{\tabularxcolumn}[1]{>{\RaggedRight\arraybackslash}m{#1}}
\usepackage[nomarginpar, showframe]{geometry}
\newcommand*\stars[1]{\raisebox{-0.4\height}{\multido{\i = 1 + 1}{#1}{*}}}

\begin{document}

\begin{table}[H]
\centering % used for centering table
\caption{Nonlinear Model Results} % title of Table
\begin{tabularx}{\linewidth}{X c c c c}
Case & Entscheidungsbäume & Neuronale Netze & kNN & SVM \\
\toprule\toprule % inserts double horizontal line
Accuracy in general & \stars {2}& \stars{3} & \stars {2}& \stars{4} \\
\midrule
Speed of learning with
respect to number of
attributes and the number of
instances & \stars{3} & \stars{1} & \stars{4} & \stars{1} \\
\midrule
Speed of classification & \stars{4} & \stars{4} & \stars{1} & \stars{4} \\
\midrule
Tolerance to missing values & \stars{1} & \stars{1} & \stars{1} & \stars {2} \\
\midrule
Tolerance to irrelevant
attributes & \stars{3} & \stars{1} & \stars {2}& \stars{4} \\
\midrule
Tolerance to noise & \stars {2}& \stars {2}& \stars {2}& \stars {2}\\
\bottomrule
\end{tabularx}
\label{table:nonlin} % is used to refer this table in the text
\end{table}

\end{document}


• It is really nice. How can I delete vertical lines at the both side of this table? – Kaja Aug 4 '14 at 17:57
• Oh! I forgot to mention they're there to visualise the margins (the table is exactly the width of lines). Remove the showframe option from the geometry package loading. – Bernard Aug 4 '14 at 18:00
• I would typeset the material in the first column raggedright rather than fully justified. That way, huge interword gaps can be avoided. – Mico Aug 4 '14 at 18:13
• A separate suggestion: Instead of using * and the wrapper instruction \raisebox{-0.4\height}{...} in the definition of the \stars macro, you may want to use \textasteriskcentered and omit the \raisebox wrapper instruction entirely. – Mico Aug 4 '14 at 18:30
• @Mico: I first thought it was an excellent suggestion… until I tested with other fonts than Computer Modern. With heuristica and MinionPro it requires adjusting by ~2-3pt. Thanks anyway: it indeed would have simplified the macro – Bernard Aug 4 '14 at 18:43

I dont know if this is what you are looking for.

% You should add the following required packages to your document preamble:
% \usepackage{booktabs}

\begin{table}[H]
\centering % used for centering table
\begin{tabular}{p{5cm} c c c c}

\\
Case & Entscheidungsbäume & Neuronale Netze & kNN & SVM \\
\toprule \toprule % inserts double thick horizontal line on the top of table
\\
Accuracy in general & ** & *** & ** & **** \\ \hline
Speed of learning with
respect to number of
attributes and the number of
instances  & *** &* & **** & * \\ \hline
Speed of classification  &**** & **** & * & ****  \\ \hline
Tolerance to missing values  & *** & * & * & **  \\ \hline
Tolerance to irrelevant
attributes  & *** & * & ** & ****  \\ \hline
Tolerance to noise  & ** & ** & *& ** \\ \bottomrule % inserts single thick horizontal line on the bottom of table
\end{tabular}
\caption{Nonlinear Model Results} % title of Table
\label{table:nonlin} % is used to refer this table in the text
\end{table}

• Thnaks a lot, Is it possible to locate stars at the middle of cells? specially in the second row. It doesnt look good – Kaja Aug 4 '14 at 17:20
• There's no guarantee that the table will actually fit in the text block -- usually a major requirement. – Mico Aug 4 '14 at 18:12
• @Kaja for this look at the pages 15 and 16 from this pdf file: tug.org/pracjourn/2007-1/mori/mori.pdf – Gilson Aug 4 '14 at 19:04