背景包-\NoBgThispage 不同的输出

背景包-\NoBgThispage 不同的输出

这个问题与我的另外两个问题相关:

这些问题所达成的设计如下图所示。

在此处输入图片描述

继续这项研究,我尝试暂时关闭颜色字段(例如,对于飞行标题,以及类似的需求)。我第一次通过包命令成功做到了这一点\NoBgThispagebackground但我发现,在当前文档的情况下,\NoBgThispage只有一次工作正确。

使用 LuaLaTeX 编译 MWE(3 次,一如既往)并查看:在第 7 页,哪里有一个飞行标题模型,没有彩色框架,但它在下一页再次出现。

在第11页,再次出现了飞行标题,但是之后的彩色框就不再出现。

\documentclass[a4paper,twoside,11pt]{ltjsarticle}

\usepackage[svgnames,x11names]{xcolor}% you need this before tikz to avoid an option clash
\usepackage{tikz,tikzpagenodes}
\usetikzlibrary{calc}
\usepackage{calc}% based rather loosely on code from the introduction to the geometry manual
\setlength\textwidth{\paperwidth-31mm}% 13+18=31
\setlength\oddsidemargin{(\paperwidth-\textwidth)/2 - 1in - 2.5mm}% .5*(13-18)=-2.5
\setlength\evensidemargin{(\paperwidth-\textwidth)/2 - 1in + 2.5mm}% .5*(18-13)=2.5
\setlength\topmargin{11mm-1in}
\setlength\headsep{3mm}
\setlength\footskip{3mm}
\setlength\marginparwidth{0pt}
\setlength\marginparsep{0pt}
\setlength\textheight{\paperheight-\headheight-\headsep-\footskip-22mm}% 2*11=22

