Overwide figures in LaTeX

26 November, 2009 - 13:05
Categories:

When using default LaTeX styles, you get a rather small text width. This is for a very good reason: readability. However, when you want to add an image, figure or table, this width can be a bit limiting. If you naively add an image (or table) that is wider than the text width, the image will typically align on the left margin and extend into the right margin, which is not that pretty. Moreover, because you're not using the left margin, it limits the maximum width you can use.

I found this nifty LaTeX recipe for overwide graphics, which I'd like to rehash.

The trick is to put the image (or something else) in a \makebox command:

\makebox[\textwidth][c]{
  % put your overwide image here
}

To see it in action, I made a small but functional illustration with a fake image (using the \rule command):

The code to produce this:

\documentclass[12pt]{article}
 
% Some float settings to get all the figures at the top of the page
\setcounter{topnumber}{4}
\setcounter{totalnumber}{4}
 
% Make the captions larger so we can read them in the screenshot.
\usepackage[Large]{caption}
 
\begin{document}
 
% An image that is small enough.
\begin{figure}
    \centering
    \rule{5cm}{1em}
    \caption{Faking a small image with the rule command.}
\end{figure}
 
% An overwide image.
\begin{figure}
    \centering
    \rule{17cm}{1em}
    \caption{What about a wide image?}
\end{figure}
 
% Using the makebox trick to align it nicely.
\begin{figure}
    \makebox[\textwidth][c]{
        \rule{17cm}{1em}
    }
    \caption{This looks better, doesn't it?}
\end{figure}
 
% The same makebox trick with right alignment.
\begin{figure}
    \makebox[\textwidth][r]{
        \rule{17cm}{1em}
    }
    \caption{We can even align it to the right.}
\end{figure}
 
 
% A bit of nonsense text to visualize the normal margins.
\section{Iprem Losum}
 
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Etiam sed mattis lorem. Mauris consectetur, diam a
condimentum fermentum, diam sem tincidunt libero, eu
venenatis nulla turpis congue urna. Quisque sagittis iaculis
turpis, id adipiscing sapien lobortis eu. Curabitur elementum,
turpis et vehicula iaculis, augue sem egestas odio, vel
ornare dui erat nec sem. Cras massa tellus, commodo nec
tincidunt a, bibendum in ipsum. Donec nisi dolor, ultrices
eu aliquet non, placerat ut orci. Nulla neque augue, vehicula
et tempor eget, mattis vitae augue. Maecenas eu felis mi, non
adipiscing libero.
 
\end{document}
27 August, 2010 - 19:16

Thanks!

Stefanos (not verified)

It was the only solution that worked for me, I tried complicated ones before that, like changing the margins temporarily etc.

Thank you very much!

27 August, 2010 - 19:16

Thanks!

Stefanos (not verified)

It was the only solution that worked for me, I tried complicated ones before that, like changing the margins temporarily etc.

Thank you very much!

11 March, 2010 - 05:51

Read the "epslatex" guide

Joaquim (not verified)

This is a nice and simple trick. But before going further, I suggest spending a few days reading the wonderful guide that is "epslatex.pdf".

It can be found in standard CTAN mirrors: http://ctan.org/tex-archive/info/epslatex/

The guide covers a lot of things, some of which I'm sure I'll never use. But if I ever actually need to use them, I'm confident this guide will be able to point me in the right direction.

As for this post, I just have one suggestion: instead of using \textwidth, I think it's good practice to use \linewidth. The latter is basically \textwidth in the *current* environment, that is, if you are inside some other environment that modifies the text width, the figure will use this new width instead of the global \textwidth which, I believe, is fixed.

4 February, 2010 - 17:20

great tip!

Ted (not verified)

I linked to this post from another one of yours on working with bash, and it happened to answer an exact problem I've been having with typesetting my dissertation! Obviously when the secretaries with the rulers come out for the final verdict, I'll have to resize the figures, but for now this is just what I'm looking for. Thanks!

Post new comment

The content of this field is kept private and will not be shown publicly.
  • No HTML tags allowed
  • Lines and paragraphs break automatically.

More information about formatting options