# Full-width figure, odd/even pages + margin

situation I'm using the memoir class, two-sided. I left place for margin notes. Thus the text block is not at the center of my "sheet of paper" and this non-central position is different for odd and even pages. (On the verso page the margin notes are situated on the left, on the recto page they are on the right side of the page.)

goal All my figures have a standard width equal to a length that I called \widthw = \textwidth + \marginparsep + \marginparwidth (I found the definition of these lengths on pages 10 and 11 of this pdf). Now I want to adjust the position of these figures like illustrated in following screenshots:

• verso (left page):
• recto (right page):

my trial

\newlength{\rf}

\newcommand*\definesHSpace
{
\checkoddpage
\ifoddpage
\setlength{\rf}{0mm}
\else
\setlength{\rf}{\marginparsep+\marginparwidth}
\fi
}

\newenvironment{myfigure}
{
\begin{figure}[h]
\definesHSpace
\hspace{-\rf}
\begin{minipage}[h]{\widthw}
}
{
\end{minipage}
\end{figure}
}

%begin document...

\begin{myfigure}
...
\end{myfigure}


problem The "IF" works not like desired. I'll try to explain why I think it fails: Let say we are on a odd page. I finished a paragraph of text and, on the page, there is still place for e.g. 3 lines of text. Now I write \begin{my figure} ... Well, the answer to the "IF" is "odd page", although LaTeX will put the figure on the next page (because the image is higher than the height of the 3 lines of text). So the figure will not be adjusted like I would have expected.

solution? It would be fantastic if someone had an idea to solve this problem. (I know tufte-book has some full-width figure environment, but I do not want to use that class.) Thanks a lot!!!

• Or using KOMA script – sandu Feb 28 '14 at 9:10

I solved the problem with the needspace package. You mention that all figures are of standard width. If, by chance they are also of standard height, then the solution is very easy: place a \needspace{length} prior to the call to \defineHSpace, where the length is the figure's standard vertical space (including surrounding blank space). In this way, the page break, if needed, will occur before \definesHSpace is invoked. Thus, the figure placement will not get out of sync with the figure invocation.

But if the figures are not of standard height, \needspace can still solve the problem; however, it requires you to use a macro, rather than an environment, to create your figures. The solution involves setting a figure in a box before it is typeset, and using \needspace to allocate the height+depth +2\baselineskip(above/below gap) of the figure before actually beginning the figure environment. As before, the page break, if needed, will occur before \definesHSpace is invoked. Comment out the \needspace macro in my MWE to see the false result, caused by the first figure being pushed to the 2nd page.

Also, I comment out two captioning options, for this MWE. Depending on whether you want them centered on the figure or the margin, uncomment the appropriate one. If the centered-on-margin caption option is used, the \needspace argument will need to be tuned to account for the added height of the caption, as well.

\documentclass[twoside,12pt]{memoir}
\usepackage{lipsum, calc, needspace, caption}
\newlength\widthw
\setlength{\widthw}{\textwidth+\marginparsep+\marginparwidth}

\newlength{\rf}

\newcommand*\definesHSpace
{
\checkoddpage
\ifoddpage
\setlength{\rf}{0mm}
\else
\setlength{\rf}{\marginparsep+\marginparwidth}
\fi
}

\newcommand\myfigure[2]{%
\setbox0=\hbox{%
\begin{minipage}[h]{\widthw}%
#2%
%    \captionof{figure}{#1}% CENTERED ON FIGURE
\end{minipage}%
}%
\needspace{\ht0+\dp0+2\baselineskip}% COMMENT THIS LINE FOR OLD RESULT
\begin{figure}[hT]%
\definesHSpace%
\hspace{-\rf}%
\box0%
%     \caption{#1}% CENTERED ON MARGIN
\end{figure}
}

\def\myfig{\myfigure{caption}{\rule{\widthw}{2ex}}}

\begin{document}
\lipsum[1-4]
\myfig%This breaks under OP dfn
\lipsum[3-5]
\myfig
\lipsum[6-8]
\myfig

\end{document}