我有一张表格,但是格式化它时遇到问题:
\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}
- 我想要一条双粗线,而不是在顶部有一条双普通线,在底部有一条粗线。
- 我希望每个单元格的中间都正好有星星。
答案1
解决方案使用宏,该tabularx
宏\stars
将星星数量作为参数,并将它们垂直居中放置。它需要包multido
;
\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}
答案2
我不知道这是否是你要找的。
% 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}