[Tex/LaTex] Tabular* environment stretching table more than page width

tables

I am using trying to use the tabular* environment to stretch a table to the page width. However the table gets stretched more than the page width defined on the preamble …

Here's my code:

\documentclass[12pt,a4paper]{article}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{siunitx}
\usepackage{booktabs}
\usepackage{natbib}
\usepackage{url}
\usepackage{float}
\usepackage{placeins}
\usepackage[font=small,labelfont=bf,margin=\parindent,tableposition=top]{caption}

\setcounter{MaxMatrixCols}{10}


\addtolength{\oddsidemargin}{-.875in}
\addtolength{\evensidemargin}{-.875in}
\addtolength{\textwidth}{1.75in}
\addtolength{\topmargin}{-.875in}
\addtolength{\textheight}{1.50in}

\parskip = 0pt
\pagestyle{plain}
\setlength{\parskip}{.0in}
\renewcommand{\baselinestretch}{1.3}
\newcommand{\figref}[1]{Figure~\ref{#1}}
\newcommand{\tabref}[1]{Table~\ref{#1}}
\newcommand{\secref}[1]{Section~\ref{#1}}
\newcommand{\eqnref}[1]{equation (\ref{#1})}
\newcommand{\chapref}[1]{Chapter~\ref{#1}}

\newenvironment{Question}[2][Question]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}


    \FloatBarrier
\begin{table}[!htbp]

  \centering
  \caption{AAAA}
  \caption*{AAAA}
  \setlength\tabcolsep{0pt}
    \begin{tabular*}{\textwidth}{l @{\extracolsep{\fill}} cccccll}
    \hline
\hline
\multicolumn{8}{c}{Panel A:}                                                                                                     \\ \hline
   & $\delta_1$           & t-stat               &                      & $\delta_2$           & t-stat               &  & $R^2$ \\ \cline{2-3} \cline{5-6} \cline{8-8} 
1  & -0.06                & -0.40                &                      & 0.8                  & 16.0                 &  & 0.05  \\
2  & 0.04                 & 0.23                 &                      & 3.3                  & 54.3                 &  & 0.39  \\
3  & 0.03                 & 0.19                 &                      & 1.7                  & 41.0                 &  & 0.27  \\
4  & 0.17                 & 0.89                 &                      & 2.2                  & 36.0                 &  & 0.22  \\
5  & 0.12                 & 0.88                 &                      & 1.2                  & 28.0                 &  & 0.15  \\
6  & 0.02                 & 0.13                 &                      & -1.9                 & -32.7                &  & 0.19  \\
7  & 0.04                 & 0.40                 &                      & 0.2                  & 5.9                  &  & 0.01  \\
8  & 0.13                 & 0.61                 &                      & 1.9                  & 27.2                 &  & 0.14  \\
9  & -0.02                & -0.22                &                      & -0.5                 & -14.8                &  & 0.05  \\
10 & 0.14                 & 1.11                 &                      & 0.3                  & 6.8                  &  & 0.01  \\
11 & -0.21                & -1.14                &                      & 0.5                  & 8.7                  &  & 0.02  \\
12 & -0.22                & -2.16                &                      & 0.4                  & 12.5                 &  & 0.03  \\ \hline
   & \multicolumn{1}{l}{} & \multicolumn{1}{l}{} & \multicolumn{1}{l}{} & \multicolumn{1}{l}{} & \multicolumn{1}{l}{} &  &       \\
   & \multicolumn{1}{l}{} & \multicolumn{1}{l}{} & \multicolumn{1}{l}{} & \multicolumn{1}{l}{} & \multicolumn{1}{l}{} &  &       \\ \hline
\multicolumn{8}{c}{Panel B:}                                                                                                     \\ \hline
   & $\delta_1$           & t-stat               &                      & $\delta_2$           & t-stat               &  & $R^2$ \\ \cline{2-3} \cline{5-6} \cline{8-8} 
1  & -0.13                & -0.58                &                      & 3.83                 & 55.00                &  & 0.40  \\
2  & -0.02                & -0.17                &                      & 2.35                 & 49.92                &  & 0.35  \\
3  & -0.05                & -0.39                &                      & 1.66                 & 40.55                &  & 0.26  \\
4  & -0.09                & -1.19                &                      & 0.79                 & 33.25                &  & 0.19  \\
5  & 0.00                 & 0.13                 &                      & -0.44                & -37.38               &  & 0.23  \\ \hline
   & \multicolumn{1}{l}{} & \multicolumn{1}{l}{} & \multicolumn{1}{l}{} & \multicolumn{1}{l}{} & \multicolumn{1}{l}{} &  &       \\
   & \multicolumn{1}{l}{} & \multicolumn{1}{l}{} & \multicolumn{1}{l}{} & \multicolumn{1}{l}{} & \multicolumn{1}{l}{} &  &       \\ \hline
\multicolumn{8}{c}{Panel C:}                                                                                                     \\ \hline
   & $\delta_1$           & t-stat               &                      & $\delta_2$           & t-stat               &  & $R^2$ \\ \cline{2-3} \cline{5-6} \cline{8-8} 
1  & 0.07                 & 0.76                 &                      & -0.91                & -32.58               &  & 0.19  \\
2  & 0.04                 & 0.61                 &                      & 0.05                 & 2.24                 &  & 0.00  \\
3  & -0.05                & -0.65                &                      & 0.38                 & 14.25                &  & 0.04  \\
4  & -0.01                & -0.16                &                      & 0.69                 & 25.03                &  & 0.12  \\
5  & -0.10                & -0.60                &                      & 2.00                 & 37.21                &  & 0.23  \\ \hline
\end{tabular*}

  \label{tab:Reg1}%
\end{table}%

Best Answer

When using the @{\extracolsep{\fill}} device, LaTeX sets the width of each intercolumn space to 2\tabcolsep+\fill. The default value of \tabcolsep, at least in most document classes I'm familiar with, is 6pt.

If the "natural" width of the tabular* environment, i.e., with \fill=0pt (note: \fill can not be negative), exceeds the width of the text block, three possible remedies should be considered:

  • Eliminate the whitespace to the left of the first column and to the right of the final column (total savings: 2\tabcolsep);

  • Execute the instruction \setlength\tabcolsep{0pt}. That way, each intercolumn whitespace is equal to \fill; and

  • Reduce the font size, e.g., by executing an instruction such as \small or \footnotesize.

The code below shows the results of using a tabular* with 14 instead of "just" 6 data columns to create an example of the table's width exceeding that of the text block. The first tabular* environment uses the default value of \tabcolsep, whereas the second uses \tabcolsep=0pt.

enter image description here

\documentclass{article}
\usepackage{booktabs,caption}
\begin{document}
\begin{table}[!htbp]
    \caption{\texttt{\textbackslash tabcolsep=6pt} (default)} \label{tab:default}
    \begin{tabular*}{\textwidth}{@{} l @{\extracolsep{\fill}} *{14}{c} @{}}
    \toprule
    & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14  \\
    \midrule
    \textbf{Historical } \\
    Lab1 & 1.0 & 1.0 & 1.0 & 1.0 & 1.0 & 1.0 & 1.0 & 1.0 & 1.0 & 1.0 & 1.0 & 1.0& 1.0 & 1.0 \\
    Lab2 & 1.0 & 1.0 & 1.0 & 1.0 & 1.0 & 1.0 & 1.0 & 1.0 & 1.0 & 1.0 & 1.0 & 1.0& 1.0 & 1.0 \\
    \bottomrule
    \end{tabular*}

    \bigskip\bigskip
    \setlength\tabcolsep{0pt} % default: 6pt
    \caption{\texttt{\textbackslash tabcolsep=0pt}} \label{tab:alt}
    \begin{tabular*}{\textwidth}{l @{\extracolsep{\fill}} *{14}{c} }
    \toprule
    & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14  \\
    \midrule
    \textbf{Historical } \\
    Lab1 & 1.0 & 1.0 & 1.0 & 1.0 & 1.0 & 1.0 & 1.0 & 1.0 & 1.0 & 1.0 & 1.0 & 1.0& 1.0 & 1.0 \\
    Lab2 & 1.0 & 1.0 & 1.0 & 1.0 & 1.0 & 1.0 & 1.0 & 1.0 & 1.0 & 1.0 & 1.0 & 1.0& 1.0 & 1.0 \\
    \bottomrule
    \end{tabular*}
\end{table}

\end{document} 

Addendum, posted after the OP augmented his/her posting to show a "real" table: Not sure what your concern is about the tabular material not fitting in the width of the text block. I did notice, though, that the table is too tall to fit into the text block. However, that's because you've changed the lowel-level TeX macro \baselineskip. Instead of modifying \baselineskip directly, I would load the setstretch package and issue the command \setstretch{1.3}; that way, material in footnotes, tables, and arrays will not be stretched vertically.

Your table has two unneeded column and a lot of unnecessary statements, c.f., all those \multicolumn{1}{l}{} directives. With some clean-up, replacing all \hline directives with \midrules and all \cline statements with \cmdirules, and using the dcolumn package to align numeric data on the respective decimal markers, one gets:

enter image description here

\documentclass[12pt,a4paper]{article}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{siunitx}
\usepackage{booktabs}
\usepackage{natbib}
\usepackage{url}
\usepackage{float}
\usepackage{placeins}
\usepackage[font=small,labelfont=bf,margin=\parindent,tableposition=top]{caption}

%\setcounter{MaxMatrixCols}{10}

%\usepackage[showframe]{geometry}


\addtolength{\oddsidemargin}{-.875in}
\addtolength{\evensidemargin}{-.875in}
\addtolength{\textwidth}{1.75in}
\addtolength{\topmargin}{-.875in}
\addtolength{\textheight}{1.50in}


\parskip = 0pt
\pagestyle{plain}
\setlength{\parskip}{.0in}
%\renewcommand{\baselinestretch}{1.3}

\usepackage{setspace}
\setstretch{1.3}

\usepackage{dcolumn}
\newcolumntype{d}[1]{D..{#1}}

\newcommand{\mc}[1]{\multicolumn{1}{c}{#1}}

\newcommand{\figref}[1]{Figure~\ref{#1}}
\newcommand{\tabref}[1]{Table~\ref{#1}}
\newcommand{\secref}[1]{Section~\ref{#1}}
\newcommand{\eqnref}[1]{equation (\ref{#1})}
\newcommand{\chapref}[1]{Chapter~\ref{#1}}

\newenvironment{Question}[2][Question]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}
\begin{document}

    \FloatBarrier
\begin{table}[!htbp]

  %%\centering
  \caption{AAAA}
  \caption*{AAAA}
  \setlength\tabcolsep{0pt}
    \begin{tabular*}{\textwidth}{l @{\extracolsep{\fill}} *{5}{d{2.2}}}
\midrule
\multicolumn{6}{c}{Panel A:}\\ 
\midrule
& \mc{$\delta_1$} & \mc{t-stat}  & \mc{$\delta_2$} & \mc{t-stat} &  \mc{$R^2$} \\ 
   \cmidrule{2-3} \cmidrule{4-5} \cmidrule{6-6} 
1  & -0.06 & -0.40 & 0.8   & 16.0  &  0.05  \\
2  & 0.04  & 0.23  & 3.3   & 54.3  &  0.39  \\
3  & 0.03  & 0.19  & 1.7   & 41.0  &  0.27  \\
4  & 0.17  & 0.89  & 2.2   & 36.0  &  0.22  \\
5  & 0.12  & 0.88  & 1.2   & 28.0  &  0.15  \\
6  & 0.02  & 0.13  & -1.9  & -32.7 &  0.19  \\
7  & 0.04  & 0.40  & 0.2   & 5.9   &  0.01  \\
8  & 0.13  & 0.61  & 1.9   & 27.2  &  0.14  \\
9  & -0.02 & -0.22 & -0.5  & -14.8 &  0.05  \\
10 & 0.14  & 1.11  & 0.3   & 6.8   &  0.01  \\
11 & -0.21 & -1.14 & 0.5   & 8.7   &  0.02  \\
12 & -0.22 & -2.16 & 0.4   & 12.5  &  0.03  \\ 
\midrule
\\ \\ 
\midrule
\multicolumn{6}{c}{Panel B:}\\ 
\midrule
& \mc{$\delta_1$} & \mc{t-stat}  & \mc{$\delta_2$} & \mc{t-stat} &  \mc{$R^2$} \\ 
\cmidrule{2-3} \cmidrule{4-5} \cmidrule{6-6} 
1  & -0.13 & -0.58 & 3.83  & 55.00 &  0.40  \\
2  & -0.02 & -0.17 & 2.35  & 49.92 &  0.35  \\
3  & -0.05 & -0.39 & 1.66  & 40.55 &  0.26  \\
4  & -0.09 & -1.19 & 0.79  & 33.25 &  0.19  \\
5  & 0.00  & 0.13  & -0.44 & -37.38 &  0.23  \\ 
\midrule
\\ \\ 
\midrule
\multicolumn{6}{c}{Panel C:}\\ 
\midrule
& \mc{$\delta_1$} & \mc{t-stat}  & \mc{$\delta_2$} & \mc{t-stat} &  \mc{$R^2$} \\ 
\cmidrule{2-3} \cmidrule{4-5} \cmidrule{6-6} 
1  & 0.07  & 0.76  & -0.91 & -32.58 &  0.19  \\
2  & 0.04  & 0.61  & 0.05  & 2.24  &  0.00  \\
3  & -0.05 & -0.65 & 0.38  & 14.25 &  0.04  \\
4  & -0.01 & -0.16 & 0.69  & 25.03 &  0.12  \\
5  & -0.10 & -0.60 & 2.00  & 37.21 &  0.23  \\
\midrule
\end{tabular*}

  \label{tab:Reg1}%
\end{table}%
\end{document}