views:

5076

answers:

4

I'm including a table in my LaTeX document and the centering works fine if the table isn't wider than the text column above it, but when the table is wider, the left side of the table sticks to the left side of the text column, and the additional width of the table is on the right side of the page, how can I center the table?

A: 

You're not the first to encounter this problem. Try one of the solutions mentioned on this forum. Good luck!

Stephan202
A: 

Are you using a multi-column document? I so, consider the table* variant environment.

In a single column environment your options run to:

  • Increase the textwidth. But the default margin were choosen for good ergonomic reasons, so this is to be discouraged beyond a minimal tweaking.
  • Reduce the text size in the table (i.e. \small or even \footnotesize inside the tabular environment). Again, this is less than optimal.
  • Use the rotating package as suggested in the link Stephan202 gave. I used this for a couple of very large tables in my dissertation (with only the p positioning options) and it came out very nicely.
dmckee
+6  A: 

I'd recommend trying the chngpage package.

\documentclass{article}

% allows for temporary adjustment of side margins
\usepackage{chngpage}

% provides filler text
\usepackage{lipsum}

% just makes the table prettier (see \toprule, \bottomrule, etc. commands below)
\usepackage{booktabs}

\begin{document}

\lipsum[1]% just a paragraph of filler text

\medskip% adds some space before the table
\begin{adjustwidth}{-1in}{-1in}% adjust the L and R margins by 1 inch
  \begin{tabular}{ll}
    \toprule
    Sequence & Wide column \\
    \midrule
    First & Vestibulum porta ultricies felis. In nec mi. \\
    Second & Nam vestibulum auctor nibh. In eleifend, lacus id tristique ullamcorper, mauris urna convallis elit. \\
    Third & Ut luctus nisi quam lobortis magna. Aenean sit amet odio et sapien rutrum lobortis. \\ 
    Fourth & Integer dictum accumsan purus. Nullam erat ligula, dictum sed, feugiat nec, faucibus id, ipsum. \\
    \bottomrule
  \end{tabular}
\end{adjustwidth}
\medskip% adds some space after the table

\noindent\lipsum[2]% just a paragraph of filler text

\end{document}

The documentation for the chngpage package is located at the bottom of the chngpage.sty file. I've pulled out the docs for the adjustwidth environment:

Within an adjustwidth environment the left and right margins can be adjusted. The environment takes one optional argument and two required length arguments:

\begin{adjustwidth}[]{leftmargin}{rightmargin}

A positive length value will increase the relevant margin

(shortening the text lines) while a negative length value will decrease the margin (lengthening text lines). An empty length argument means no change to the margin. At the end of the environment the margins revert to their original values.

For example, to extend the text into the right margin:

\begin{adjustwidth}{}{-8em}

Any appearance of the optional argument (even just []) will cause the values of the margins to switch between odd and even pages.

If the document is being set twosided it might be advantageous to have any wider text extending into the outside margin. This could be done via the optional argument, as:

\begin{adjustwidth}[]{}{-8em}

To have the adjusted text horizontally centered with respect to any surrounding text, the margins should be adjusted equally:

\begin{adjustwidth}{-4em}{-4em}

godbyk
Great answer. One caveat: you're better off using the newer "changepage" package instead, which is almost identical but uses the same interface as the memoir class. All by the same author.
Will Robertson
Will, that's true. But since the `changepage` package is so new, I used the `chngpage` package here, since it comes with all the LaTeX distributions.To Zequj, the syntax for the `adjustwidth` environment varies slightly between the `chngpage` and `changepage` packages.
godbyk
A: 

If you're using a \table float, the \begin{adjustwidth} ... \end{adjustwidth} has to be contained inside it.

db