0

I made a table, but i would like to stretch it completely out to the width of the page. I used following code:
I appreciate all your help

\documentclass{article}
\usepackage{caption}
\usepackage{geometry}
\usepackage{tabulary}


\begin{document}
\begin{table}[]
\centering
\begin{tabulary}{\textwidth}{l @{\extracolsep{\fill}} ccccccc}
Variable                                                                               & Data & $\delta$     & t-stat & P\textgreater{}$|t|$ & P\textgreater F & $\overline{R}^2$   &      $\Delta\overline{R}^2$ \\ \hline
\textbf{\begin{tabular}[c]{@{}l@{}}Macroeconomic predictor\\   variables\end{tabular}} &           &        &                    &                     &        &            \\ \hline
Dividend-price ratio*                                                                   & 1871-2017 & -0,97 & -3,08  & 0,2                & 0,33                & 0,65   & 0,6        \\
Dividend yield*                                                                         & 1871-2017 & -0,98 & -3,11  & 0,2                & 0,32                & 0,73   & 0,64       \\
Earnings-price ratio**                                                                   & 1871-2017 & -0,80 & -2,61  & 0,9                & 1,91                & 0,65   & 0,46       \\
Dividend-earnings ratio**                                                                & 1871-2017 & -0,72 & -2,50  & 1,3                & 4,40                & 0,29   & 0,33       \\
Conditional variance***                                                                   & 1885-2017 & -0,73 & -2,31  & 2,1                & 6,96                & 0,25   & 0,31       \\
Book-to-market ratio***                                                                   & 1921-2017 & -0,91 & -1,54  & 12,4               & 9,84                & 0,72   & 0,33       \\
Cross-Sectional Premium                                                                & 1937-2017 & 0,18  & 0,35   & 72,6               & 21,73               & 0,14   & -0,11      \\
Net equity expansions***                                                                  & 1926-2017 & -0,56 & -0,85  & 39,4               & 7,48                & 0,44   & 0,07       \\
T-bill rate                                                                            & 1920-2017 & -0,64 & -1,13  & 25,7               & 36,87               & 0,07   & 0,14       \\
Long-term yield                                                                        & 1919-2017 & -0,59 & -1,07  & 28,4               & 52,22               & 0,03   & 0,11       \\
Long-term return**                                                                       & 1926-2017 & -0,59 & 1,07   & 28,4               & 3,39                & 0,32   & 0,18       \\
Term spread                                                                            & 1920-2017 & -0,62 & -1,10  & 27,2               & 29,69               & 0,1    & 0,13       \\
Default yield spread                                                                   & 1919-2017 & -0,94 & -1,69  & 9,1                & 20,45               & 0,42   & 0,34       \\
Default return spread                                                                  & 1926-2017 & -0,69 & -1,09  & 27,4               & 13,89               & 0,16   & 0,15       \\
Inflation***                                                                              & 1913-2017 & -0,75 & -1,51  & 13,1               & 5,04                & 0,3    & 0,25       \\ \hline
\textbf{Technical predictor variables}                                                 &           &       &        &                    &                     &        &            \\ \hline
Past return**                                                                            & 1871-2017 & -0,62 & -2,12  & 3,5                & 1,28                & 0,75   & 0,26       \\
Volatility*                                                                             & 1871-2017 & -0,80 & -2,67  & 0,8                & 0,24                & 0,7    & 0,46       \\
Momentum rule (12)***                                                                     & 1871-2017 & -0,68 & -2,25  & 2,5                & 6,58                & 0,29   & 0,31       \\
Simple Moving Average (10)**                                                             & 1871-2017 & -0,74 & -2,43  & 1,5                & 4,98                & 0,33   & -4,639     \\ \hline
\end{tabulary}
\caption{Badtimes}
\end{table}

\end{document}

enter image description here

