## Centering wide tables or figures

When you want to include an image or a table that’s wider than the text width, you will notice that even when \centering or the center-environment is used this wide object will not be centered in relation to the surrounding text. It will be placed at the left margin but go into the right margin. Its frequently requested that wide figures or tables should overlap at both sides in equal measure.

It can easily achieved by putting the table or picture inside a box, giving the box the width of the text, by the \makebox command. Here is a compilable example, where I’m centering a table having 1.5 times the width of the text:

\documentclass[a4paper,10pt]{article} \usepackage[english]{babel} \usepackage{blindtext} \usepackage{tabularx} \begin{document}   \blindtext \bigskip   \noindent\makebox[\textwidth]{% \begin{tabularx}{1.5\textwidth}{XX} \blindtext & \blindtext \end{tabularx}}   \bigskip \blindtext   \end{document}

I’ve used \noindent to suppress the paragraph indentation, otherwise I would get an overfull \hbox. As you may notice there’s no \centering necessary because the width of the box equals \textwidth.

This topic was discussed in the LaTeX Community Forum, on CQF.info and on mrunix.de.

17. September 2008 by stefan
Categories: Figures and Tables | 37 comments

1. Thanks for sharing this. I recently stumbled upon the same problem and did not find a good solution. Next time I’ll use this trick.

2. That’s pretty interesting. Being a long-time plain TeX user, I would just do an hbox totextwidth{hss … hss}, but this solution is much more LaTeX-like.

3. Hi Kjell, hi Marcin,

thank you for your comments, they’re encouraging me to post some more small tricks and workarounds.

4. Thanks. You have make a good job.

5. Thanks. I like that. However, it would have been better if you could display what it would look like when you compile it. I have a problem centering a picture even though I used the centering code; which did not work. How do you put a picture on the left of the frame?
Again thanks

6. Hi Some,

here’s a screenshot using the code above:

Concerning your problem please show some code that’s needing correction. Btw. to position a picture freely you could use the textpos package.

7. I’m still a beginner with Latex, but this definitely helped. Thanks!

8. Thanks for the great post topic.

The example code works fine for me, but not when I try to adapt it for a figure.

Specifically,

\noindent\makebox[\textwidth]{% \begin{figure} \includegraphics{mypic} \end{figure}}

returns “LaTeX Error: Not in outer par mode.” for me.

When I place the figure environment outside of the \makebox command,

\begin{figure} \noindent\makebox[\textwidth]{% \includegraphics{mypic}} \end{figure}

the figure appears, but I am unable to change the width of the image,

\begin{figure} \noindent\makebox[\textwidth]{% \includegraphics[width=\textwidth]{mypic}} \end{figure}

returns the “Not in outer par mode” again. Any ideas what I’m doing incorrectly?

9. @Aaron:

That should be done differently:
en.wikibooks.org/wiki/LaTeX/Floats,_Figures_and_Captions

Check out the section about wide tables/figures in 2-column documents.
you need: begin{figure*}end{figure*}

10. Dear Sir

I have just seem this site. I have a question about LaTex. Please, I would like to know if the e-mail of :Aaron from 20 October 2009 at 6:27 PM, was answeered, because I have the same problem. Subject:Centering wide tables or figures.

Regards

Leon

11. Hi Leon,

you cannot put a figure into a box, because figures are intended to float, but you boxes inside figures are possible. So the second try of Aaron should work.

This example works for me:

\documentclass[a4paper,10pt]{article} \usepackage{graphicx} \begin{document} \begin{figure} \noindent\makebox[\textwidth]{% \includegraphics[width=1.4\textwidth]{mypic}} \end{figure} \end{document}

Perhaps don’t use a figure environment if you wouldn’t need floating. Captions can be positioned using the caption package, even without a figure environment.

Stefan

12. Dear Stefan, thank you so much. Your last reply really helped my in formatting my Master-Thesis

13. Sweet article. But, I don’t understand why would you create the box for the figure instead of simply doing \includegraphics[width=\textwidth]{mypic}, what would the difference be?

14. Hi Bjørnar,

the difference is: that article should help to center a figure that’s wider than the text, not to resize it.
Sometimes there’s a picture or a table that’s too wide and resizing it would make it unreadable or would reduce quality. That’s why I’ve noted this workaround.
If possible, I would prefer to scale the figure to the text width too, then of course we don’t need makebox.

Stefan

15. I have been searching for this type of solution for a while. Your tip about figures was perfect! I am sure lots of people want this functionality, perhaps we should add it to the latex wiki on figures and/or layout?

16. Oh and this method also seems to play well with subfigures!

documentclass[a4paper,10pt]{article}
usepackage{graphicx}
begin{document}
begin{figure}[htp]
noindentmakebox[textwidth]{%
subfigure[caption1]includegraphics[width=0.8textwidth]{pic1.jpg}}
subfigure[caption2]includegraphics[width=0.8textwidth]{pic2.jpg}}}
end{figure}
end{document}

17. Hi Mark,

feel free to copy it if you would like to. Of course it would be very good to add content to such knowledge bases like the LaTeX wiki.

Stefan

18. Is there perhaps a way to make the image go over the top and bottom margins as well, i.e. right against the top/bottom edge of the page? I’m try to make a cover page for my thesis and have a graphic header and footer that would like to use.

