I'm trying to improve the typesetting of openly licensed books created by my company. We do the typesetting of all our books with LaTeX. The design of these books requires coloured environments that stretch completely across the page as well as boxes in the margin containing lists of words etc.
Now, the problem I'm having is that when a margin environment occurs just before a page-wide environment, the margin box gets overlapped by the wide environment.
At the moment, we deal with this by hand, moving things around and recompiling the document until we have no more overlaps, but something better would be great.
Is there a way to force the margin box to be on top of anything typeset after it?
or
Can I somehow tell marginpar (or another margin note environment) to avoid having margin notes close to these environments?
Here is a MWE to illustrate the problem:
\documentclass[12pt, a4paper, openleft]{memoir}
\usepackage{blindtext}
\usepackage{environ}% enables you to pass environment contents to a command
\usepackage{tikz}
\usetikzlibrary{%
arrows,%
shapes,%
backgrounds,%
patterns,%
decorations.pathreplacing,%
decorations.pathmorphing,%
decorations.markings,%
shadows,%
shapes.misc,%
calc,%
positioning,%
intersections}
\tikzset{normal border/.style={orange!30!black!10}}
\pgfmathsetseed{1} % To have predictable results
% Start of Boxed Environment
%
% Macro to draw the shape behind the text, when it fits completly in the
% page
\def\WideEnvBoxframe#1{
\tikz{
\node[inner sep=2em, outer xsep=5cm] (A) {#1}; % Draw the text of the node
\begin{pgfonlayer}{background} % Draw the shape behind
\fill[fill=normalborder]
(A.south east) -- (A.south west) --
(A.north west) -- (A.north east) -- cycle;
\end{pgfonlayer}}}
% Macro to draw the shape, when the text will continue in next page
\def\WideEnvBoxframetop#1{
\begin{tikzpicture}[remember picture]
\node[inner sep=2em, outer xsep=5cm] (A) {#1}; % Draw the text of the node
\begin{pgfonlayer}{background}
\fill[fill=normalborder] % Draw the ``complete shape'' behind
(A.south east) -- (A.south west) --
(A.north west) -- (A.north east) -- cycle;
\end{pgfonlayer}
% \node[] (empty) at (current page.south west) {};
% \fill[fill=red]
% ($ (empty.south east)+(0,2)$) -- ($ (empty.south west)+(0,2)$) -- (empty.south west) -- (empty.south east) -- cycle;
\end{tikzpicture}
% fill in the white space gap between bottom of frame and footer
\begin{tikzpicture}[remember picture,overlay]
\begin{pgfonlayer}{background}
\fill[fill=normalborder,opacity=1]
($(A.south west)+(-1,0.1)$) rectangle
($(current page.south east)+(2,2.2)$);
\end{pgfonlayer}
\end{tikzpicture}
}
% Macro to draw the shape, when the text continues from previous page
\def\WideEnvBoxframebottom#1{
\tikz{
\node[inner sep=0.2em, outer xsep=5cm, outer ysep=0cm] (A) {#1}; % Draw the text of the node
\begin{pgfonlayer}{background}
\fill[fill=normalborder] % Draw the ``complete shape'' behind
(A.south east) -- (A.south west) --
(A.north west) -- (A.north east) -- cycle;
\end{pgfonlayer}}
% fill in the white space gap between bottom of frame and footer
\begin{tikzpicture}[overlay,remember picture]
\begin{pgfonlayer}{background}
\fill[fill=normalborder,opacity=1]
($(current page.north west)+(-3mm,3mm)$) rectangle
($(current page.north east)+(3mm,-2.25cm)$);
\end{pgfonlayer}
\end{tikzpicture}}
% Macro to draw the shape, when both the text continues from previous page
% and it will continue in next page
\def\WideEnvBoxframemiddle#1{
\begin{tikzpicture}[remember picture]
\node[inner sep=0.2em, outer xsep=5cm, outer ysep=0cm] (A) {#1}; % Draw the text of the node
\begin{pgfonlayer}{background}
\fill[fill=normalborder] % Draw the ``complete shape'' behind
(A.south east) -- (A.south west) --
(A.north west) -- (A.north east) -- cycle;
\end{pgfonlayer}
\end{tikzpicture}
% fill in the white space gap between bottom of frame and footer
\begin{tikzpicture}[overlay,remember picture]
\begin{pgfonlayer}{background}
\fill[fill=normalborder,opacity=1]
($(A.south west)+(-1,0.1)$) rectangle
($(current page.south east)+(2,0)$);
\end{pgfonlayer}
\end{tikzpicture}
% fill in the white space gap between top of frame and header
\begin{tikzpicture}[overlay,remember picture]
\begin{pgfonlayer}{background}
\fill[fill=normalborder,opacity=1]
([xshift=-3mm, yshift=3mm] current page.north west) rectangle
([yshift=-2.25cm, xshift=3mm] current page.north east);
\end{pgfonlayer}
\end{tikzpicture}}
% Define the environment which puts the frame
% In this case, the environment also accepts an argument with an optional
% title (which defaults to ``Example'', which is typeset in a box overlaid
% on the top border
\newenvironment{WideEnvBox}[2]{%
\tikzset{normalborder/.style={#2}}
\def\FrameCommand{\WideEnvBoxframe}%
\def\FirstFrameCommand{\WideEnvBoxframetop}%
\def\LastFrameCommand{\WideEnvBoxframebottom}%
\def\MidFrameCommand{\WideEnvBoxframemiddle}%
\MakeFramed {\FrameRestore}
%\needspace{9\baselineskip}
{#1}\par
}%
{\endMakeFramed}
\definecolor[named]{activity}{HTML}{E1E6D1}
\newenvironment{Activity}[1]{%
\colorlet{normalborder}{activity}
\begin{WideEnvBox}{\sffamily\large\textbf{ACTIVITY:} #1}{activity}%
}{%
\end{WideEnvBox}%
}
% End of Boxed Environment
%
% Margin box
%
\definecolor[named]{newwords}{HTML}{FCD2C1}
\tikzstyle{newwordsblock} = [rectangle, fill=newwords, text badly centered, text width=2.5cm, rounded corners=10pt, draw=black, very thick]
\NewEnviron{NoteNewwords}{%
\marginpar{\begin{tikzpicture}
\node[] (text) [newwordsblock]
{\vskip1mm\small\textbf{New Words}\vskip2mm\hrule\vspace{3mm}\scriptsize\BODY\vspace{3mm}};
\node[below=0.5cm of text] (dummytext) [newwordsblock] {\vspace{50mm}};
\end{tikzpicture}}%
}
\begin{document}
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}
\begin{NoteNewwords}
\blindlist{itemize}[6]
\end{NoteNewwords}
\begin{Activity}{Example}
\blindtext[3]
\end{Activity}
\end{document}
pgfdeclarelayer
in the manual. You can put the margin stuff in a "foreground" layer, or the green box in a "background" layer. – John Wickerson Jun 5 '13 at 12:20tikzpicture
environment, I'm not sure one can define a global document-wide layer (which is exactly what I need) i.e. stuff on theforeground
layer is always above stuff in thebackground
layer, regardless of where and when they were typeset. – ezietsman Jun 5 '13 at 12:26mdframed
package if it fits my needs. – Malipivo Apr 4 '14 at 20:02