6

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}
Jayvl
  • 319

2 Answers2

5

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}
David Carlisle
  • 757,742
  • 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
1

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.

Toscho
  • 4,713
  • 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 00:46