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.
horizontal alignmenttables
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.
Best Answer
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 theMakebox
environment from therealboxes
can be used as an replacement. It reads the content as a box. Better would be theadjustbox
macro or environment from theadjustbox
package together with thecenter
key.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
. Note that<your table>
should be atabular
or equivalent environment, not atable
environment.You can now also use the
tabular
key ofadjustbox
(as first key!) to save the extra\begin{tabular}
..\end{tabular}
which is then added internally.