EDIT: This is my table using tabular*, \hline is too long, and thats why i would like to strech colums outtabular*

  • I see that its current state is good enough. Why do you need to do that? – user156344 Apr 12 at 15:07
  • I think it looks good, but i think that stretching colums would make it easier readable – Filip Pierzgalski Apr 12 at 15:09
  • making the columns further apart would just make the table harder for your readers to read. Also \begin{tabulary}{\textwidth}{l @{\extracolsep{\fill}} ccccccc} should be \begin{tabular*}{\textwidth}{l @{\extracolsep{\fill}} ccccccc} as tabulary can not do anything with c columns or \extracolsep. – David Carlisle Apr 12 at 15:10
  • Thank for for your feedback JouleV and David Carlisle, i initially used tabular* , however i noticed that table looked weird. see picture – Filip Pierzgalski Apr 12 at 15:22
  • Thank you so much Bernard, this table is perfect! have a lovely day – Filip Pierzgalski Apr 12 at 16:47
1

Your table can fit the textwidth, with this simpler code, based on tabularx and siunitx, for an alignment of the numbers on the decimal comma (furthermore the minus sign won't be a hyphen dash!):

\documentclass{article}
\usepackage{caption}
\usepackage{geometry}
\usepackage{tabularx}
\usepackage{siunitx}

\begin{document}

\begin{table}[!htb]
\centering
\sisetup{copy-decimal-marker, table-number-alignment=center, table-format=-1.2}
\setlength{\extrarowheight}{2pt}
\setlength{\tabcolsep}{4pt}
\begin{tabularx}{\textwidth}{XcSSS[table-format=2.1]S[table-format=2.2]SS[table-format=-1.3]}
Variable & Data & {$\delta$} & {t-stat} & {P\textgreater{}$|t|$} & {P\textgreater F} & {$\overline{R}^2$} & {$\Delta\overline{R}^2$} \\ \hline
\multicolumn{2}{l}{\bfseries Macroeconomic predictor variables} \\ \hline
Dividend-price ratio* & 1871-2017 & -0,97 & -3,08 & 0,2 & 0,33 & 0,65 & 0,6 \\
Dividend yield* & 1871-2017 & -0,98 & -3,11 & 0,2 & 0,32 & 0,73 & 0,64 \\
Earnings-price ratio** & 1871-2017 & -0,80 & -2,61 & 0,9 & 1,91 & 0,65 & 0,46 \\
Dividend-earnings ratio** & 1871-2017 & -0,72 & -2,50 & 1,3 & 4,40 & 0,29 & 0,33 \\
Conditional variance*** & 1885-2017 & -0,73 & -2,31 & 2,1 & 6,96 & 0,25 & 0,31 \\
Book-to-market ratio*** & 1921-2017 & -0,91 & -1,54 & 12,4 & 9,84 & 0,72 & 0,33 \\
Cross-Sectional Premium & 1937-2017 & 0,18 & 0,35 & 72,6 & 21,73 & 0,14 & -0,11 \\
Net equity expansions*** & 1926-2017 & -0,56 & -0,85 & 39,4 & 7,48 & 0,44 & 0,07 \\
T-bill rate & 1920-2017 & -0,64 & -1,13 & 25,7 & 36,87 & 0,07 & 0,14 \\
Long-term yield & 1919-2017 & -0,59 & -1,07 & 28,4 & 52,22 & 0,03 & 0,11 \\
Long-term return** & 1926-2017 & -0,59 & 1,07 & 28,4 & 3,39 & 0,32 & 0,18 \\
Term spread & 1920-2017 & -0,62 & -1,10 & 27,2 & 29,69 & 0,1 & 0,13 \\
Default yield spread & 1919-2017 & -0,94 & -1,69 & 9,1 & 20,45 & 0,42 & 0,34 \\
Default return spread & 1926-2017 & -0,69 & -1,09 & 27,4 & 13,89 & 0,16 & 0,15 \\
Inflation*** & 1913-2017 & -0,75 & -1,51 & 13,1 & 5,04 & 0,3 & 0,25 \\ \hline
\multicolumn{2}{l}{\bfseries Technical predictor variables} \\ \hline
Past return** & 1871-2017 & -0,62 & -2,12 & 3,5 & 1,28 & 0,75 & 0,26 \\
Volatility* & 1871-2017 & -0,80 & -2,67 & 0,8 & 0,24 & 0,7 & 0,46 \\
Momentum rule (12)*** & 1871-2017 & -0,68 & -2,25 & 2,5 & 6,58 & 0,29 & 0,31 \\
Simple Moving Average (10)** & 1871-2017 & -0,74 & -2,43 & 1,5 & 4,98 & 0,33 & -4,639 \\ \hline
\end{tabularx}
\caption{Badtimes}
\end{table}

\end{document} 

enter image description here

1

in tabulary environment the macro @{\extracolsep{\fill}} doesn't work. in it you also need to use its column specifiers (L, C, R or J). Using them and removing @{\extracolsep{\fill}} you will almost obtain for what you after. however with tabular* (instead of the tabulary) table environment, using macro @{\extracolsep{\fill}} and S columns defined in the siunitx package ypo will obtain better result:

\documentclass{article}
\usepackage{geometry}
\usepackage{caption}
\usepackage{booktabs, makecell}
\usepackage{siunitx}
\usepackage{amsmath}

%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}
    \begin{table}[!htb]
    \centering
