Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a document containing a table which is slightly too wide for the page. But instead of growing to the right side only, I would like to have it centered on the page.

I have tried to use the center environment but this doesn't seem to help.

share|improve this question
4  
Have a look at Center flow chart horizontally, the answer works also for too wide tables, perhaps also have a look at Centering wide tables or figures. Similar solution here: How to center the minipage. –  Stefan Kottwitz Dec 27 '11 at 16:30
    
Please compose a compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. –  Peter Grill Dec 27 '11 at 16:30
    
@PeterGrill: I don't think a MWE is really necessary here. It's kind of a common, easily understandable issue. –  Martin Scharrer Dec 27 '11 at 16:45
    
@martin Sure, but knowing, say, the class, help know which tools are readily available. –  daleif Dec 27 '11 at 17:34
    
See also: tex.stackexchange.com/questions/32726/… –  Dejan Dec 29 '11 at 14:26
show 1 more comment

2 Answers

up vote 18 down vote accepted

If a table (or any other horizontal box) is wider than the text (\textwidth) an overfull hbox warning is given and the content is placed anyway, which makes it run into the right margin. To avoid this and to suppress the error the content must be placed in a box with is equal or smaller than \textwidth. The \makebox macro with its two optional argument for the width and horizontal alignment can be used for this: \makebox[\textwidth][c]{<table>} will center the content. See Center figure that is wider than \textwidth and Place figures side by side, spill into outer margin were this is used for figures and further explained.

For more complicated tables, especially if they should contain verbatim material, you should use a different approach. \makebox reads the whole content as macro argument which does not allow verbatim content and is not very efficient (ok, nowadays the latter isn't really important any longer). The \Makebox macro or the Makebox environment from the realboxes can be used as an replacement. It reads the content as a box. Better would be the adjustbox macro or environment from the adjustbox package together with the center key.

\begin{adjustbox}{center}
<your table>
\end{adjustbox}

Which centers the content to \linewidth (mostly identical to \textwidth) by default but also takes any other length as an optional value, e.g. center=10cm.

share|improve this answer
    
Thank you very much for the detailed explanation. Why not use \centerline{} as suggested in another answer? Are you aware of any drawbacks? –  Dejan Dec 28 '11 at 5:51
1  
@Dejan: \centerline reads the content as a macro argument as well and is basically the same as \makebox[\hsize][c], using more lower-level TeX commands than LaTeX ones. It will work, but \makebox or \adjustbox is more flexible. –  Martin Scharrer Dec 28 '11 at 8:52
add comment

Put your table into \centerline{}. The table will extend evenly into both margins if it's wider than \textwidth.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.