一个booktabs问题:如何去掉空白列?

一个booktabs问题:如何去掉空白列?

我尝试制作如下表格: 在此处输入图片描述

但我不想要那些黑色空间,我怎样才能摆脱它们?(我仍然希望表格具有文本宽度)

我参考了 latex 代码 http://www.inf.ethz.ch/personal/markusp/teaching/guides/guide-tables.pdf帮助提供 booktabs 表

这是我的代码:

\documentclass{article}
\usepackage{booktabs,tabularx}
\usepackage[margin=1in]{geometry} % set margins to meet your document's needs
\newcolumntype{Y}{>{\raggedright\arraybackslash}X} 

\begin{document}
\begin{table}[t]
\caption{Minimum Requirements for Automatic Readmission 
  into the Commerce Faculty} \label{table:mr}
%\centering  % not needed, since table is as wide as text block
\begin{tabularx}{\textwidth}{rrcrrc}
\toprule
&\multicolumn{2}{c}{\bfseries BCom}
&\multicolumn{2}{c}{\bfseries B.Bus Sci} \\
\cmidrule(lr){2-3} 
\cmidrule(lr){4-5} 
& $N$ & $\%$ & $N$ & $\%$ 
\\\midrule
$dir=Dels$\\
$c$ & 0.0790 & 0.1692 & 0.2945 & 0.3670 \\
$c$ & -0.8651& 50.0476& 5.9384 & -9.0714& \\
$c$ & 124.2756& -50.9612& -14.2721& 128.2265&\\
$dir=0$\\
$c$ & 0.0357& 1.2473& 0.2119& 0.3593& \\
$c$ & -17.9048& -37.1111& 8.8591& -30.7381& \\
$c$ & 105.5518& 232.1160& -94.7351& 100.2497&\\
\bottomrule
\end{tabularx}
\end{table}
\end{document}

答案1

也许最简单的做法是将改为tabularxtabular*手动设置\tabcolsep为某个适当的值。

\documentclass{article}
\usepackage{booktabs,tabularx}
\usepackage[margin=1in]{geometry} % set margins to meet your document's needs
%\newcolumntype{Y}{>{\hspace{\fil}\raggedright\arraybackslash}X} 

\begin{document}
\begin{table}[t]
\caption{Minimum Requirements for Automatic Readmission 
  into the Commerce Faculty} \label{table:mr}
%\centering  % not needed, since table is as wide as text block
\tabcolsep=27.8pt\relax
\begin{tabular*}{\textwidth}{rrcrrc}
\toprule
&\multicolumn{2}{c}{\bfseries BCom}
&\multicolumn{2}{c}{\bfseries B.Bus Sci} \\
\cmidrule(lr){2-3} 
\cmidrule(lr){4-5} 
& $N$ & $\%$ & $N$ & $\%$ 
\\\midrule
$dir=Dels$\\
$c$ & 0.0790 & 0.1692 & 0.2945 & 0.3670 \\
$c$ & -0.8651& 50.0476& 5.9384 & -9.0714& \\
$c$ & 124.2756& -50.9612& -14.2721& 128.2265&\\
$dir=0$\\
$c$ & 0.0357& 1.2473& 0.2119& 0.3593& \\
$c$ & -17.9048& -37.1111& 8.8591& -30.7381& \\
$c$ & 105.5518& 232.1160& -94.7351& 100.2497&\\
\bottomrule
\end{tabular*}
\end{table}
\end{document}

在此处输入图片描述

答案2

我不明白为什么你想要一个宽度与文本宽度相同的表格。你可以使用常规的tabular而不是tabularx。但是,需求就是需求,其他人会决定它们。因此这里有一个选择。使用tabulary而不是tabularx

\documentclass{article}
\usepackage{booktabs,tabulary}
\usepackage[margin=1in]{geometry} % set margins to meet your document's needs
\newcolumntype{Y}{>{\raggedright\arraybackslash}X}

\begin{document}
\begin{table}[t]
\caption{Minimum Requirements for Automatic Readmission
  into the Commerce Faculty} \label{table:mr}
