Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I've seen similar threads with centering problems, but could not find the right solution to mine. I'm using the report class (onesided).

I have a float figure (object width=1.3\textwidth here, may change for other figures). By default it is flushed left and spills into the right margin. I want it to grow into both margins. The problem is my left margin is smaller than my right margin, so when I center it using e.g. \makebox the left margin is filled too much.
I want the figure to expand unevenly, e.g. 2cm right for every 1cm left.

First I used \hspace{-0.1\textwidth} to pull it into the left margin. My current solution is to adjust the margins (make them equal) with a changemargins environment I found in another thread. Then the \makebox or \centerfloat solutions work fine.

But I'm not happy I have to hardcode numbers. So I thought if I could center it with respect to the page (A4) instead of the uneven margins, it would spill into the margins properly. Anyone know how to do this?

EDIT: Added MWE, see below

\documentclass[10pt,a4paper]{report}
\usepackage{blindtext}
\usepackage[demo]{graphicx}

\usepackage[bottom=1in,left=1.22in,right=1.63in]{geometry}

\begin{document}
\blindtext

%before
\begin{figure}[bht]
\includegraphics[width=1.4\textwidth,height=4cm]{myPictureName.png}
\end{figure}

%after margin centering
\begin{figure}[bht]
\noindent\makebox[\textwidth]{%
\includegraphics[width=1.4\textwidth,height=4cm]{myPictureName.png}
}%
\end{figure}

%desired output: equal whitespace both sides
\begin{figure}[bht]
\hspace{-0.2\textwidth}\hspace{0.2in}
\includegraphics[width=1.4\textwidth,height=4cm]{myPictureName.png}
\end{figure}

\end{document}
share|improve this question
    
Please add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. –  Papiro Apr 26 '13 at 14:01
1  
Can't you use \changemargins to make the margins 0? That wouldn't really be "hard-coding a value", and yet should give the intended effect. –  T. Verron Apr 26 '13 at 14:18
    
That could work. Also, my \changemargins doesn't work with floatrow environment. Maybe something centering related would... –  Jayvl Apr 26 '13 at 14:40
    
If you are using a oneside setting you just need to negative space by \oddsidemargin but if you are using a two side option it isn't possible without a lot of work as the figure is set before latex allocates it to a page so the margins are not known. –  David Carlisle Apr 26 '13 at 16:23
    
Related: Center figure that is wider than \textwidth –  Werner Apr 26 '13 at 17:00

2 Answers 2

up vote 4 down vote accepted

For one sided setting you just have to take account of \oddsidemargin and the default 1in offset:

\documentclass[10pt,a4paper,oneside]{report}
\usepackage{blindtext}
\usepackage[demo]{graphicx}

\usepackage[bottom=1in,left=1.22in,right=1.63in]{geometry}

\begin{document}
\blindtext


%desired output: equal whitespace both sides
\begin{figure}

\hspace*{-\dimexpr\oddsidemargin+1in\relax}\makebox[\paperwidth]{%
\includegraphics[width=1.4\textwidth,height=4cm]{myPictureName.png}}\hspace*{-\paperwidth}
\end{figure}

\end{document}
share|improve this answer
    
Thanks this seems to work fine, took me a few minutes to understand it. So I make a box the size of the page to ensure it bleeds equally into the left and right margins. But because of how the box is placed it needs to be shifted to the left by amount equal to the L-margin. –  Jayvl Apr 26 '13 at 18:03

If you want to reach half as wide into the left margin as into the right margin, you can use the following:

\documentclass[10pt,a4paper]{report}
\usepackage{blindtext}
\usepackage[demo]{graphicx}

\usepackage[bottom=1in,left=1.22in,right=1.63in,showframe]{geometry}

\begin{document}
\blindtext

\newlength{\picturewidth}
\setlength{\picturewidth}{1.4\textwidth}
\newlength{\picturehoffset}
\setlength{\picturehoffset}{-0.333333\picturewidth}
\addtolength{\picturehoffset}{0.333333\textwidth}
\begin{figure}[bht]
\hspace*{\picturehoffset}%
\includegraphics[width=\picturewidth,height=4cm]{myPictureName.png}
\end{figure}
\end{document}

There is is still some glitch: If you set \picturewidth to \textwidth, you see some small indentation, but I don't know why.

share|improve this answer
    
you have a word space between the hspace and the includegraphis, you need a % at end of line. also this puts the image also the arithmetic seems a little odd: the image is 1.4\textwidth so to stick into the margin the same amount you need a negative space of .2\textwidth –  David Carlisle Apr 26 '13 at 17:32
    
You did the symmetric solution. But the OP said in the question, he wanted the picture to stick into the margin assymmetrically: "2cm right for every 1cm left". So I did this. It looks rather strange to me, but that's what he also asked for. –  Toscho Apr 26 '13 at 20:54
    
so he did:-) I was going by the subject line which says center on page rather than text block but you are right that the detailed description doesn't really match that:-) –  David Carlisle Apr 26 '13 at 21:05
    
In his MWE he has the comment "%desired output: equal whitespace both sides", so there are two alternative aims asked for. –  Toscho Apr 26 '13 at 21:15
    
But by centering w.r.t. the page, given the condition of uneven margins, one automatically achieves the desired asymmetric behaviour---namely such that the whitespace on both sides is equal. I see I wasn't very clear on that point, thanks! –  Jayvl Apr 27 '13 at 0:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.