我怎样才能使这张表看起来比这更漂亮、更优雅?你认为最好将它放在一列还是两列中?如果你认为这样更好,我也愿意让它跨越两列。
\documentclass[10pt,conference]{IEEEtran}
\IEEEoverridecommandlockouts
\usepackage{cite}
\usepackage{amsmath,amssymb,amsfonts}
\usepackage{algorithmic}
\usepackage{algorithm}
\usepackage{graphicx}
\usepackage{changepage}
%\usepackage{algpseudocode}
\usepackage{lipsum}
\usepackage{ctable}% http://ctan.org/pkg/ctable
\usepackage{color, colortbl}
\newcommand{\var}{\textit}
\newcommand{\proc}{\textbf}
\newcommand{\prop}{\texttt}
\newcommand{\plusplus}{{+}{+}}% Other options:
\newcommand*\ita[1]{\textit{#1}}
%\usepackage{xcolor} % changed
\usepackage{array, booktabs, makecell, multirow}% new
\definecolor{Gray}{gray}{0.9}
\usepackage{textcomp}
\usepackage{booktabs}
\newcommand\mytab[1]{\begin{tabular}[t]{@{}c@{}} #1 \end{tabular}}
\newcommand\mc[2]{\multicolumn{#1}{c}{#2}}
\renewcommand{\algorithmiccomment}[1]{//#1}
\def\BibTeX{{\rm B\kern-.05em{\sc i\kern-.025em b}\kern-.08em
T\kern-.1667em\lower.7ex\hbox{E}\kern-.125emX}}
\begin{document}
\begin{table}[]
\caption{XCallers and XCallees for Methods in Figure}
\label{tab:XCallersXCalleesExample}
\begin{tabular}{|c|c|c|c|c|c|c|c|}
\hline
\textbf{Method\#} & \textbf{1-StartGPS} & \textbf{2-Start} &
\textbf{\begin{tabular}[c]{@{}c@{}}3-Reserve\\ Seat\end{tabular}} &
\textbf{\begin{tabular}[c]{@{}c@{}}4-Set\\ Passenger\\ Info\end{tabular}} &
\textbf{5-Start} & \textbf{\begin{tabular}[c]{@{}c@{}}6-Book\\
Ticket\end{tabular}} & \textbf{\begin{tabular}[c]{@{}c@{}}7-Book\\
Ticket\end{tabular}} \\ \hline
\textbf{XCallers} & \begin{tabular}[c]{@{}c@{}}2-Start \\ 5-
Start\end{tabular} & Empty & \begin{tabular}[c]{@{}c@{}}6-BookTicket \\ 7-
BookTicket\end{tabular} & Empty & Empty & \begin{tabular}[c]{@{}c@{}}4-
Set\\ Passenger\\ Info\end{tabular} & \begin{tabular}[c]{@{}c@{}}4-Set\\
Passenger\\ Info\end{tabular} \\ \hline
\textbf{XCallees} & Empty & 1-StartGPS & Empty & \begin{tabular}[c]
{@{}c@{}}6-BookTicket \\ 7-BookTicket\end{tabular} & 1-StartGPS & 3-
ReserveSeat & 3-ReserveSeat \\ \hline
\end{tabular}
\end{table}
\end{document}
答案1
什么是好看的表格是个人观点。显然(从您上一个问题的接受答案来看)您不喜欢专业外观的表格。
无论如何,正如我在评论中告诉你的那样,你的表格太宽了,无法放入一列。因此,根据我的口味我建议你把它写在两栏中,如下所示:
\documentclass[10pt,conference]{IEEEtran}
\IEEEoverridecommandlockouts
\usepackage{textcomp}
\usepackage{booktabs, makecell, multirow, tabularx}
\renewcommand\theadfont{\small\bfseries}
\renewcommand\theadgape{}
\usepackage{stfloats}
\usepackage{lipsum}
\begin{document}
\lipsum[1]
\begin{table*}[b]
\centering
\caption{XCallers and XCallees for Methods in Figure}
\label{tab:XCallersXCalleesExample}
\begin{tabular}{>{\bfseries}l *{7}{c}}
\toprule
\thead[bl]{Method \#}
& \thead[b]{StartGPS} & \thead[b]{Start}
& \thead[b]{Reserve Seat} & \thead[b]{Set\\ Passenger Info}
& \thead[b]{Start} & \thead[b]{Book Ticket}
& \thead[b]{Book Ticket} \\
& (1) & (2) & (3) & (4) & (5) & (6) & (7) \\
\midrule
XCallers
& \makecell{2-Start\\
5-Start} & Empty
& \makecell{6-BookTicket\\
7-BookTicket} & Empty
& Empty & 4-Set Passenger Info
& 4-Set Passenger Info \\
\addlinespace
XCallees
& Empty & 1-StartGPS
& Empty & \makecell{6-BookTicket\\
7-BookTicket}
& 1-StartGPS & 3-ReserveSeat
& 3-ReserveSeat \\
\bottomrule
\end{tabular}
\end{table*}
\lipsum
\end{document}
或者考虑第二种可能性:交换表中的行和列:
\documentclass[10pt,conference]{IEEEtran}
\IEEEoverridecommandlockouts
\usepackage{textcomp}
\usepackage{booktabs, makecell, multirow, tabularx}
\setcellgapes{2pt}
\renewcommand\theadfont{\small\bfseries}
\renewcommand\theadgape{}
\usepackage{stfloats}
\usepackage{lipsum}
\begin{document}
\lipsum[1]
\begin{table}[htb]
\centering
\makegapedcells
\caption{XCallers and XCallees for Methods in Figure}
\label{tab:XCallersXCalleesExample}
\begin{tabular}{>{\bfseries}l ll }
\toprule
Method \# & \thead{XCallers} & \thead{XCallees} \\
\midrule
1-StartGPS & \makecell[tl]{2-Start\\
5-Start}& Empty \\
2-Start & Empty & 1-StartGPS \\
3-Reserve Seat & \makecell[tl]{6-BookTicket\\
4-Set Passenger Info}
& Empty \\
4-Start & Empty & 4-Set Passenger Info \\
5-Start & Empty & 1-StartGPS \\
6-Book Ticket & 4-Set Passenger Info & 3-ReserveSeat \\
7-Book Ticket & 4-Set Passenger Info & 3-ReserveSeat \\
\bottomrule
\end{tabular}
\end{table}
\lipsum
\end{document}
答案2
这是我简单的建议。%<----adding
你可以看到我的改变。最重要的是使用来\resizebox
减小表格的大小。
\documentclass[10pt,conference]{IEEEtran}
\IEEEoverridecommandlockouts
\usepackage{cite}
\usepackage{amsmath,amssymb,amsfonts}
\usepackage{algorithmic}
\usepackage{algorithm}
\usepackage{graphicx}
\usepackage{changepage}
\usepackage{lipsum}%<-------------------adding
%\usepackage{algpseudocode}
\usepackage{lipsum}
\usepackage{ctable}% http://ctan.org/pkg/ctable
\usepackage{color, colortbl}
\newcommand{\var}{\textit}
\newcommand{\proc}{\textbf}
\newcommand{\prop}{\texttt}
\newcommand{\plusplus}{{+}{+}}% Other options:
\newcommand*\ita[1]{\textit{#1}}
%\usepackage{xcolor} % changed
\usepackage{array, booktabs, makecell, multirow}% new
\definecolor{Gray}{gray}{0.9}
\usepackage{textcomp}
\usepackage{booktabs}
\newcommand\mytab[1]{\begin{tabular}[t]{@{}c@{}} #1 \end{tabular}}
\newcommand\mc[2]{\multicolumn{#1}{c}{#2}}
\renewcommand{\algorithmiccomment}[1]{//#1}
\def\BibTeX{{\rm B\kern-.05em{\sc i\kern-.025em b}\kern-.08em
T\kern-.1667em\lower.7ex\hbox{E}\kern-.125emX}}
\begin{document}
\lipsum[1]
\begin{table}[]
\centering%<-------------------adding
\caption{XCallers and XCallees for Methods in Figure}
\label{tab:XCallersXCalleesExample}
\resizebox{0.45\textwidth}{!}{\begin{tabular}{|c|c|c|c|c|c|c|c|}%<-------------------adding
\hline
\textbf{Method\#} & \textbf{1-StartGPS} & \textbf{2-Start} &
\textbf{\begin{tabular}[c]{@{}c@{}}3-Reserve\\ Seat\end{tabular}} &
\textbf{\begin{tabular}[c]{@{}c@{}}4-Set\\ Passenger\\ Info\end{tabular}} &
\textbf{5-Start} & \textbf{\begin{tabular}[c]{@{}c@{}}6-Book\\
Ticket\end{tabular}} & \textbf{\begin{tabular}[c]{@{}c@{}}7-Book\\
Ticket\end{tabular}} \\ \hline
\textbf{XCallers} & \begin{tabular}[c]{@{}c@{}}2-Start \\ 5-
Start\end{tabular} & Empty & \begin{tabular}[c]{@{}c@{}}6-BookTicket \\ 7-
BookTicket\end{tabular} & Empty & Empty & \begin{tabular}[c]{@{}c@{}}4-
Set\\ Passenger\\ Info\end{tabular} & \begin{tabular}[c]{@{}c@{}}4-Set\\
Passenger\\ Info\end{tabular} \\ \hline
\textbf{XCallees} & Empty & 1-StartGPS & Empty & \begin{tabular}[c]
{@{}c@{}}6-BookTicket \\ 7-BookTicket\end{tabular} & 1-StartGPS & 3-
ReserveSeat & 3-ReserveSeat \\ \hline
\end{tabular}}
\end{table}
\lipsum[2-3]
\end{document}
答案3
不要尝试使用\resizebox
表格,这对用户来说是一个非常糟糕的建议,因为它会产生非常丑陋的结果。
如果您想保留这种布局(Zarko 的简洁布局要好得多),请手动选择较小的字体大小并减少列间空间:
\documentclass[10pt,conference]{IEEEtran}
\IEEEoverridecommandlockouts
\usepackage{cite}
\usepackage{amsmath,amssymb,amsfonts}
\usepackage{algorithmic}
\usepackage{algorithm}
\usepackage{graphicx}
\usepackage{changepage}
%\usepackage{algpseudocode}
\usepackage{lipsum}
\usepackage{ctable}% http://ctan.org/pkg/ctable
\usepackage{color, colortbl}
\newcommand{\var}{\textit}
\newcommand{\proc}{\textbf}
\newcommand{\prop}{\texttt}
\newcommand{\plusplus}{{+}{+}}% Other options:
\newcommand*\ita[1]{\textit{#1}}
%\usepackage{xcolor} % changed
\usepackage{array, booktabs, makecell, multirow}% new
\definecolor{Gray}{gray}{0.9}
\usepackage{textcomp}
\usepackage{booktabs}
\newcommand\mytab[1]{\begin{tabular}[t]{@{}c@{}} #1 \end{tabular}}
\newcommand\mc[2]{\multicolumn{#1}{c}{#2}}
\renewcommand{\algorithmiccomment}[1]{//#1}
\def\BibTeX{{\rm B\kern-.05em{\sc i\kern-.025em b}\kern-.08em
T\kern-.1667em\lower.7ex\hbox{E}\kern-.125emX}}
\begin{document}
\begin{table}[]
\caption{XCallers and XCallees for Methods in Figure}
\label{tab:XCallersXCalleesExample}
\tiny
\setlength{\tabcolsep}{2.7pt}
\begin{tabular}{|c|c|c|c|c|c|c|c|}
\hline
\textbf{Method\#} & \textbf{1-StartGPS} & \textbf{2-Start} &
\textbf{\begin{tabular}[c]{@{}c@{}}3-Reserve\\ Seat\end{tabular}} &
\textbf{\begin{tabular}[c]{@{}c@{}}4-Set\\ Passenger\\ Info\end{tabular}} &
\textbf{5-Start} & \textbf{\begin{tabular}[c]{@{}c@{}}6-Book\\
Ticket\end{tabular}} & \textbf{\begin{tabular}[c]{@{}c@{}}7-Book\\
Ticket\end{tabular}} \\ \hline
\textbf{XCallers} & \begin{tabular}[c]{@{}c@{}}2-Start \\ 5-
Start\end{tabular} & Empty & \begin{tabular}[c]{@{}c@{}}6-BookTicket \\ 7-
BookTicket\end{tabular} & Empty & Empty & \begin{tabular}[c]{@{}c@{}}4-
Set\\ Passenger\\ Info\end{tabular} & \begin{tabular}[c]{@{}c@{}}4-Set\\
Passenger\\ Info\end{tabular} \\ \hline
\textbf{XCallees} & Empty & 1-StartGPS & Empty & \begin{tabular}[c]
{@{}c@{}}6-BookTicket \\ 7-BookTicket\end{tabular} & 1-StartGPS & 3-
ReserveSeat & 3-ReserveSeat \\ \hline
\end{tabular}
\end{table}
\end{document}