我有这张乳胶桌
\begin{table}[H]
\centering
\footnotesize
\begin{tabular}{p{3.5cm}p{3.5cm}p{3.5cm}}
\hline
Metric& cca vs. cca1 &cca vs. King James Bible\\[0.1cm]
\hline
Average codelength & 0.84 & 1.84 \\[0.1cm]
Top1 unigram & 7.65 & 10.52 \\[0.1cm]
Top5 unigram & 6.94 & 10.05 \\[0.1cm]
Top10 unigram & 6.38 & 9.72 \\[0.1cm]
Top100 unigram & 4.88 & 7.54 \\[0.1cm]
Top1 bigram & 8.52 & 11.25 \\[0.1cm]
Top5 bigram & 6.68 & 10.23 \\[0.1cm]
Top10 bigram & 5.94 & 9.38 \\[0.1cm]
Top100 bigram & 4.17 & 7.19 \\[0.1cm]
Top1 trigram & 5.4 & 9.56 \\[0.1cm]
Top5 trigram & 4.77 & 8.68 \\[0.1cm]
Top10 trigram & 4.6 & 8.17 \\[0.1cm]
Top100 trigram & 3.58 & 6.3 \\[0.1cm]
\% of words in 1st corpus not in 2nd corpus &6.05 & 8.73 \\[0.1cm]
\% of words in 2nd corpus not in 1st corpus & 5.54 & 2.94 \\[0.1cm]
Top 10 unseen words in 1st corpus & Mr. Mrs. Dr. Mr SIC J. St. Colour Fig. R. & LORD Shalt and was are hast Is Were be \\[0.1cm]
Top 10 unseen words in 2nd corpus & Mr\& **f Mrs\& **h Program Dr\& <The **f. Center St\& & Has Mr\& American Mrs\& Around during United Does don't didn't \\[0.1cm]
\end{tabular}%
\label{tab:addlabel}%
\end{table}%
我如何才能使该表的记录居中以获得更好的表格形状
特别是我有一些包含多行文本的记录,如下所示?
答案1
您可以将第 2 列和第 3 列的“主”列类型设置为S
(由包提供siunitx
)以使数字条目居中并进行小数对齐,同时p{<width>}
对这些列中选定的其他单元格使用适当调整的列类型。
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{array}
\newcolumntype{P}{>{\raggedright\arraybackslash}p{3.5cm}}
\usepackage{siunitx} % center and decimal-align numeric entries
\sisetup{table-format=1.2}
\begin{document}
\begin{table}
\caption{A table with three columns}
\label{tab:addlabel}
\smallskip % some separation between caption and tabular env.
\setlength\extrarowheight{0.1cm} % so you don't have to add [0.1cm] after every "\\"
\centering
% \footnotesize %% not needed, is it?
\begin{tabular}{PSS}
\hline
Metric& \multicolumn{1}{c}{cca vs. cca1} &
\multicolumn{1}{P}{cca vs. King James Bible}\\
\hline
Average codelength & 0.84 & 1.84 \\
Top1 unigram & 7.65 & 10.52 \\
Top5 unigram & 6.94 & 10.05 \\
Top10 unigram & 6.38 & 9.72 \\
Top100 unigram & 4.88 & 7.54 \\
Top1 bigram & 8.52 & 11.25 \\
Top5 bigram & 6.68 & 10.23 \\
Top10 bigram & 5.94 & 9.38 \\
Top100 bigram & 4.17 & 7.19 \\
Top1 trigram & 5.4 & 9.56 \\
Top5 trigram & 4.77 & 8.68 \\
Top10 trigram & 4.6 & 8.17 \\
Top100 trigram & 3.58 & 6.3 \\
\% of words in 1st corpus not in 2nd corpus &6.05 & 8.73 \\
\% of words in 2nd corpus not in 1st corpus & 5.54 & 2.94 \\
Top 10 unseen words in 1st corpus &
\multicolumn{1}{P}{Mr. Mrs. Dr. Mr SIC J. St. Colour Fig. R.} &
\multicolumn{1}{P}{LORD Shalt and was are hast Is Were be} \\
Top 10 unseen words in 2nd corpus &
\multicolumn{1}{P}{Mr\& **f Mrs\& **h Program Dr\& <The **f. Center St\&} &
\multicolumn{1}{P}{Has Mr\& American Mrs\& Around during United Does don't didn't}\\
\end{tabular}
\end{table}
\end{document}
答案2
请参阅该包的文档array
。
您可以添加额外的命令来对表格列进行操作。因此,要将 ap 列居中,您可以编写
>{\centering}p{3cm}
或完整
\begin{tabular}{>{centering}p{3.5cm}p{3.5cm}p{3.5cm}}
在这种情况下,居中只会作用于第一列,您必须为需要的每个列添加它。这有点烦人,所以只需定义您自己的新列类型
\newcolumntype{P}[1]{>{\centering}p{#1}}
然后你就可以写字了P{3cm}
,你会得到一个以文本为中心的、具有定义宽度的列。有时文本在狭窄的表格列上会变得奇怪。那么你可能要考虑ragged2e
用 \Centering 包替换 \centering ,这样效果会更好。