48

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?

42

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.

screenshot

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

\begin{document}

\begin{figure}
 \begin{adjustwidth}{-2cm}{}
\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{adjustwidth}
\end{figure}

\end{document}
  • 2
    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
31

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.

  • 11
    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
  • 3
    I encountered an issue using \hskip where it misbehaved for values under 1.6cm, which went away using \hspace*. – Dimpl Aug 28 '16 at 13:19
  • 2
    It appears, that if one uses \begin{table} ... \input{tablecontent} ...\end{table} the \hspace{-4cm} has to go into the file of tablecontent itself, in order to have effect – TobiO Dec 28 '16 at 11:12
  • @TobiO Correct. – Yiannis Lazarides Dec 28 '16 at 15:38
15

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 well-spaced horizontal rules, and (iii) reduce the amount of inter-column whitespace. The third task may be achieved most easily, in my opinion, by using a tabular* environment instead of a tabular environment, setting \tabcolsep to 0pt, and using an @{\extracolsep{\fill}} directive -- I know, it's not exactly intuitive! -- to make LaTeX figure out how much intercolumn whitespace needs to to be inserted.

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 text block.

enter image description here

By the way, if one needs to specify that a table should have 21 columns of type l, 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 placing a tabular (or 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).

\documentclass[letterpaper]{article}
\usepackage{booktabs}
\usepackage[margin=1in,showframe=true]{geometry} % remove 'showframe' option in real doc.
\begin{document}
\begin{figure}
\setlength{\tabcolsep}{0pt} % let LaTeX figure out amount of intercolumn whitespace
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}*{21}{l}} % no vert. bars
\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}
8

Rather than nudging the table over an arbitrary distance, I'd recommend resizing or centering the table. LaTeX will do the tedious work of figuring out what that distance ought to be to fit the table on the page. The graphicx package will enable resizing within a \figure or \table environment. Simply enclose your \tabular or \includegraphics with

\resizebox{1 \textwidth}{!}{
.
.
}

Similarly, makebox enables centering of tables and figures:

\makebox[1 \textwidth][c]{ 
.
.
}

Change the inputs to \resizebox{<width>}{<height>} as you see fit. Note that these can extend beyond the boundaries of makebox. See the following example:

\documentclass{article}

\usepackage{graphicx} % enable graphics, images and resizebox

\usepackage{multicol} % enable multicolumn
\usepackage{lipsum}   % generate example text


\begin{document}

\section{Before}

\begin{figure}[!h]
\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}


\section{Resize}

\begin{figure}[!h]

\resizebox{1 \textwidth}{!}{   %resize table

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

} %close resize


\caption{\label{fig:text2}text experiment}
\end{figure}

\section{Center}

\begin{figure}[!h]


\makebox[1 \textwidth][c]{       %centering table
\resizebox{1.3 \textwidth}{!}{   %resize table

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

} %close resize
} %close centering


\caption{\label{fig:text3}text experiment}
\end{figure}

\lipsum[1-1]

\end{document}

This generates the following document with dummy text for comparison with margins.

enter image description here

  • 2
    This is the nicest solution of all above, much more general than fixing a dimension with adjustwidth. – GiuTeX Mar 23 '18 at 20:16
7

Simple answer : If you want to shift 6 em to the left you do something like

\hspace*{-6em}
\begin{tabular}{ m{5em}  m{14em}  m{17em}  m{4em} }
\hline  
\textbf{Year} & \textbf{Degree/Certificate} & \textbf{Institute} & \textbf{CGPA}
\end{tabular}

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.