# Table off the page

I know there is a plenty of resources that deal with tables off the page. And I tried all of them. And they all either do something undesirable, or are not working for me. Please help me position this table in the center of my work AND make the columns less wide.

Thank you!

\documentclass[paper=a4, fontsize=11pt]{scrartcl}
\usepackage[T1]{fontenc}
\usepackage{fourier}

\usepackage[english]{babel}                                                         % English language/hyphenation
\usepackage[protrusion=true,expansion=true]{microtype}
\usepackage{amsmath,amsfonts,amsthm}

\usepackage{url}
\usepackage{pgfplots} %for the drawing
\usepackage{chngpage}
\usepackage{sectsty}
\allsectionsfont{\centering \normalfont\scshape}

\usepackage{fancyhdr}
\pagestyle{fancyplain}
\fancyhead{}                                            % No page header
\fancyfoot[L]{}                                         % Empty
\fancyfoot[C]{}                                         % Empty
\fancyfoot[R]{\thepage}                                 % Pagenumbering
\renewcommand{\headrulewidth}{0pt}          % Remove header underlines
\renewcommand{\footrulewidth}{0pt}              % Remove footer underlines
\setlength{\headheight}{13.6pt}

%%% Equation and float numbering
\numberwithin{equation}{section}        % Equationnumbering: section.eq#
\numberwithin{figure}{section}          % Figurenumbering: section.fig#
\numberwithin{table}{section}               % Tablenumbering: section.tab#