\sisetup{output-decimal-marker={,},
         table-auto-round,
         table-format=-1.2}
\setcellgapes{1pt}
\makegapedcells
\setlength{\tabcolsep}{0pt}
    \begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}
            lc SS SS SS}
Variable & Data & {$\delta$}  & {t-stat}
         & {$\text{P} > |t|$} & {$\text{P} > \text{F}$}
         & {$\overline{R}^2$} & {$\Delta\overline{R}^2$}            \\
    \midrule
\multicolumn{8}{l}{\bfseries Macroeconomic predictor variables}     \\
    \midrule
Dividend-price ratio*
        & 1871-2017 & -0,97 & -3,08 &  0,2 &  0,33 & 0,65 &  0,6    \\
Dividend yield*
        & 1871-2017 & -0,98 & -3,11 &  0,2 &  0,32 & 0,73 &  0,64   \\
Earnings-price ratio**
        & 1871-2017 & -0,80 & -2,61 &  0,9 &  1,91 & 0,65 &  0,46   \\
Dividend-earnings ratio**
        & 1871-2017 & -0,72 & -2,50 &  1,3 &  4,40 & 0,29 &  0,33   \\
Conditional variance***
        & 1885-2017 & -0,73 & -2,31 &  2,1 &  6,96 & 0,25 &  0,31   \\
Book-to-market ratio***
        & 1921-2017 & -0,91 & -1,54 & 12,4 &  9,84 & 0,72 &  0,33   \\
Cross-Sectional Premium
        & 1937-2017 &  0,18 &  0,35 & 72,6 & 21,73 & 0,14 & -0,11   \\
Net equity expansions***
        & 1926-2017 & -0,56 & -0,85 & 39,4 &  7,48 & 0,44 &  0,07   \\
T-bill rate
        & 1920-2017 & -0,64 & -1,13 & 25,7 & 36,87 & 0,07 &  0,14   \\
Long-term yield
        & 1919-2017 & -0,59 & -1,07 & 28,4 & 52,22 & 0,03 &  0,11   \\
Long-term return**
        & 1926-2017 & -0,59 &  1,07 & 28,4 &  3,39 & 0,32 &  0,18   \\
Term spread
        & 1920-2017 & -0,62 & -1,10 & 27,2 & 29,69 & 0,1  &  0,13   \\
Default yield spread
        & 1919-2017 & -0,94 & -1,69 &  9,1 & 20,45 & 0,42 &  0,34   \\
Default return spread
        & 1926-2017 & -0,69 & -1,09 & 27,4 & 13,89 & 0,16 &  0,15   \\
Inflation***
        & 1913-2017 & -0,75 & -1,51 & 13,1 &  5,04 & 0,3  &  0,25   \\
    \midrule
\multicolumn{8}{l}{\bfseries Technical predictor variables}         \\
    \midrule
Past return**
        & 1871-2017 & -0,62 & -2,12 &  3,5 &  1,28 & 0,75 &  0,26   \\
Volatility*
        & 1871-2017 & -0,80 & -2,67 &  0,8 &  0,24 & 0,7  &  0,46   \\
Momentum rule (12)***
        & 1871-2017 & -0,68 & -2,25 &  2,5 &  6,58 & 0,29 &  0,31   \\
Simple Moving Average (10)**
        & 1871-2017 & -0,74 & -2,43 &  1,5 &  4,98 & 0,33 & -4,639  \\
        \bottomrule
\end{tabular*}
\caption{Badtimes}
\end{table}

\end{document}

gives:

enter image description here

(red lines indicate page layout)

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.