论文要求表格总宽度是8cm,搞了两三个小时才找到怎么搞,累死了,好多方法是调了总宽度没法居中,缩放的方法字号大小又会变,反正就是搞了好半天才满意。
目的:保证表格总宽度是8cm,里面的每个元素好看点,不要跑偏
使用\usepackage{tabularx}
代码如下`
\begin{table}[tb]
\footnotesize
%% increase table row spacing, adjust to taste
%\renewcommand{\arraystretch}{1.5}
% if using array.sty, it might be a good idea to tweak the value of
%\extrarowheight as needed to properly center the text within the cells
\caption{哈哈哈哈哈哈哈哈哈}
\label{table:1}
\begin{center}
\begin{tabularx}{8cm}{p{2cm}<{\centering}|p{1.2cm}<{\centering}|p{1.2cm}<{\centering}|X<{\centering}|X<{\centering}}%这里8cm是总宽度,p{}设置每个的宽度
\hline
\bfseries Algorithm & Prec(20px) & AUC & FPS & GPU \
\hline
\bfseries name & 0.924 & 0.687 & 16.7 & O \
\hline
\bfseries name & 0.903 & 0.659 & 2.9 & O \
\hline
\bfseries name & 0.898 & 0.670 & 15.0 & O \
\hline
\bfseries name & 0.889 & 0.603 & 5.8 & O\
\hline
\bfseries name & 0.852 & 0.579& \textless 1 & O \
\hline
\bfseries name & 0.870 & 0.653 & 1.7 & X \
\hline
\bfseries name & 0.849 & 0.641 & \textless 1 & O \
\hline
\end{tabularx}
\end{center}
\end{table}`
注意 \begin{tabularx}{8cm}{p{2cm}<{\centering}|p{1.2cm}<{\centering}|p{1.2cm}<{\centering}|X<{\centering}|X<{\centering}}%这里8cm是总宽度,p{}设置每个的宽度
如果写成这样\begin{tabularx}{8cm}{p{2cm}|p{1.2cm}|p{1.2cm}|X|X},就不是居中了,X是自动计算剩余多少多少空余,<{\centering}就是居中用的