I have a fairly large figure in a LaTeX document. This figure is too large for the left and right margin of the document. This results in the figure being placed flush with the left margin, and way beyond the right margin. What I want is to do, is center the figure on the page. Can I do this, e.g. by setting a different left margin for this figure?
-
Welcome to TeX.sx! Your question was migrated here from [so]. Please register on this site, too, and make sure that both accounts are associated with each other (by using the same OpenID), otherwise you won't be able to comment on or accept answers or edit your question. – Werner May 29 '12 at 12:12
7 Answers
\centerline{\includegraphics{...}}
Does this without any hspace trickery.
- 2,181
-
13Very clean code, and solves the need-more-width-for-my-graph problem, so worth a try! – nruth Dec 04 '11 at 02:22
-
6
-
4Where have you been all my life. Why have I been struggling with this for years... – keyser Jan 31 '15 at 12:46
-
-
@becko ERT before the image with
\centerline{, ERT after the image with}. – Sparhawk Jun 27 '17 at 06:28 -
But this answer works only if the image should be centered. If you just want to give a small, possibly partly transparent, image a negative margin, the accepted answer is better. – JepZ Jan 25 '19 at 11:50
-
1Perfect! Exactly what I needed and is the easiest solution. It also worked on a subfigure containing two figures side-by-side. Yay! – anaotha Aug 28 '19 at 11:03
-
-
If the figure is e.g. 3 inches too wide, add a negative space of half that before the figure:
\hspace*{-1.5in}
\includegraphics{...}
- 11,970
- 2
- 18
- 11
-
2How can this
negative spaceapproach be used to make use of the space on the right? – Prradep Jan 12 '18 at 10:21 -
For me, images that are too wide automatically already penetrate the right-side margin. – user1271772 Dec 03 '18 at 23:16
The above did not work for me as I wanted the figure wider than the caption.
Also, I think there is a override by the endfloat package.
This will leave the entire document intact and only alter the figure:
\begin{figure}
\advance\leftskip-4cm
\includegraphics[options]{location}
\end{figure}
You could also use:
\advance\rightskip-2cm
-
1Your code snippet worked just fine, thank you for the insight ! The hspace command above didn't work in my case. – Jun 21 '10 at 20:21
-
This worked well for me in the case of multiple horizontally distributed \includegraphics in the same figure :) – JorgeGT Mar 08 '16 at 13:27
If the figure is an external graphics, then do like this:
\begin{figure}
\begin{center}
\includegraphics[width=\textwidth]{...}
\end{center}
\end{figure}
\textwidth will stretch it to full text width. You can specify a coefficient like, for example, 0.75 of the text width:
\includegraphics[width=0.75\textwidth]{...}
Found a great simple solution to this problem!
\documentclass[a4paper,10pt]{article}
\usepackage{graphicx}
\begin{document}
\begin{figure}
\noindent\makebox[\textwidth]{%
\includegraphics[width=1.4\textwidth]{mypic}}
\end{figure}
\end{document}
I found this solution here: http://texblog.net/latex-archive/layout/centering-figure-table/#comment-875
If you are using the memoir class, the solution is to use
\centerfloat
rather than
\centering
in your float. This will prevent you from having to manually set the negative horizontal spacing.
Maybe you're not using memoir. Fair enough. \centerfloat is defined thusly, so you can just make your own:
\newcommand*{\centerfloat}{%
\parindent \z@
\leftskip \z@ \@plus 1fil \@minus \textwidth
\rightskip\leftskip
\parfillskip \z@skip}
- 63,575
- 61
The automated version of Ian's answer might look like this:
\newlength{\myimageoversize}
\newsavebox{\myimage}
\newcommand{\mycenter}[1]{%
\savebox{\myimage}{#1}
\settowidth{\myimageoversize}{\usebox{\myimage}}
\addtolength{\myimageoversize}{-\textwidth}
\setlength{\leftskip}{-0.5\myimageoversize}
\noindent
\usebox{\myimage}}
\begin{figure}
\mycenter{\includegraphics{...}}
\end{figure}