%%% Maketitle metadata
\newcommand{\horrule}[1]{\rule{\linewidth}{#1}}     % Horizontal rule

\title{
%\vspace{-1in}
\usefont{OT1}{bch}{b}{n}
\normalfont \normalsize \textsc{XXX: XXX} \\ [5pt]
\normalfont \normalsize \textsc{Dr. XXX XXX} \\ [15pt]
\horrule{0.5pt} \\[0.4cm]
\huge Assignment 2\\
\horrule{2pt} \\[0.5cm]
}
\author{
\normalfont                                 \normalsize
XXX\\[-3pt]     \normalsize
\today
}
\date{}

%%% Begin document
\begin{document}
\maketitle

\section*{2.24}

Refer to Copier maintenance Problem 1.20.

a. Set up the basic ANOVA table in the format of Table 2.2. Which elements of your table are additive? Also set up the ANOVA table in the format of Table 2.3. How do the two tables differ?\\\\
%%%%%%
%Attach q2.24table to the end
%%%%%%
\textbf{Answer:}

First, we need to find values that will be used to construct the ANOVA table. Our initial step is taken to construct the following table (you can find the full table at the end of this homework):

\begin{table*} \small
\caption{Data  on Copier Maintenance needed for calculation}
\centering
\begin{tabular}{c c c c c c c c c c cc}
\hline\hline
&$X_i$ & $Y_i$ & $X_i-\bar{X}$ & $Y_i-\bar{Y}$ & $\hat{Y_i}$ & $Y_i-\hat{Y_i}$& $(X_i-\bar{X})^2$&$(Y_i-\bar{Y})^2$&$(Y_i-\hat{Y_i})^2$&$\hat{Y_i}-\bar{Y}$&$(\hat{Y_i}-\bar{Y})^2$\\ [0.5ex] % inserts table %heading
\hline
&2&20&-3.11&-56.27&29.48&-9.48&9.68&3165.94&89.87&-46.79&2188.99 \\
&4&60&-1.11&-16.27&59.54&0.46&1.23&264.60&0.21&-16.73&279.78 \\
&$\cdots$ &$\cdots$&$\cdots$&$\cdots$&$\cdots$&$\cdots$&$\cdots$&$\cdots$&$\cdots$&$\cdots$&$\cdots$ \\
&4 & 61 & -1.11&-15.27&59.54&1.46 &1.23& 233.07&2.13&-16.73&279.78\\
&5 & 77 & -0.11 & 0.73&74.57&2.43&0.01&0.54&5.90&-1.70&2.88 \\ [1ex]
\hline
\textbf{Total}&230 &3432 & 0 & 0&3430.80&1.20&340.44&80376.8&3416.41&-1.2&76906.74 \\
\textbf{Mean}&5.11 &76.27 &  &&& \\
\hline
\end{tabular}
\label{table:nonlin}
\end{table*}
\end{document}

• Just an idea: Try tabular enclosed with \resizebox{\textwidth}{!}{ and }. – pushpen.paul Sep 20 '14 at 19:51
• A \resizebox... for tables is only a last resort. I would just say, that your table is too large. Think of a landscape/sideway approach – user31729 Sep 20 '14 at 20:02

## 2 Answers

Some suggestions:

• Since the material in the table contains (mostly) math expressions, I'd use an array environment instead of a tabular environment. By having all cells automatically in math mode, unary minus symbols will be typeset correctly.

• Setting the parameter \arraycolsep, which governs the amount of intercolumn whitespace in array environments, to 2.8pt (or anything less than that) and eliminating the whitespace to the left of the first column and to the right of the final column should succeed in making the table/array fit inside the text block.

• I noticed you're trying to achieve some improvement in the spacing of the horizontal lines. Instead of trying to do so manually, I'd recommend using the commands \toprule, \midrule, and \bottomrule of the booktabs package. The second table in the screenshot below shows the result of using these macros instead of \hline (and \hline\hline).

\documentclass[paper=a4, fontsize=11pt]{scrartcl}
\usepackage[T1]{fontenc}
\usepackage{fourier}

\usepackage[english]{babel}                                                         % English language/hyphenation
\usepackage[protrusion=true,expansion=true]{microtype}
\usepackage{amsmath,amsfonts,amsthm}

\usepackage{url}
\usepackage{pgfplots} %for the drawing
\usepackage{chngpage}
\usepackage{sectsty}
\allsectionsfont{\centering \normalfont\scshape}
\usepackage{booktabs}  %% for \toprule, \midrule, and \bottomrule

\usepackage{fancyhdr}
\pagestyle{fancyplain}
\fancyhead{}                                            % No page header
\fancyfoot[L]{}                                         % Empty
\fancyfoot[C]{}                                         % Empty
\fancyfoot[R]{\thepage}                                 % Pagenumbering
\renewcommand{\headrulewidth}{0pt}          % Remove header underlines
\renewcommand{\footrulewidth}{0pt}              % Remove footer underlines
\setlength{\headheight}{13.6pt}

%%% Equation and float numbering
\numberwithin{equation}{section}        % Equationnumbering: section.eq#
\numberwithin{figure}{section}          % Figurenumbering: section.fig#
\numberwithin{table}{section}               % Tablenumbering: section.tab#

%%% Maketitle metadata
\newcommand{\horrule}[1]{\rule{\linewidth}{#1}}     % Horizontal rule

\title{
%\vspace{-1in}
\usefont{OT1}{bch}{b}{n}
\normalfont \normalsize \textsc{XXX: XXX} \\ [5pt]
\normalfont \normalsize \textsc{Dr. XXX XXX} \\ [15pt]
\horrule{0.5pt} \\[0.4cm]
\huge Assignment 2\\
\horrule{2pt} \\[0.5cm]
}
\author{
\normalfont                                 \normalsize
XXX\\[-3pt]     \normalsize
\today
}
\date{}

%%% Begin document
\begin{document}
%\maketitle

\section*{2.24}

Refer to Copier maintenance Problem 1.20.

\noindent
a. Set up the basic ANOVA table in the format of Table 2.2. Which elements of your table are additive? Also set up the ANOVA table in the format of Table 2.3. How do the two tables differ?
%%%%%%
%Attach q2.24table to the end
%%%%%%

\noindent
\textbf{Answer:}

\noindent
First, we need to find values that will be used to construct the ANOVA table. Our initial step is taken to construct the following table (you can find the full table at the end of this homework):

\begin{table}[h!] % location specifier just for this example
\small
\setlength\arraycolsep{2.75pt} % default value: 5pt
\caption{Data  on Copier Maintenance needed for calculation} \label{table:nonlin}

$\begin{array}{@{}c c c c c c c c c c cc @{}} \hline\hline &X_i & Y_i & X_i-\bar{X} & Y_i-\bar{Y} & \hat{Y_i} & Y_i-\hat{Y_i}& (X_i-\bar{X})^2&(Y_i-\bar{Y})^2&(Y_i-\hat{Y_i})^2&\hat{Y_i}-\bar{Y}&(\hat{Y_i}-\bar{Y})^2\\ [0.5ex] % inserts table %heading \hline &2&20&-3.11&-56.27&29.48&-9.48&9.68&3165.94&89.87&-46.79&2188.99 \\ &4&60&-1.11&-16.27&59.54&0.46&1.23&264.60&0.21&-16.73&279.78 \\ & \vdots\\ &4 & 61 & -1.11&-15.27&59.54&1.46 &1.23& 233.07&2.13&-16.73&279.78\\ &5 & 77 & -0.11 & 0.73&74.57&2.43&0.01&0.54&5.90&-1.70&2.88 \\ [0.5ex] \hline \textbf{Total}&230 &3432 & 0 & 0&3430.80&1.20&340.44&80376.8&3416.41&-1.2&76906.74 \\ \textbf{Mean}&5.11 &76.27 & &&& \\ \hline \end{array}$
\end{table}

\begin{table}[h!] % location specifier just for this example
\small
\setlength\arraycolsep{2.75pt} % default value: 5pt
\caption{Same table, but with lines drawn with macros of the booktabs package} \label{table:nonlin}

$\begin{array}{@{} l *{11}{c} @{}} \toprule &X_i & Y_i & X_i-\bar{X} & Y_i-\bar{Y} & \hat{Y_i} & Y_i-\hat{Y_i}& (X_i-\bar{X})^2&(Y_i-\bar{Y})^2&(Y_i-\hat{Y_i})^2&\hat{Y_i}-\bar{Y}&(\hat{Y_i}-\bar{Y})^2\\ \midrule &2&20&-3.11&-56.27&29.48&-9.48&9.68&3165.94&89.87&-46.79&2188.99 \\ &4&60&-1.11&-16.27&59.54&0.46&1.23&264.60&0.21&-16.73&279.78 \\ & \vdots \\ &4 & 61 & -1.11&-15.27&59.54&1.46 &1.23& 233.07&2.13&-16.73&279.78\\ &5 & 77 & -0.11 & 0.73&74.57&2.43&0.01&0.54&5.90&-1.70&2.88 \\ \midrule \textbf{Total}&230 &3432 & 0 & 0&3430.80&1.20&340.44&80376.8&3416.41&-1.2&76906.74 \\ \textbf{Mean}&5.11 &76.27 & &&& \\ \bottomrule \end{array}$
\end{table}

\end{document}

• Your table looks wonderful. I will use it as a template throughout the whole document. Thank you! – Olga Sep 21 '14 at 0:16
• @Olga - Many thanks for the compliment! – Mico Sep 21 '14 at 7:22
• Hey, your table seems to float. Can you add a separate code for a table with fixed location? – Olga Sep 21 '14 at 19:16
• @Olga - all table environments float unless you specifically prevent them from doing so. See the posting Keeping tables/figures close to where they are mentioned for methods to prevent (or at least limit) the floating behavior. – Mico Sep 22 '14 at 6:34

You could use a tabu with the tabu package: \usepackage{tabu}.

And your tabular will be a tabu with the \tabcolsep and \extrarowsep adjusted. Also using the X[-1] creates columns with just the width needed for the content. For treating all but the first column as math mark them with a $ in the tabu-preamble and remove the $s from your table body:

\setlength{\tabcolsep}{2pt}
\setlength{\extrarowsep}{2pt}
\begin{tabu}{X[-1]*{11}{X[$-1]}} \hline\hline &X_i & Y_i & X_i-\bar{X} & Y_i-\bar{Y} & \hat{Y_i} & Y_i-\hat{Y_i}& (X_i-\bar{X})^2&(Y_i-\bar{Y})^2&(Y_i-\hat{Y_i})^2&\hat{Y_i}-\bar{Y}&(\hat{Y_i}-\bar{Y})^2\\ [0.5ex] % inserts table %heading \hline &2&20&-3.11&-56.27&29.48&-9.48&9.68&3165.94&89.87&-46.79&2188.99 \\ &4&60&-1.11&-16.27&59.54&0.46&1.23&264.60&0.21&-16.73&279.78 \\ &\cdots &\cdots&\cdots&\cdots&\cdots&\cdots&\cdots&\cdots&\cdots&\cdots&\cdots \\ &4 & 61 & -1.11&-15.27&59.54&1.46 &1.23& 233.07&2.13&-16.73&279.78\\ &5 & 77 & -0.11 & 0.73&74.57&2.43&0.01&0.54&5.90&-1.70&2.88 \\ [1ex] \hline \textbf{Total}&230 &3432 & 0 & 0&3430.80&1.20&340.44&80376.8&3416.41&-1.2&76906.74 \\ \textbf{Mean}&5.11 &76.27 & &&& \\ \hline \end{tabu}  • With this setup, all the unary minus symbols are rendered as simple dashes rather than as typographically appropriate minus symbols. Is there a version of tabu that treats the material automatically as math stuff? – Mico Sep 20 '14 at 20:35 • @Mico Just change the preamble of the tabu to X[-1]*{11}{X[$-1]} and adjust the \tabcolsep to 2pt. I edited my answer. – Rafael Wörner Sep 20 '14 at 20:58
• +1 for explaining how to use tabu to treat columns as math-mode material. – Mico Sep 20 '14 at 21:09