\usepackage{titletoc}
\usepackage[pagestyles]{titlesec}
\usepackage{background}
\newcommand{\colourframe}[2][white]{%
  \clearpage
  \backgroundsetup{%
    angle=0,
    scale=1,
    opacity=1,
    contents={%
      \begin{tikzpicture}[remember picture, overlay]
        \path [fill=#2, even odd rule]
          (current page.south west) rectangle (current page.north east)
          ($(current page text area.south west) - (2mm,2mm)$) rectangle ($(current page text area.north east) + (2mm,2mm)$)
          ;
        \node [fill=#1, draw=black, anchor=north, text=black, inner xsep=5mm, inner ysep=1.5mm, yshift=-1mm] at ($(current page text area.south) - (0,2mm)$) {\thepage};
      \end{tikzpicture}},
    position=current page.south west,
    nodeanchor=south west
  }%
  \pagestyle{colourfancy}%
  \sethead[][][\thesection\quad\sectiontitle]{\thesection\quad\sectiontitle}{}{}%
  \setfoot[][][]{}{}{}%
  \colorlet{SectionFrameColor}{#2!50}%
  \colorlet{SectionFillColor}{#2!20}%
  \colorlet{SectionFontColor}{#2!80}%
  \titleformat{\section}[hang]{%
    \Large\sffamily\color{SectionFontColor}%
  }{%
    \begin{tikzpicture}
      [
        baseline={([yshift=-.8ex]current bounding box.center)},
      ]
      \node [thick, draw=SectionFrameColor, fill=SectionFillColor, rectangle, rounded corners, text=white] {\thesection};
    \end{tikzpicture}%
  }{12pt}{}[{\titlerule[1pt]}]%
  \titleformat{\paragraph}[hang]{\bfseries}{}{}{}[]}

\newpagestyle{colourfancy}[]{}
\newpagestyle{tocandintro}[]{\headrule\setheadrule{0.5mm}\footrule\setfootrule{0.5mm}}
\backgroundsetup{%
  contents={},
}

\usepackage{lipsum}

\begin{document}

\pagestyle{tocandintro}
\sethead[Table of contents][][]{}{}{Table of contents}
\setfoot[\thepage][][ABC Project]{ABC Project}{}{\thepage}

\tableofcontents

\clearpage% uncomment if you don't want to have Intro in the header of the final contents page
\sethead[Intro][][]{}{}{Intro}
Intro text

\colourframe[orange]{red}
\part{RED}
\section{Red section}
\subsection{Red A}
\subsubsection{Red AA}

\lipsum{3-50}

\subsubsection{Red AB}

\lipsum{3-50}  

\subsection{Red B}
\subsubsection{Red BA}

\cleardoublepage
\thispagestyle{empty}
\NoBgThispage
\part{BLUE}
\quad

\newpage\pagestyle{plain}
\colourframe[cyan]{blue}
\section{Blue section}
\subsubsection{Blue AA}

\lipsum{3-50}  
\subsubsection{Red AB}
\lipsum{3-50}  

\cleardoublepage
\thispagestyle{empty}
\NoBgThispage
\part{GREEN}
\quad

\newpage\pagestyle{plain}
\colourframe[DarkSeaGreen1]{Green1}
\section{Green section}
\subsubsection{Blue AA}

\lipsum{3-50}  
\subsubsection{Red AB}
\lipsum{3-50}  

\end{document}

答案1

这是一个解决方法。定义

\newcommand{\nocolourframe}{%
  \clearpage
  \backgroundsetup{%
    contents={}
    }
    \pagestyle{empty}
  }

并像使用它一样

\cleardoublepage
%\thispagestyle{empty}
%\NoBgThispage
\nocolourframe
\part{GREEN}
\quad

在此处输入图片描述

\documentclass[a4paper,twoside,11pt]{article}

\usepackage[svgnames,x11names]{xcolor}% you need this before tikz to avoid an option clash
\usepackage{tikz,tikzpagenodes}
\usetikzlibrary{calc}
\usepackage{calc}% based rather loosely on code from the introduction to the geometry manual
\setlength\textwidth{\paperwidth-31mm}% 13+18=31
\setlength\oddsidemargin{(\paperwidth-\textwidth)/2 - 1in - 2.5mm}% .5*(13-18)=-2.5
\setlength\evensidemargin{(\paperwidth-\textwidth)/2 - 1in + 2.5mm}% .5*(18-13)=2.5
\setlength\topmargin{11mm-1in}
\setlength\headsep{3mm}
\setlength\footskip{3mm}
\setlength\marginparwidth{0pt}
\setlength\marginparsep{0pt}
\setlength\textheight{\paperheight-\headheight-\headsep-\footskip-22mm}% 2*11=22

\usepackage{titletoc}
\usepackage[pagestyles]{titlesec}
\usepackage{background}
\newcommand{\colourframe}[2][white]{%
  \clearpage
  \backgroundsetup{%
    angle=0,
    scale=1,
    opacity=1,
    contents={%
      \begin{tikzpicture}[remember picture, overlay]
        \path [fill=#2, even odd rule]
          (current page.south west) rectangle (current page.north east)
          ($(current page text area.south west) - (2mm,2mm)$) rectangle ($(current page text area.north east) + (2mm,2mm)$)
          ;
        \node [fill=#1, draw=black, anchor=north, text=black, inner xsep=5mm, inner ysep=1.5mm, yshift=-1mm] at ($(current page text area.south) - (0,2mm)$) {\thepage};
      \end{tikzpicture}},
    position=current page.south west,
    nodeanchor=south west
  }%
  \pagestyle{colourfancy}%
  \sethead[][][\thesection\quad\sectiontitle]{\thesection\quad\sectiontitle}{}{}%
  \setfoot[][][]{}{}{}%
  \colorlet{SectionFrameColor}{#2!50}%
  \colorlet{SectionFillColor}{#2!20}%
  \colorlet{SectionFontColor}{#2!80}%
  \titleformat{\section}[hang]{%
    \Large\sffamily\color{SectionFontColor}%
  }{%
    \begin{tikzpicture}
      [
        baseline={([yshift=-.8ex]current bounding box.center)},
      ]
      \node [thick, draw=SectionFrameColor, fill=SectionFillColor, rectangle, rounded corners, text=white] {\thesection};
    \end{tikzpicture}%
  }{12pt}{}[{\titlerule[1pt]}]%
  \titleformat{\paragraph}[hang]{\bfseries}{}{}{}[]}

\newcommand{\nocolourframe}{%
  \clearpage
  \backgroundsetup{%
    contents={}
    }
    \pagestyle{empty}
  }


\newpagestyle{colourfancy}[]{}
\newpagestyle{tocandintro}[]{\headrule\setheadrule{0.5mm}\footrule\setfootrule{0.5mm}}
\backgroundsetup{%
  contents={},
}

\usepackage{lipsum}

\begin{document}

\pagestyle{tocandintro}
\sethead[Table of contents][][]{}{}{Table of contents}
\setfoot[\thepage][][ABC Project]{ABC Project}{}{\thepage}

\tableofcontents

\clearpage% uncomment if you don't want to have Intro in the header of the final contents page
\sethead[Intro][][]{}{}{Intro}
Intro text

\colourframe[orange]{red}
\part{RED}
\section{Red section}
\subsection{Red A}
\subsubsection{Red AA}

\lipsum{3-50}

\subsubsection{Red AB}

\lipsum{3-50}

\subsection{Red B}
\subsubsection{Red BA}

\cleardoublepage
%\thispagestyle{empty}
\nocolourframe
%\NoBgThispage
\part{BLUE}
\quad

\newpage\pagestyle{plain}
\colourframe[cyan]{blue}
\section{Blue section}
\subsubsection{Blue AA}

\lipsum{3-50}
\subsubsection{Red AB}
\lipsum{3-50}

\cleardoublepage
%\thispagestyle{empty}
%\NoBgThispage
\nocolourframe
\part{GREEN}
\quad

\newpage\pagestyle{plain}
\colourframe[DarkSeaGreen1]{Green1}
\section{Green section}
\subsubsection{Blue AA}

\lipsum{3-50}
\subsubsection{Red AB}
\lipsum{3-50}

\cleardoublepage
%\thispagestyle{empty}
%\NoBgThispage
\nocolourframe
\part{GREEN}
\quad

\newpage\pagestyle{plain}
\colourframe[olive]{brown}
\section{Green section}
\subsubsection{Blue AA}

\lipsum{3-50}
\subsubsection{Red AB}
\lipsum{3-50}

\end{document}

相关内容