3

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}%
  • 2
    Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – user31729 May 4 '15 at 12:43
  • 4
    stretching is just fine for me. Your missing MWE makes it unreproducable. – LaRiFaRi May 4 '15 at 12:56
  • Please could you complete your code so that it compiles? Start with \documentclass{.... If I complete your code in the obvious way, the tabular fits fine into the width of the text body - not one overfull box is mentioned in the log file. – cfr May 4 '15 at 19:35
  • It's fine with both A4 and US letter.... – cfr May 4 '15 at 19:40
  • 1
    Your tabular fits fine. This isn't surprising since your preamble increases the text width, so if the table fits in the standard case, it is bound to fit with your custom settings. By the way, you could minimise the code posted considerably e.g. remove the packages which aren't needed for the example. You are also missing \begin{document}...\end{document}. – cfr May 4 '15 at 21:17
3

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}
  • Hi, thanks for the answer. I have added : \setlength\tabcolsep{0pt} to the table but nothing changed ... – phdstudent May 4 '15 at 17:19
  • @volcompt - please post a more realistic example, one that illustrates the actual issues you're facing. With the tabular materiel you've posted so far, setting \tabcolsep to zero very much makes a difference. – Mico May 4 '15 at 17:38
  • Hi Mico, thanks. I have edited my post and included the full table. It does not matter whether I add \setlength\tabcolsep{0pt} or not, the table width is still bigger than the margins I am using. Thanks – phdstudent May 4 '15 at 17:56
  • @volcompt - I've provided an addendum to show how I would typeset your "real" table, while still using a tabular* environment. – Mico May 4 '15 at 23:00
2

Your table fits in the stated margins. This is what I get if I add \usepackage{showframe} and the missing \begin{document} and \end{document}

enter image description here

As you clearly see, it fits in the box representing the text block margins.


Here is how I'd typeset it: enlarging the table will simply make it unreadable.

\documentclass[12pt,a4paper]{article}
\usepackage{siunitx}
\usepackage{booktabs}
\usepackage[font=small,labelfont=bf,margin=\parindent,tableposition=top]{caption}

\begin{document}

\begin{table}[!htbp]
\centering
\caption{AAAA}\label{tab:Reg1}

\begin{tabular}{
  @{}
  r
  S[table-format=-1.2]
  S[table-format=-1.2]
  S[table-format=-1.2]
  S[table-format=-2.2]
  S[table-format=1.2]
  @{}
}
\toprule
\multicolumn{6}{c}{Panel A:} \\
\midrule
& {$\delta_1$} & {t-stat} & {$\delta_2$} & {t-stat} & {$R^2$} \\
\cmidrule(lr){2-3} \cmidrule(lr){4-5} \cmidrule(lr){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[\heavyrulewidth]
\multicolumn{6}{c}{Panel B:} \\
\midrule
& {$\delta_1$} & {t-stat} & {$\delta_2$} & {t-stat} & {$R^2$} \\
\cmidrule(lr){2-3} \cmidrule(lr){4-5} \cmidrule(lr){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[\heavyrulewidth]
\multicolumn{6}{c}{Panel C:} \\
\midrule
& {$\delta_1$} & {t-stat} & {$\delta_2$} & {t-stat} & {$R^2$} \\
\cmidrule(lr){2-3} \cmidrule(lr){4-5} \cmidrule(lr){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  \\
\bottomrule
\end{tabular}

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