我尝试在会议给定的 LaTeX 模板中编写一个表格并添加所需的 usepackage。但不知道该如何使表格居中并画线。
它输出:
\documentclass[a4paper,10pt,oneside]{article}
\usepackage{icad2020,amsmath,epsfig,times,url}
\usepackage{makecell, multirow, tabularx} %for table multirow
\usepackage{booktabs}
\usepackage{longtable}
\begin{document}
\begin{table}[h!]
\centering
\begin{tabular*}{0.55\textwidth}{
@{}
l
S[table-format=4]
S[table-format=4]
S[table-format=4]
@{}
}
\toprule
{\thead{Stimulus \\ Sample}}
& {\thead{Class A \\ Sample \\ Sample}}
& {\thead{Class B \\ Sample \\ Sample}}
& {\thead{Class C \\ Sample \\ Sample}}\\
\midrule
Stimulus 7 & A2 & B47 & A28 \\
Stimulus 8 & A18 & B34 & B33 \\
\bottomrule
\end{tabular*}
\end{table}
\end{document}
答案1
- 您的 MWE 包含
icad2020
不公开的包。请将其影响页面布局的内容添加到您的 MWE 中 - 省略
icad2020
你的 MWE 生成一个列文档,其中你的问题不会发生 - 您的表中没有数字,因此其他列类型可能更合适
- 使用了
S
列,但是您没有加载定义它的包 - 你规定的表格宽度大于其自然宽度以及列宽
\documentclass[a4paper,10pt, twocolumn,
oneside]{article}
\usepackage{%icad2020,
amsmath,epsfig,times,url}
\usepackage{makecell, multirow, tabularx} %for table multirow
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{lipsum}
\begin{document}
\lipsum[1]
\begin{table}[h!]
\centering
\begin{tabular}{@{} l *{4}{c} @{} }
\toprule
{\thead{Stimulus \\ Sample}}
& {\thead{Class A \\ Sample \\ Sample}}
& {\thead{Class B \\ Sample \\ Sample}}
& {\thead{Class C \\ Sample \\ Sample}}\\
\midrule
Stimulus 7 & A2 & B47 & A28 \\
Stimulus 8 & A18 & B34 & B33 \\
\bottomrule
\end{tabular}
\end{table}
\lipsum[2-6]
\end{document}
答案2
一个更简单的解决方案是使用tabulary
:
\documentclass[a4paper,twocolumn]{article}
\usepackage{tabulary}
\usepackage{booktabs}
\usepackage{lipsum}
\begin{document}
\begin{table}
\centering
\tabcolsep0pt
\tymax.25\dimexpr\linewidth
\begin{tabulary}{\linewidth}{@{}CCCC@{}}\toprule
Stimulus Sample &
Class A Sample Sample &
Class B Sample Sample &
Class C Sample Sample \\\midrule
Stimulus 7 & A2 & B47 & A28 \\
Stimulus 8 & A18 & B34 & B33 \\\bottomrule
\end{tabulary}
\end{table}
\lipsum
\end{document}