我是 Latex 的完全初学者。我想创建一个表格。不幸的是,表格有点拥挤,无法放入页面。因此,我想减小表格内的字体大小,并在 Google 上搜索了相关内容。我找到了 [这个][1] 答案并应用了它。它帮助我将表格放入页面,但现在,我无法为表格添加标题。每当我尝试添加标题时,都会出现以下错误:
你不能在这里使用 `\hrule',除非有领导者。 \caption@hrule ->\hrule \@height \z@ l.203 \end{tabular}}
这是我用来创建表的代码:
\begin{table}
\resizebox{\textwidth}{!}{%
\centering
\captionsetup{labelformat=empty}
\caption{Data statistics Treebanks. The values on \{Train,Dev,Test\}-Set columns are the number of tokens in the splits. Unique tags column gives the number of distinct sets of tags (pos + morphological features) assigned to words, unique features gives the number of distinct features that exist in the dataset.}
\begin{tabular}{llllll|llllll}
\multicolumn{1}{c}{\textbf{lang}} & \multicolumn{1}{c}{\textbf{train}} & \multicolumn{1}{c}{\textbf{dev}} & \multicolumn{1}{c}{\textbf{test}} & \multicolumn{1}{c}{\textbf{\textbar{}T\textbar{}}} & \multicolumn{1}{c|}{\textbf{\textbar{}F\textbar{}}} & \multicolumn{1}{c}{\textbf{lang}} & \multicolumn{1}{c}{\textbf{train}} & \multicolumn{1}{c}{\textbf{dev}} & \multicolumn{1}{c}{\textbf{test}} & \multicolumn{1}{c}{\textbf{\textbar{}T\textbar{}}} & \multicolumn{1}{c}{\textbf{\textbar{}F\textbar{}}} \\
\hline
ar & 1 & 4 & 2 & 123 & 123123 & es & 123 & 902 & 123 & 234 & 31567 \\
bg & 3425 & 45 & 234 & 5252 & 1231634 & pt & 755 & 234 & 645 & 2464 & 242 \\
cs & 767 & 23 & 86 & 345453 & 23422 & sk & 3453 & 1231 & 235 & 43243 & 34663 \\
en & & & & & & sl & & & & & \\
et & & & & & & ru & & & & & \\
fr & & & & & & hi & & & & & \\
hu & & & & & & lv & & & & & \\
ro & & & & & & nl & & & & & \\
tr & & & & & & pl & & & & & \\
hr & & & & & & de & & & & & \\
it & & & & & & gr & & & & & \\
da & & & & & & la & & & & & \\
ca & & & & & & ko & & & & & \\
fi & & & & & & ir & & & & &
\end{tabular}}
\end{table}
我正在使用的软件包:
\usepackage{booktabs}
\usepackage{float}
\usepackage{breakcites}
\usepackage{svg}
\usepackage{graphics}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage{caption}
如果我注释\captionsetup
和\caption
行,表格将不显示标题
答案1
resizebox
除非您愿意让表格中的字体大小与周围文本中使用的字体大小有很大差异,否则不要使用。
一些额外的建议:
使用
\small
字体大小指令(将字体大小线性减少 10%)并使用环境tabular*
而不是tabular
环境来排版表格材料。既然您无论如何都要加载该
booktabs
包,请使用其宏:\toprule
、\bottomrule
和\cmidrule
。表格标题要简短明了。如果图例较长,请将其放在标题和表格之间。
将 10 个数字列右对齐似乎比左对齐更好。
写作
$|\mathbf{T}|$
比做事容易\textbf{\textbar{}T\textbar{}}
,对吧?
这是实现这些想法的 MWE 的输出。
\documentclass{article}
\usepackage{booktabs,caption}
\newcommand\mc[1]{\multicolumn{1}{c}{#1}} % handy shortcut macro
\begin{document}
\begin{table}
\captionsetup{font=small,skip=0.333\baselineskip}
\caption*{Data statistics Treebanks}
\small
The values in the \{Train, Dev, Test\}-Set of columns
are the number of tokens in the splits. Unique tags
column gives the number of distinct sets of tags
(pos~+ morphological features) assigned to words,
unique features gives the number of distinct features
that exist in the dataset.
\medskip
\setlength\tabcolsep{0pt}
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}
*{2}{l*{5}{r}}}
\toprule
\textbf{lang} & \mc{\textbf{train}} & \mc{\textbf{dev}}
& \mc{\textbf{test}} & \mc{$|\mathbf{T}|$} & \mc{$|\mathbf{F}|$} &
\textbf{lang} & \mc{\textbf{train}} & \mc{\textbf{dev}}
& \mc{\textbf{test}} & \mc{$|\mathbf{T}|$} & \mc{$|\mathbf{F}|$} \\
\cmidrule{1-6} \cmidrule{7-12}
ar & 1 & 4 & 2 & 123 & 123123 &
es & 123 & 902 & 123 & 234 & 31567 \\
bg & 3425 & 45 & 234 & 5252 & 1231634 &
pt & 755 & 234 & 645 & 2464 & 242 \\
cs & 767 & 23 & 86 & 345453 & 23422 &
sk & 3453 & 1231 & 235 & 43243 & 34663 \\
en & & & & & &
sl & & & & & \\
et & & & & & &
ru & & & & & \\
fr & & & & & &
hi & & & & & \\
hu & & & & & &
lv & & & & & \\
ro & & & & & &
nl & & & & & \\
tr & & & & & &
pl & & & & & \\
hr & & & & & &
de & & & & & \\
it & & & & & &
gr & & & & & \\
da & & & & & &
la & & & & & \\
ca & & & & & &
ko & & & & & \\
fi & & & & & &
ir & & & & & \\
\bottomrule
\end{tabular*}
\end{table}
\end{document}
答案2
您不应该使用\resizebox
来制作表格,因为这会导致字体大小不一致,并且表格通常难以阅读。这里有一个解决方案,只需在表格环境中简单地更改字体大小,并将 的值(\tabcolsep
即列两侧的填充)设置为较小值。我还擅自稍微更改了表格的布局:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{array}
\usepackage{caption}
\begin{document}
\begin{table}
\centering\small\setlength{\tabcolsep}{3.6pt}
\setlength{\extrarowheight}{2pt}
\captionsetup{labelformat=empty, font = small}
\caption{Data statistics Treebanks. The values on \{Train,Dev,Test\}-Set columns are the number of tokens in the splits. Unique tags column gives the number of distinct sets of tags (pos + morphological features) assigned to words, unique features gives the number of distinct features that exist in the dataset.}
\begin{tabular}{@{}c*{5}{l}|c*{5}{l}@{}}
\multicolumn{1}{c}{\textbf{lang}} & \multicolumn{1}{c}{\textbf{train}} & \multicolumn{1}{c}{\textbf{dev}} & \multicolumn{1}{c}{\textbf{test}} & \multicolumn{1}{c}{\textbf{\textbar{}T\textbar{}}} & \multicolumn{1}{c|}{\textbf{\textbar{}F\textbar{}}} & \multicolumn{1}{c}{\textbf{lang}} & \multicolumn{1}{c}{\textbf{train}} & \multicolumn{1}{c}{\textbf{dev}} & \multicolumn{1}{c}{\textbf{test}} & \multicolumn{1}{c}{\textbf{\textbar{}T\textbar{}}} & \multicolumn{1}{c}{\textbf{\textbar{}F\textbar{}}} \\
\hline
ar & 1 & 4 & 2 & 123 & 123123 & es & 123 & 902 & 123 & 234 & 31567 \\
bg & 3425 & 45 & 234 & 5252 & 1231634 & pt & 755 & 234 & 645 & 2464 & 242 \\
cs & 767 & 23 & 86 & 345453 & 23422 & sk & 3453 & 1231 & 235 & 43243 & 34663 \\
en & & & & & & sl & & & & & \\
et & & & & & & ru & & & & & \\
fr & & & & & & hi & & & & & \\
hu & & & & & & lv & & & & & \\
ro & & & & & & nl & & & & & \\
tr & & & & & & pl & & & & & \\
hr & & & & & & de & & & & & \\
it & & & & & & gr & & & & & \\
da & & & & & & la & & & & & \\
ca & & & & & & ko & & & & & \\
fi & & & & & & ir & & & & &
\end{tabular}%}
\end{table}
\end{document}
答案3
可以通过嵌套tabular*
环境来简化输入。
值table-format
可以调整事后当完整数据可见时。
\documentclass{article}
\usepackage{booktabs,caption,siunitx}
\begin{document}
\begin{table}
\caption{Data statistics Treebanks}
The values in the \{Train, Dev, Test\}-Set of columns
are the number of tokens in the splits. Unique tags
column gives the number of distinct sets of tags
(pos~+ morphological features) assigned to words,
unique features gives the number of distinct features
that exist in the dataset.
\medskip
\small
\setlength{\tabcolsep}{0pt} % let tabular* do the job
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}ll@{}}
\toprule
\begin{tabular*}{.48\textwidth}[t]{
@{\extracolsep{\fill}}
l
S[table-format=4.0]
S[table-format=4.0]
S[table-format=3.0]
S[table-format=6.0]
S[table-format=7.0]
@{}
}
\textbf{lang} & {\textbf{train}} & {\textbf{dev}}
& {\textbf{test}} & {$|\mathbf{T}|$} & {$|\mathbf{F}|$} \\
\midrule
ar & 1 & 4 & 2 & 123 & 123123 \\
bg & 3425 & 45 & 234 & 5252 & 1231634 \\
cs & 767 & 23 & 86 & 345453 & 23422 \\
en & & & & & \\
et & & & & & \\
fr & & & & & \\
hu & & & & & \\
ro & & & & & \\
tr & & & & & \\
hr & & & & & \\
it & & & & & \\
da & & & & & \\
ca & & & & & \\
fi & & & & & \\
\end{tabular*}
&
\begin{tabular*}{.48\textwidth}[t]{
@{\extracolsep{\fill}}
l
S[table-format=4.0]
S[table-format=4.0]
S[table-format=3.0]
S[table-format=6.0]
S[table-format=7.0]
@{}
}
\textbf{lang} & {\textbf{train}} & {\textbf{dev}}
& {\textbf{test}} & {$|\mathbf{T}|$} & {$|\mathbf{F}|$} \\
\midrule
es & 123 & 902 & 123 & 234 & 31567 \\
pt & 755 & 234 & 645 & 2464 & 242 \\
sk & 3453 & 1231 & 235 & 43243 & 34663 \\
sl & & & & & \\
ru & & & & & \\
hi & & & & & \\
lv & & & & & \\
nl & & & & & \\
pl & & & & & \\
de & & & & & \\
gr & & & & & \\
la & & & & & \\
ko & & & & & \\
ir & & & & & \\
\end{tabular*} \\
\bottomrule
\end{tabular*}
\end{table}
\end{document}