边缘中的 TikZ 节点被页面范围的 tikz 环境覆盖

边缘中的 TikZ 节点被页面范围的 tikz 环境覆盖

我正在尝试改进我公司创作的公开许可书籍的排版。我们使用 LaTeX 对所有书籍进行排版。这些书籍的设计需要完全覆盖整个页面的彩色环境以及包含单词列表等的边距框。

现在,我遇到的问题是,当边距环境出现在页面宽度环境之前时,边距框会与宽环境重叠。

目前,我们手动处理这个问题,移动内容并重新编译文档,直到不再有重叠,但如果有更好的方法就更好了。

有没有办法强制边距框位于其后排版的任何内容的顶部?

或者

我能否以某种方式告诉 marginpar (或其他边际注释环境) 避免将边际注释靠近这些环境?

下面是一个 MWE 来说明这个问题:

\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}

边距框位于页面范围环境下方

答案1

像这样:

在此处输入图片描述

好吧,图层只能在单个tikzpicture环境中工作,在主图层上绘制多个东西是不可能的。因此,绘制将按照命令编写的自然顺序进行;在这里,您输入标记marginbox,然后输入页面范围环境的标记,因此后者覆盖了前者。

marginbox我在这里建议的解决方案是在绘制页面范围的环境后延迟绘制。但首先,计算稍后插入框的正确位置。以下是此命令和修改后的环境:

\newcommand{\tikzmark}[1]{\tikz[remember picture] \coordinate (#1);}

\NewEnviron{NoteNewwords}[1]{%
\begin{tikzpicture}[remember picture,overlay]
    \node (text) at (#1) [newwordsblock,anchor=north west]
    {\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}}%

调用时,\tikzmark命令将保存当前坐标,因此如果我们发出:

\marginpar{\tikzmark{here}}

这意味着我们\marginpar在当前插入点处放置一个标记。接下来,在绘制页面范围的环境后,我们可以使用marginbox位置信息的额外参数来调用该环境:

\begin{NoteNewwords}{here}
\blindlist{itemize}[6]
\end{NoteNewwords}

完整代码如下:

\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]

\newcommand{\tikzmark}[1]{\tikz[remember picture] \coordinate (#1);}

\NewEnviron{NoteNewwords}[1]{%
\begin{tikzpicture}[remember picture,overlay]
    \node (text) at (#1) [newwordsblock,anchor=north west]
    {\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}

\marginpar{\tikzmark{here}}

\begin{Activity}{Example}
\blindtext[3]
\end{Activity}

\begin{NoteNewwords}{here}
\blindlist{itemize}[6]
\end{NoteNewwords}



\end{document}

相关内容