latex 设置表格总宽度 并且居中

论文要求表格总宽度是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}就是居中用的
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值