1

I tried to make a table like this: enter image description here

But I don't want those black space, how can I get ride of them? (I still want the table to have text width )

I referred to the latex code of http://www.inf.ethz.ch/personal/markusp/teaching/guides/guide-tables.pdf and Help with a booktabs table

Here is my code:

\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}
3

Perhaps the easiest thing to do is to change the tabularx into a tabular* and manually set \tabcolsep to some appropriate value.

\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}

enter image description here

0

I don't understand why you want a table with a width of text width. You could have used the regular tabular instead of tabularx. However, needs are needs and somebody else will decide them. Hence here is an option. Use tabulary instead of 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}

enter image description here

Or I might have just misunderstood the question (after seeing Steven's answer). You can define new columns like

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

Also, you are using 5 columns entries but declaring 6 columns. Remove them like the following (i.e., just 5 columns).

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

Code:

\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}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.