Ingo

19. Hi Ingo,

you could use the eso-pic package or the textpos package to put text or images beyond the margin. Or use TikZ and the current page node like in this post: http://texblog.net/latex-archive/layout/fancy-chapter-tikz/

Stefan

20. thanks so much! you also saved my master thesis

21. Thanks Stefan

The textpos package works perfectly

22. Yes!! I’ve been looking all over for this. My large tables would never center properly, until now! Thank you very much!

23. Sweet, thanks for that! Google did a terrible job for me finding a solution to this problem (or I did a terrible job using Google), this was exactly what I was looking for, but took me hours of browsing.

THANK YOU!!!!!!!!!!!!!!!!!!

25. This problem has been annoying me for years! Thanks for the solution!

26. THANK YOU!!!

27. Hey,

this seems like a great trick. i course, it won’t work for me… i’m using the bookstab package and so latex won’t accept the graphix package at the same time. could that be the problem?
and is there any way to make it work when you use bookstab?

cheers

28. Hey,

It looks very nice with tabularx, but it seems not to work with longtable. My code is something like yours;

 noindentmakebox[textwidth]{% begin{longtable}{>{centeringarraybackslash}m{0.55textwidth} >{centeringarraybackslash}m{0.55textwidth}} blindtext & blindtext \ end{longtable}} 

But I get this error:
! Missing endgroup inserted.

endgroup

If I just have the table without this nice fix, nothing is wrong with any endgroup. Is there a disambiguation between longtable and makebox?

29. Hi!

Really useful code, but it obviously doesn’t work anymore when I try to add a frame around the created box:

noindentfbox{makebox[textwidth]{%
includegraphics{mypic}}}

The frame will only be textwidth wide and cut through the picture. Any suggestions?

However, I must use the documentclass[twocolumn]{svjour3}% twocolumn

so that, the problem is that I can not insert a table which is almost as wide as the two columns. When I put my code (given below), I can not find my table in the next page because it has two large figures, but I can find it at the end of the document (after the references). I am also new to latex. please help me.

begin{table}[p] % table caption is above the table caption{Summery for all scenarios} label{tab:7} % Give a unique label % For LaTeX tables use begin{tabular}{l l l l| l l l |l l l |l l l} hline % multirow{2}{*}{scheme}&amp;multicolumn{3}{c|}{scen. $1$}&amp;multicolumn{3}{c|}{scen. $2$}&amp;multicolumn{3}{c|}{scen. $3$}&amp;multicolumn{3}{c}{scen. $4$}\   &amp; C &amp; SI &amp; PAPR &amp; C&amp; SI &amp; PAPR &amp; C&amp; SI &amp; PAPR &amp; C&amp; SI &amp; PAPR \ hline CSLM&amp;textendash&amp; $5$ &amp; $10.5$ &amp;textendash&amp; $5$ &amp; $10.5$ &amp;textendash&amp; $5$ &amp; $10.5$ &amp;textendash&amp; $5$ &amp; $10.5$ \ SSLM &amp;$44$&amp; $5$ &amp; $9.5$ &amp; $70$ &amp; $4$ &amp; $9.75$ &amp;$83$&amp;$3$&amp;$9.75$&amp;$90$&amp;$2$&amp;$9.8$\ hline hline multicolumn{13}{l}{C $colon$ Complexity reduction (percentage)}\ multicolumn{13}{l}{SI $colon$ Side Information (number of bits) }\ multicolumn{13}{l}{PAPR$colon$ Peak textendash to textendash Average Power Ration Reduction (dB)}\ multicolumn{13}{l}{Note$colon$ this table build on the best results of the CSLM and the SSLM techniques respectively}\ multicolumn{13}{l}{Note$colon$ , i.e., $U = 32$ for the CSLM, and $z = 48$, at $r =8$ for the SSLM.}\ %noalign{smallskip}hline end{tabular} end{table}

Note Please: when I remove the option [p] , the table will appear after the page of the figures but in the beginning of the second column, therefore, it will cutoff because it is very wide (approximately 90% of the two columns).

31. Hai How to create this types of tables

32. Dear Tex-Community,

when I try to add a caption to a table inside a box using the makebox routine as described above, I receive the following error message:

! Package caption Error: caption outside float.

Can anyone help?

Thanks!

33. Thanks!

34. Thanks for sharing the guidance, great really,

I am using this

\newpage
\vfill
\begin{figure}[htbp]
\noindent\makebox[\textwidth]{%
\includegraphics[width=1.4\textwidth]{xxxxxxxxxxxxx.jpg}}
\caption{yyyyyyyyyyyyyyyyy}
\end{figure}
\vfill
\clearpage

With \caption{yyyyyyyyyyyyyyyy}, I thought I might be able to get the caption below the image.

I get a good rendering of the image, occupying the whole page, in landscape I get empty/white header running across the page about 2 cm width, no caption. Any recommendations welcome,

35. It does not seem to work with xtable.

I.e. this

\noindent\makebox[\textwidth]{
print(xtable)
}

doesn’t print anything.

36. Thanks!

37. This could help someone since similar problem was asked on Stackexchange: http://tex.stackexchange.com/questions/39435/how-can-i-center-a-too-wide-table