Graphics, Figures & TablesCentering wide tables

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
davidec
Posts: 16
Joined: Thu Oct 22, 2009 6:18 pm

Centering wide tables

Post by davidec »

I have the recurrent problem of tables that are wider than my normal text width. I would like them to be centered on the page, but LaTeX justifies them on the left margin. As an example:

Code: Select all

\documentclass[letterpaper,12pt]{article}
\usepackage[left=5cm]{geometry}
\usepackage{lipsum}
\begin{document}
\lipsum[1]

\begin{table}[h]
\begin{tabular}{rrrrrrr} \hline
Variable  & N.\ Obs. & Mean & Std.dev. & Treatment & Control & Difference \\ \hline\hline
Outcome 1 & 80 & 8400 & 8577 & 11579 & 7410 & 4169 \\
Outcome 2  & 126 & 6984 & 7183 & 8960 & 6495 & 2465 \\ \hline
\end{tabular}
\end{table}

\lipsum[1]
\end{document}
How can I get the table to be centered relatively to the page, or rather, relatively to the body of the text? I.e., exceeding the width of the text body by the same amount on either side?

I tried to bracket the table environment into a center environment, but to no avail. Thanks!

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Centering wide tables

Post by gmedina »

Hi,

use a \makebox command, as described here:

http://texblog.net/latex-archive/layout/centering-figure-table/
1,1,2,3,5,8,13,21,34,55,89,144,233,...
davidec
Posts: 16
Joined: Thu Oct 22, 2009 6:18 pm

Re: Centering wide tables

Post by davidec »

Thanks a lot! I don't know how I couldn't have found this before.
davidec
Posts: 16
Joined: Thu Oct 22, 2009 6:18 pm

Centering wide tables

Post by davidec »

Actually, I do have a followup on this. I usually have a footnote at the end of the table, with the sources of the data etc etc. One of my previous headaches was how to format the note so that it had the same width as the table itself. The way I found was to use a lrbox:

Code: Select all

\documentclass[letterpaper,12pt]{article}
\usepackage[left=5cm]{geometry}
\usepackage{lipsum}

\begin{document}
\newsavebox{\tablebox}
\newlength{\tableboxwidth}

\lipsum[1]

\begin{table}[h]
\caption{Summary statistics}
\begin{lrbox}{\tablebox} 
\begin{tabular}{rrrrrrr}
\hline
Variable  & N.\ Obs. & Mean & Std.dev. & Treatment & Control & Difference \\ \hline\hline
Outcome 1 & 80 & 8400 & 8577 & 11579 & 7410 & 4169 \\
Outcome 2  & 126 & 6984 & 7183 & 8960 & 6495 & 2465 \\ \hline
\end{tabular}
\end{lrbox} 
\usebox{\tablebox}
\settowidth{\tableboxwidth}
{\usebox{\tablebox}}
\parbox{\tableboxwidth}{\textbf{Note:} \lipsum[1]}
\end{table}

\lipsum[1-3]
\end{document}
Now, however, I do not know how to combine this with the makebox command suggested by gmedina in his post on texblog. I tried different combinations (putting everything into a makebox, putting the main body of the table and the notes into two separate makeboxes), but none seems to deliver the right results. Any suggestions?
Post Reply