使用 Tikz 和报告类自定义章节样式

使用 Tikz 和报告类自定义章节样式

我正在尝试使用相同的程序使用 tikz 自定义章节样式,用于报告类和双面打印。

但是对于偶数页,我遇到了意料之外的行为(见图 2)。而对于奇数页,我没有遇到问题(见图 1)。

图1 图。1

图 2 图2

我读过 titlesec 的文档,其中可以使用\titleformat{name=\chapter,page=even/odd}偶数页或奇数页的额外选项,但是当我编译更简单版本的代码时,颜色框不会显示在 pdf 中。

\documentclass[11pt, a4paper,twoside]{report}
\usepackage{lipsum}
\usepackage[explicit]{titlesec}
\usepackage{fourier}
\usepackage{tikz}
\usepackage{epigraph}
\usepgflibrary{qrr.shapes.openrectangle}

\definecolor{mybluei}{RGB}{0,173,239}
\definecolor{myblueii}{RGB}{63,200,244}
\definecolor{myblueiii}{RGB}{199,234,253}

\tikzset{
mynode/.style={
  rounded corners=30pt,
  shape=open rectangle,
  open rectangle fill=myblueii,
  open rectangle sides=#1,
  }
}

\titleformat{name=\chapter,page=even}[display]
  {\usefont{T1}{qhv}{b}{n}\selectfont}
  {}
  {20pt}
  {%
  \begin{tikzpicture}[remember picture,overlay]
  \node[
    anchor=west,
    rectangle,
    minimum height=4cm,
    text width=\paperwidth,
    xshift=-\the\dimexpr\oddsidemargin+1in\relax,
    outer sep=0pt,
    fill=myblueiii] (titlerect) {};
  \node[
    anchor=south west,
    xshift=2cm,
    text width=\textwidth] 
    at ([yshift=5pt]titlerect.south west) {\huge #1};
  \node[
    mynode=nw,
    anchor=south east,
    fill=myblueii,
    inner xsep=1.5cm,
    outer sep=0pt,
    font=\color{white},
    minimum height=30pt] 
    at (current page.east|-titlerect.north)
     {\bfseries\MakeUppercase{\chaptertitlename}\ \thechapter};
  \end{tikzpicture}%
  }
\titleformat{name=\chapter,page=odd}[display]
  {\usefont{T1}{qhv}{b}{n}\selectfont}
  {}
  {20pt}
  {%
  \begin{tikzpicture}[remember picture,overlay]
  \node[
    anchor=west,
    rectangle,
    minimum height=4cm,
    text width=\paperwidth,
    xshift=-\the\dimexpr\oddsidemargin+1in\relax,
    outer sep=0pt,
    fill=myblueiii] (titlerect) {};
  \node[
    anchor=south west,
    xshift=2cm,
    text width=\textwidth] 
    at ([yshift=5pt]titlerect.south west) {\huge #1};
  \node[
    mynode=nw,
    anchor=south east,
    fill=myblueii,
    inner xsep=1.5cm,
    outer sep=0pt,
    font=\color{white},
    minimum height=30pt] 
    at (current page.east|-titlerect.north)
     {\bfseries\MakeUppercase{\chaptertitlename}\ \thechapter};
  \end{tikzpicture}%
  }
\titleformat{name=\chapter,numberless}[display]
  {\usefont{T1}{qhv}{b}{n}\selectfont}
  {}
  {20pt}
  {\huge #1}
\titlespacing*{\chapter}
  {0pt}{-20pt}{60pt}


\begin{document}

\chapter{Chapter odd}
\lipsum[2]
\chapter{Chapter even}
\lipsum[2]
\chapter*{Numberless chapter}

\end{document}

我怎么解决这个问题?。

答案1

我注意到与该解决方案类似的问题,并设法想出了以下替代方案(我的tikz技能不是那么好):

在此处输入图片描述

\documentclass[11pt, a4paper,twoside]{report}
\usepackage{lipsum}
\usepackage[explicit]{titlesec}
\usepackage{fourier}
\usepackage{tikzpagenodes}% Loads tikz
\usepgflibrary{qrr.shapes.openrectangle}

\definecolor{mybluei}{RGB}{0,173,239}
\definecolor{myblueii}{RGB}{63,200,244}
\definecolor{myblueiii}{RGB}{199,234,253}

\tikzset{
mynode/.style = {
  rounded corners = 30pt,
  shape=open rectangle,
  open rectangle fill = myblueii,
  open rectangle sides = #1,
  }
}

\titleformat{\chapter}[display]
  {\usefont{T1}{qhv}{b}{n}\selectfont}
  {}
  {20pt}
  {%
  \begin{tikzpicture}[remember picture, overlay]
  \node[
    anchor = west,
    rectangle,
    minimum height = 4cm,
    ] 
    (titlerect) {};
  \fill[color = myblueiii] ([xshift = -1cm]current page.west|-titlerect.south) rectangle (current page.east|-titlerect.north);
  \node[
    anchor = south west,
    xshift = -1cm,
    text width = \textwidth] 
    at ([yshift = 5pt]titlerect.south west) {\huge #1};
  \node[
    mynode = nw,
    anchor = south east,
    fill = myblueii,
    inner xsep = 1.5cm,
    outer sep = 0pt,
    font = \color{white},
    minimum height = 30pt] 
    at (current page.east|-titlerect.north)
     {\bfseries\MakeUppercase{\chaptertitlename}\ \thechapter};%
  \end{tikzpicture}%
  }
\titleformat{name = \chapter, numberless}[display]
  {\usefont{T1}{qhv}{b}{n}\selectfont}
  {}
  {20pt}
  {%
  \begin{tikzpicture}[remember picture, overlay]
  \node[
    anchor = west,
    rectangle,
    minimum height = 4cm,
    ] 
    (titlerect) {};
  \fill[color = myblueiii] ([xshift = -1cm]current page.west|-titlerect.south) rectangle (current page.east|-titlerect.north);
  \node[
    anchor = south west,
    xshift = -1cm,
    text width = \textwidth] 
    at ([yshift = 5pt]titlerect.south west) {\huge #1};
  \end{tikzpicture}%
  }
\titlespacing*{\chapter}
  {0pt}{-20pt}{60pt}

\begin{document}

\chapter{Chapter odd}
\lipsum[2]
\chapter{Chapter even}
\lipsum[2]
\chapter*{Numberless chapter}

\end{document}

我在用着tikzpagenodes设置彩色框时利用页面边界,而不是手动移动它们。

相关内容