%\centering  % not needed, since table is as wide as text block
\begin{tabulary}{\textwidth}{rrcrrc}
\toprule
&\multicolumn{2}{c}{\bfseries BCom}
&\multicolumn{2}{c}{\bfseries B.Bus Sci} \\
\cmidrule(lr){2-3}
\cmidrule(lr){4-5}
& $N$ & $\%$ & $N$ & $\%$
\\\midrule
$dir=Dels$\\
$c$ & 0.0790 & 0.1692 & 0.2945 & 0.3670 \\
$c$ & -0.8651& 50.0476& 5.9384 & -9.0714& \\
$c$ & 124.2756& -50.9612& -14.2721& 128.2265&\\
$dir=0$\\
$c$ & 0.0357& 1.2473& 0.2119& 0.3593& \\
$c$ & -17.9048& -37.1111& 8.8591& -30.7381& \\
$c$ & 105.5518& 232.1160& -94.7351& 100.2497&\\
\bottomrule
\end{tabulary}
\end{table}

With just \verb|tabular|:

\begin{table}[htb]
\caption{Minimum Requirements for Automatic Readmission
  into the Commerce Faculty} \label{table:mr}
%\centering  % not needed, since table is as wide as text block
\begin{tabular}{rrcrrc}
\toprule
&\multicolumn{2}{c}{\bfseries BCom}
&\multicolumn{2}{c}{\bfseries B.Bus Sci} \\
\cmidrule(lr){2-3}
\cmidrule(lr){4-5}
& $N$ & $\%$ & $N$ & $\%$
\\\midrule
$dir=Dels$\\
$c$ & 0.0790 & 0.1692 & 0.2945 & 0.3670 \\
$c$ & -0.8651& 50.0476& 5.9384 & -9.0714& \\
$c$ & 124.2756& -50.9612& -14.2721& 128.2265&\\
$dir=0$\\
$c$ & 0.0357& 1.2473& 0.2119& 0.3593& \\
$c$ & -17.9048& -37.1111& 8.8591& -30.7381& \\
$c$ & 105.5518& 232.1160& -94.7351& 100.2497&\\
\bottomrule
\end{tabular}
\end{table}
\end{document}

在此处输入图片描述

或者我可能只是误解了这个问题(在看到 Steven 的回答之后)。您可以定义新的列,例如

\newcolumntype{Y}{>{\raggedleft\arraybackslash}X}
\newcolumntype{Z}{>{\centering\arraybackslash}X}

另外,您使用的是 5 列条目,但声明了 6 列。请像下面这样删除它们(即只有 5 列)。

\begin{tabularx}{\textwidth}{YYZYY}

代码:

\documentclass{article}
\usepackage{booktabs,tabularx}
\usepackage[margin=1in]{geometry} % set margins to meet your document's needs
\newcolumntype{Y}{>{\raggedleft\arraybackslash}X}
\newcolumntype{Z}{>{\centering\arraybackslash}X}

\begin{document}
\begin{table}[t]
\caption{Minimum Requirements for Automatic Readmission
  into the Commerce Faculty} \label{table:mr}
%\centering  % not needed, since table is as wide as text block
\begin{tabularx}{\textwidth}{YYZYY}
\toprule
&\multicolumn{2}{>{\hsize=2\hsize}Z}{\bfseries BCom}
&\multicolumn{2}{>{\hsize=2\hsize}Z}{\bfseries B.Bus Sci} \\
\cmidrule(lr){2-3}
\cmidrule(lr){4-5}
& $N$ & $\%$ & $N$ & $\%$
\\\midrule
$dir=Dels$\\
$c$ & 0.0790 & 0.1692 & 0.2945 & 0.3670 \\
$c$ & -0.8651& 50.0476& 5.9384 & -9.0714 \\
$c$ & 124.2756& -50.9612& -14.2721& 128.2265\\
$dir=0$\\
$c$ & 0.0357& 1.2473& 0.2119& 0.3593 \\
$c$ & -17.9048& -37.1111& 8.8591& -30.7381 \\
$c$ & 105.5518& 232.1160& -94.7351& 100.2497\\
\bottomrule
\end{tabularx}
\end{table}

\end{document}

在此处输入图片描述

相关内容