我有一张有 11 列的表,这是代码:
\documentclass[conference,article, 8pt]{IEEEtran}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{mathtools}
\DeclarePairedDelimiter\ceil{\lceil}{\rceil}
\usepackage[usenames]{color}
\usepackage[pdftex]{graphicx}
\usepackage{tcolorbox}
\usepackage{tabularx,ragged2e}
\usepackage{booktabs}
\usepackage{array}
\usepackage{threeparttable}
\tcbuselibrary{listingsutf8}
\newcommand{\tabhead}[1]{\textbf{#1}}
\newcommand{\rothead}[1]{\rotatebox{90}{\tabhead{#1}}}
\newsavebox\mysavebox
\begin{document}
\begin{table*}[!t]
\caption{Results}
\label{tab:tb1}
\centering
\begin{threeparttable}
\resizebox{\textwidth}{!}{\begin{tabular}{l >{\raggedright}p{5em} l l l l l}
\toprule
\rothead{Name} & \rothead{Category} &
\rothead{Size\tnote{1}} & \rothead{Number of vertices} &
\rothead{Number of edges} & \rothead{std. dev} &
\rothead{Avg. degree} & \rothead{Avg. diameter} & \rothead{Avg. time 1\tnote{2}} & \rothead{Avg. time 2} & \rothead{Avg. time 3\quad} \\
\midrule
I-SB0-SWR0 & --- & 9.670 & 6.383 & 4.587 & 9.896 & --- & --- & --- & --- & ---\\
II-SB4-SWR0 & 4 Steel Bars \O 6 mm & 15.80 & 9.966 & 5.10
& 15.451 & 56.133 & --- & --- & --- & --- & ---\\
III-SB0-SWR4 & 4 P-SWRs \O 3 mm & 14.650 & 9.369 & 5.338
& 14.525 & 46.776 & --- & --- & --- & --- & ---\\
IV-SB2-SWR2 & 2 Steel Bars \O 6 mm and 2 P-SWRs \O 3 mm
& 15.240 & 9.680 & 5.748 & 15.0 & 51.576 & --- & --- & --- & --- & ---\\
V-SB0-SWR8 & 8 P-SWRs \O 3 mm & 19.490 & 12.050 & 7.720
& 18.682 & 88.783 & --- & --- & --- & --- & ---\\
\bottomrule\\
\end{tabular}}
\begin{tablenotes}
\item[1] In MB
\item[2] In ms
\end{tablenotes}
\end{threeparttable}
\end{table*}
\end{document}
但是表格太大,无法将较大的列固定在一行中。结果如下:
我该如何修复它,让所有列都只显示在一行中(有问题的列是最后 4 个)?我还尝试将列名旋转 45°。
答案1
您仅声明了 7 列,但您的表有 11 列......
看看以下是否给出了预期的结果:
\documentclass[8pt]{IEEEtran}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
%\usepackage{amsmath} loaded by mathtools
\usepackage{amssymb}
%\usepackage{amsfonts} loaded by amssymb
\usepackage{mathtools}
\DeclarePairedDelimiter\ceil{\lceil}{\rceil}
\usepackage[usenames]{color}
\usepackage{graphicx} & you not need to declare driver pdftex
\usepackage{tcolorbox}
\usepackage{tabularx,ragged2e}
\usepackage{booktabs}
\usepackage{array}
\usepackage{threeparttable}
\tcbuselibrary{listingsutf8}
\newcommand{\tabhead}[1]{\textbf{#1}}
\newcommand{\rothead}[1]{\rotatebox{90}{\tabhead{#1}}}
\newsavebox\mysavebox
\begin{document}
\begin{table*}
\centering
\setlength\tabcolsep{0pt}
\begin{threeparttable}
\caption{Results}
\label{tab:tb1}
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}
l >{\raggedright}p{5em} *{9}{l}}
\toprule
\rothead{Name}
& \rothead{Category}
& \rothead{Size\tnote{1}}
& \rothead{Number of vertices}
& \rothead{Number of edges}
& \rothead{std. dev}
& \rothead{Avg. degree}
& \rothead{Avg. diameter}
& \rothead{Avg. time 1\tnote{2}}
& \rothead{Avg. time 2}
& \rothead{Avg. time 3} \\
\midrule
I-SB0-SWR0 & --- & 9.670 & 6.383 & 4.587 & 9.896 & --- & --- & --- & --- & ---\\
II-SB4-SWR0 & 4 Steel Bars \O 6 mm
& 15.80 & 9.966 & 5.10 & 15.451 & 56.133 & --- & --- & --- & ---\\
III-SB0-SWR4 & 4 P-SWRs \O 3 mm
& 14.650 & 9.369 & 5.338 & 14.525 & 46.776 & --- & --- & --- & --- \\
IV-SB2-SWR2 & 2 Steel Bars \O 6 mm and 2 P-SWRs \O 3 mm
& 15.240 & 9.680 & 5.748 & 15.0 & 51.576 & --- & --- & --- & --- \\
V-SB0-SWR8 & 8 P-SWRs \O 3 mm
& 19.490 & 12.050& 7.720 & 18.682 & 88.783 & --- & --- & --- & --- \\
\bottomrule
\end{tabular*}
\begin{tablenotes}
\item[1] In MB
\item[2] In ms
\end{tablenotes}
\end{threeparttable}
\end{table*}
\end{document}
但是,l
我宁愿使用在包中定义的S
数字列siunitx
和列标题来代替列类型。\rothead
makecell
编辑: 考虑到您的评论(您希望表格有 12 列,其中第二列的单元格可以有多行文本),并在最后一个表格的行中添加虚拟数字,以便更好地填充列“密度”。显示两种情况:
- 第二列仍然是
l
类型` - 第二列是
p{...}
您想要的类型。
\documentclass[8pt]{IEEEtran}
\usepackage{rotating}
\usepackage{booktabs, makecell, threeparttable}
\renewcommand\theadfont{\bfseries}
\usepackage{siunitx}
\begin{document}
\begin{table*}
\centering
\setlength\tabcolsep{0pt}
\renewcommand\arraystretch{1.1}
\settowidth\rotheadsize{\theadfont Avg. time 3\tnote{2}}
\begin{threeparttable}
\caption{Results}
\label{tab:tb1}
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}
l
l@{\qquad}
S[table-format=2.3]@{\qquad}
*{9}{S[table-format=2.3]} }
\toprule
\rothead{Name}
& {\rothead{Category}}
& {\rothead{Size\tnote{1}}}
& {\rothead{Number of vertices}}
& {\rothead{Number of edges}}
& {\rothead{std. dev}}
& {\rothead{Avg. degree}}
& {\rothead{Avg. diameter}}
& {\rothead{Avg. time 1\tnote{2}}}
& {\rothead{Avg. time 2}}
& {\rothead{Avg. time 3}}
& {\rothead{twelfth column}}\\
\midrule
I-SB0-SWR0 & {---} & 9.670 & 6.383 & 4.587 & 9.896 & {---} & {---} & {---} & {---} & {---} & {---} \\
II-SB4-SWR0 & 4 Steel Bars \O 6 mm
& 15.80 & 9.966 & 5.10 & 15.451 & 56.133 & {---} & {---} & {---} & {---} & {---} \\
III-SB0-SWR4 & 4 P-SWRs \O 3 mm
& 14.650 & 9.369 & 5.338 & 14.525 & 46.776 & {---} & {---} & {---} & {---} & {---} \\
IV-SB2-SWR2 & 2 Steel Bars \O 6 mm and 2 P-SWRs \O 3 mm
& 15.240 & 9.680 & 5.748 & 15.0 & 51.576 & {---} & {---} & {---} & {---} & {---} \\
V-SB0-SWR8 & 8 P-SWRs \O 3 mm
& 19.490 & 12.050& 7.720 & 18.682 & 88.783 & 12.345 & 12.345 & 12.345 & 12.345 & 12.345\\
\bottomrule
\end{tabular*}
\begin{tablenotes}
\item[1] In MB
\item[2] In ms
\end{tablenotes}
\end{threeparttable}
\end{table*}
\begin{table*}
\centering
\setlength\tabcolsep{0pt}
\renewcommand\arraystretch{1.1}
\settowidth\rotheadsize{\theadfont Avg. time 3\tnote{2}}
\begin{threeparttable}
\caption{Results}
\label{tab:tb2}
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}
l
>{\raggedright}p{10em}@{\qquad}
S[table-format=2.3]@{\qquad}
*{9}{S[table-format=2.3]} }
\toprule
\rothead{Name}
& {\rothead{Category}}
& {\rothead{Size\tnote{1}}}
& {\rothead{Number of vertices}}
& {\rothead{Number of edges}}
& {\rothead{std. dev}}
& {\rothead{Avg. degree}}
& {\rothead{Avg. diameter}}
& {\rothead{Avg. time 1\tnote{2}}}
& {\rothead{Avg. time 2}}
& {\rothead{Avg. time 3}}
& {\rothead{twelfth column}}\\
\midrule
I-SB0-SWR0 & {---} & 9.670 & 6.383 & 4.587 & 9.896 & {---} & {---} & {---} & {---} & {---} & {---} \\
II-SB4-SWR0 & 4 Steel Bars \O 6 mm
& 15.80 & 9.966 & 5.10 & 15.451 & 56.133 & {---} & {---} & {---} & {---} & {---} \\
III-SB0-SWR4 & 4 P-SWRs \O 3 mm
& 14.650 & 9.369 & 5.338 & 14.525 & 46.776 & {---} & {---} & {---} & {---} & {---} \\
IV-SB2-SWR2 & 2 Steel Bars \O 6 mm and 2 P-SWRs \O 3 mm
& 15.240 & 9.680 & 5.748 & 15.0 & 51.576 & {---} & {---} & {---} & {---} & {---} \\
V-SB0-SWR8 & 8 P-SWRs \O 3 mm
& 19.490 & 12.050& 7.720 & 18.682 & 88.783 & 12.345 & 12.345 & 12.345 & 12.345 & 12.345\\
\bottomrule
\end{tabular*}
\begin{tablenotes}
\item[1] In MB
\item[2] In ms
\end{tablenotes}
\end{threeparttable}
\end{table*}
\end{document}
答案2
如果允许在列标题内换行,则无需旋转它们:
\documentclass[8pt]{IEEEtran}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{amssymb}
\usepackage{mathtools}
\DeclarePairedDelimiter\ceil{\lceil}{\rceil}
\usepackage[usenames]{color}
\usepackage{graphicx}
\usepackage{tcolorbox}
\tcbuselibrary{listingsutf8}
\usepackage{ragged2e}
\usepackage{booktabs, tabularx, threeparttable}
\usepackage{siunitx}
\newsavebox\mysavebox
\usepackage{makecell}
\renewcommand{\theadfont}{\bfseries}
\begin{document}
\begin{table*}
\centering
\begin{threeparttable}
\caption{Results}
\label{tab:tb1}
\begin{tabularx}{\linewidth}{ l >{\raggedright\arraybackslash}X *{9}{S[table-format=2.3]} }
\toprule
{\thead[l]{Name}}
& {\thead[l]{Category}}
& {\thead{Size\tnote{1}}}
& {\thead{No. of\\vertices}}
& {\thead{No. of\\edges}}
& {\thead{std. dev}}
& {\thead{Avg.\\degree}}
& {\thead{Avg.\\diameter}}
& {\thead{Avg.\\time 1\tnote{2}}}
& {\thead{Avg.\\time 2}}
& {\thead{Avg.\\time 3}} \\
\midrule
I-SB0-SWR0 & {---} & 9.670 & 6.383 & 4.587 & 9.896 & {---} & {---} & {---} & {---} & {---} \\
II-SB4-SWR0 & 4 Steel Bars \O{} \SI{6}{\mm}
& 15.80 & 9.966 & 5.10 & 15.451 & 56.133 & {---} & {---} & {---} & {---} \\
III-SB0-SWR4 & 4 P-SWRs \O{} \SI{3}{\mm}
& 14.650 & 9.369 & 5.338 & 14.525 & 46.776 & {---} & {---} & {---} & {---}\\
IV-SB2-SWR2 & 2 Steel Bars \O{} \SI{6}{\mm} and 2 P-SWRs \O{} \SI{3}{\mm}
& 15.240 & 9.680 & 5.748 & 15.0 & 51.576 & {---} & {---} & {---} & {---}\\
V-SB0-SWR8 & 8 P-SWRs \O{} \SI{3}{\mm}
& 19.490 & 12.050& 7.720 & 18.682 & 88.783 & {---} & {---} & {---} & {---}\\
\bottomrule
\end{tabularx}
\begin{tablenotes}
\item[1] In MB
\item[2] In ms
\end{tablenotes}
\end{threeparttable}
\end{table*}
\end{document}
第 3 列周围有更多水平空间:
\documentclass[8pt]{IEEEtran}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{amssymb}
\usepackage{mathtools}
\DeclarePairedDelimiter\ceil{\lceil}{\rceil}
\usepackage[usenames]{color}
\usepackage{graphicx}
\usepackage{tcolorbox}
\tcbuselibrary{listingsutf8}
\usepackage{ragged2e}
\usepackage{booktabs, tabularx, threeparttable}
\usepackage{siunitx}
\newsavebox\mysavebox
\usepackage{makecell}
\renewcommand{\theadfont}{\bfseries}
\begin{document}
\begin{table*}
\sisetup{table-format=2.3}
\centering
\begin{threeparttable}
\caption{Results}
\label{tab:tb1}
\begin{tabularx}{\linewidth}{ l >{\raggedright\arraybackslash}X @{\hspace{4\tabcolsep} }S @{\hspace{4\tabcolsep}} S*{8}{S}}
\toprule
{\thead[l]{Name}}
& {\thead[l]{Category}}
& {\thead{Size\tnote{1}}}
& {\thead{No. of\\vertices}}
& {\thead{No. of\\edges}}
& {\thead{std. dev}}
& {\thead{Avg.\\degree}}
& {\thead{Avg.\\diameter}}
& {\thead{Avg.\\time 1\tnote{2}}}
& {\thead{Avg.\\time 2}}
& {\thead{Avg.\\time 3}} \\
\midrule
I-SB0-SWR0 & {---} & 9.670 & 6.383 & 4.587 & 9.896 & {---} & {---} & {---} & {---} & {---} \\
II-SB4-SWR0 & 4 Steel Bars \O{} \SI{6}{\mm}
& 15.80 & 9.966 & 5.10 & 15.451 & 56.133 & {---} & {---} & {---} & {---} \\
III-SB0-SWR4 & 4 P-SWRs \O{} \SI{3}{\mm}
& 14.650 & 9.369 & 5.338 & 14.525 & 46.776 & {---} & {---} & {---} & {---}\\
IV-SB2-SWR2 & 2 Steel Bars \O{} \SI{6}{\mm} and 2 P-SWRs \O{} \SI{3}{\mm}
& 15.240 & 9.680 & 5.748 & 15.0 & 51.576 & {---} & {---} & {---} & {---}\\
V-SB0-SWR8 & 8 P-SWRs \O{} \SI{3}{\mm}
& 19.490 & 12.050& 7.720 & 18.682 & 88.783 & {---} & {---} & {---} & {---}\\
\bottomrule
\end{tabularx}
\begin{tablenotes}
\item[1] In MB
\item[2] In ms
\end{tablenotes}
\end{threeparttable}
\end{table*}
\end{document}