latex设置表格总宽度并且居中
centering论⽂要求表格总宽度是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}就是居中⽤的

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。