# making a table fit on a page by moving it left

I have a table where the last columns fall off the page. Instead of making the text smaller I would like the table to not adhere to the margin of where it begins. I would like to move it to the left. I am using flushleft, which is not working. Here is the code:

\begin{figure}
\begin{flushleft}
\begin{tabular}{l|l|l|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|}
\multicolumn{21}{l}{a)text}\\ \hline
& 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10& 11& 12& 13& 14& 15& 16& 17& 18& 19& 20\\ \hline
day1&9.2&8.6&8.1&6.3&7.7&7.3&8.0&8.4&5.9&6.8&7.3&7.6&9.0&7.4&6.6&7.0&5.3&7.0&8.0&5.2\\
day2&6.7&6.9&0&7.0&0&8.1&9.0&6.1&0&6.9&0&7.3&7.8&5.3&0&8.9&0&8.4&8.4&7.5\\
day3&0&5.2&0&0&7.5&0&0&8.2&0&0&5.4&0&0&8.3&0&0&7.7&0&0&7.3
\end{tabular}
\end{flushleft}
\caption{\label{fig:text}text experiment}
\end{figure}

What can be modified? What possible solutions exist?

-
Have a look at tex.stackexchange.com/questions/16582/… –  lockstep Nov 1 '11 at 18:18

You could use adjustwidth from the changepage package which allows you to widen or shorten the page width from the left or the right.

I loaded the geometry package with showframe=true just so that you an see where the page boundaries lie.

\documentclass{article}
\usepackage[showframe=true]{geometry}
\usepackage{changepage}

\begin{document}

\begin{figure}
\begin{tabular}{l|l|l|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|}
\multicolumn{21}{l}{a)text}\\ \hline
& 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10& 11& 12& 13& 14& 15& 16& 17& 18& 19& 20\\ \hline
day1&9.2&8.6&8.1&6.3&7.7&7.3&8.0&8.4&5.9&6.8&7.3&7.6&9.0&7.4&6.6&7.0&5.3&7.0&8.0&5.2\\
day2&6.7&6.9&0&7.0&0&8.1&9.0&6.1&0&6.9&0&7.3&7.8&5.3&0&8.9&0&8.4&8.4&7.5\\
day3&0&5.2&0&0&7.5&0&0&8.2&0&0&5.4&0&0&8.3&0&0&7.7&0&0&7.3
\end{tabular}
\caption{\label{fig:text}text experiment}
\end{figure}

\end{document}
-
it works and I turned the flag for the showframe off after the distance for the adjustwidth was found (\usepackage[showframe=false]{geometry}) –  Vass Nov 1 '11 at 18:32
This is magical! Thanks so much for making me discover adjustwidth. –  Zenon May 30 '12 at 16:27

Easiest way to do achieve it insert an \hskip-4.0cm\begin{tabular}... \end{figure}.

The hskip-4.0cm will tell LaTeX to move the box left by the amount of 4.0cm.

-
Wouldn't \hspace*{-4cm} be "more LaTeX"? –  egreg Nov 2 '11 at 15:12
@egreg It is two characters shorter:) I personally don't mind mixing a bit of LaTeX with TeX. In the same way that if I am using a Python library it shouldn't stop me from using the Python primitives. Also \hskip will not introduce a space if you leave a space after the 4cm whereas \hspace* will. –  Yiannis Lazarides Nov 2 '11 at 16:16

In addition to the approach that uses the adjustwidth environment to change the width of the text block locally, you can also reduce the amount of inter-column white-space to reduce the overall width of the table and hence make it fit into the normal text block.

Specifically, I recommend that you (i) omit all vertical rules (because they take up some space), (ii) use the booktabs package to get pleasantly-spaced horizontal rules, and (iii) reduce the inter-column whitespace amount. The third task may be achieved by adjusting with the \tabcolsep parameter. A minute or so of experimentation shows that, for a text block width of 6.5" and Computer Modern font set at 10pt, reducing the value of this parameter from the default value of 6.0pt to 4.6pt -- for a reduction of less than 25% -- does the trick, as the following MWE illustrates. (As in one of the other answers, I've specified the showframe=true option of the geometry package merely to show the width of the textblock.)

\documentclass[letterpaper]{article}
\usepackage{booktabs}
\usepackage[margin=1in,showframe=true]{geometry}
\begin{document}
\begin{figure}
\renewcommand{\tabcolsep}{4.6pt}
\begin{tabular}{@{} *{21}{l} @{}} % use "@{}" suppresses whitespace at start and end of table
\toprule
& 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 & 16 & 17
& 18 & 19 & 20 \\
\midrule
Day 1 & 9.2&8.6&8.1&6.3&7.7&7.3&8.0&8.4&5.9&6.8&7.3&7.6&9.0&7.4&6.6&7.0
&5.3&7.0&8.0&5.2\\
Day 2 & 6.7&6.9&0&7.0&0&8.1&9.0&6.1&0&6.9&0&7.3&7.8&5.3&0&8.9&0&8.4&8.4&7.5\\
Day 3 & 0&5.2&0&0&7.5&0&0&8.2&0&0&5.4&0&0&8.3&0&0&7.7&0&0&7.3\\
\bottomrule
\end{tabular}
\caption{\label{tab:text}Text Experiment}
\end{figure}
\end{document}

By the way, when one needs to specify that a table should have (more or less identical) 21 columns, it is not necessary to type

\begin{tabular}{ l | l | l | l ... l }

Instead, one may specify \begin{tabular}{ l *{20}{|l} } to denote 20 instances of "|l". As explained above, I think the table looks just as good -- actually, better :-) -- without any vertical rules, hence my specification *{21}{l}. If you simply must have vertical rules after the first column and then after every fifth column, say, you could specify \begin{tabular}{ l *{4}{|lllll} }.

Finally, when setting a tabular environment in a float environment, it's better to use the table environment rather than the figure environment (as you did in your MWE and I copied in my answer).

-
I like your answer, but was confused by the part when you said the adjustwidth squashes the content. The command \resizebox from the graphicx package does this, but the adjustwidth environment does not, it simply changes the page width. Try my example and change -2cm to 6cm; the content inside does not get squashed! –  cmhughes Nov 1 '11 at 22:35
@cmhughes: You're right, my mistake. I'll correct my answer. –  Mico Nov 1 '11 at 23:02