重现 Legrand Orange Book 的章节图片风格

重现 Legrand Orange Book 的章节图片风格

我正在尝试重现罗格朗橙皮书但使用类scrbook。由于图片和章节标题是由fancyhdr我设置的,因此我不能只使用相同的代码,因为scrbook与模板配合不好。因此我试图重现这一部分。到目前为止,我可以插入图片并绘制带有一些文本的橙色框。但是我不知道如何让它工作,以便我可以将其用作自动设置标题的函数。

编辑:tikz对于这种事情,是否真的有必要这样做或者这是一种好的做法?

\documentclass[a4paper]{scrbook}
\usepackage{tikz}
\usepackage{xcolor}
\definecolor{ocre}{RGB}{243,102,25}

\begin{document}

\begin{tikzpicture}[remember picture,overlay]
  \node at (current page.north west)
  {\begin{tikzpicture}[remember picture,overlay]
    \node[anchor=north west,inner sep=0pt] at (0,0) {\includegraphics[width=\paperwidth]{pic}}; 
    \draw[anchor=west] (5cm,-9cm) node [line width=2pt,rounded corners=15pt,draw=ocre,fill=white,fill opacity=0.5,inner sep=15pt]{\strut\makebox[13cm]{}};
    \draw[anchor=west] (5.3cm,-9.1cm) node {\huge\sffamily\bfseries\color{black}1. Title of a Chapter\strut};
  \end{tikzpicture}};
\end{tikzpicture}
\vspace*{10cm}

Content of the chapter.

\end{document}

在此处输入图片描述

答案1

更新重新定义\chapterlinesformat

自 KOMA-Script 版本 3.19 起,\chapterlinesformat可以重新定义该命令以更改没有前缀行的章节标题的布局。现在可以为页面标题设置不同的条目,或使用带星号的章节标题命令版本。也可以使用多行章节标题。

下面的例子用来open=any表明它也适用于左手页面。

\documentclass[open=any]{scrbook}[2015/10/03]
%\providecommand*\Ifthispageodd{\ifthispageodd}% needed up to and including KOMA-Script version 3.27, see https://komascript.de/faq_deprecatedif
\usepackage{blindtext}% dummy text
\usepackage{tikz}
\usetikzlibrary{positioning}

\RedeclareSectionCommand[
  beforeskip=1sp minus 1sp,
  afterskip=4\baselineskip plus .5ex minus .5ex
]{chapter}

\newcommand*\chapterimageheight{.5\paperwidth}% height of the chapter images
\newcommand*\chapterboxvoffset{1cm}% offset from text bottom to image bottom
\newcommand*\chapterboxhoffset{1cm}% offset from outer text margin to outer box border
\newcommand*\chapterboxwidth{\textwidth+1cm}% width of the chapter box 
\newcommand*\chapterboxsep{1em}% inner sep of the chapter box

\definecolor{ocre}{RGB}{243,102,25}
\colorlet{chapterbordercolor}{ocre}

\tikzset{
  chapterbox/.style={
    line width=2pt,rounded corners=20pt,draw=chapterbordercolor,
    fill=white,fill opacity=.5,text opacity=1,
    inner sep=\chapterboxsep,
    font=\usekomafont{disposition}\usekomafont{chapter}\huge
  }
}

\makeatletter
\newcommand*\@chapterimage{example-image.pdf}
\newcommand*\chapterimage[1]{\renewcommand*\@chapterimage{#1}}

\renewcommand\chapterlinesformat[3]{%
  \vspace*{\dimexpr-1in-\headsep-\headheight-\topmargin-1ex\relax}%
  \Ifthispageodd
    {\hspace*{\dimexpr-1in-\oddsidemargin\relax}%
      \tikzset{chapterboxpos/.style={
        anchor=south east,
        above left= \chapterboxvoffset and \chapterboxhoffset of bb.south east
      }}%
    }
    {\hspace*{\dimexpr\textwidth+1in+\oddsidemargin-\paperwidth\relax}%
      \tikzset{chapterboxpos/.style={
        anchor=south west,
        above right= \chapterboxvoffset and \chapterboxhoffset of bb.south west
      }}%
    }%
  \makebox[0pt][l]{%
    \parbox[b][\chapterimageheight][b]{\paperwidth}{%
      \begin{tikzpicture}[inner sep=0pt,outer sep=0pt]
        \node[use as bounding box,minimum width=\paperwidth,minimum height=\chapterimageheight](bb){};
        \node[anchor=center] at (bb.center)
          {\includegraphics[width=\paperwidth,height=\chapterimageheight]
            {\@chapterimage}};
        \node[chapterbox,chapterboxpos]
          {\parbox{\dimexpr\chapterboxwidth-\chapterboxsep*2\relax}{\@hangfrom{#2}{\raggedchapter#3}}};
      \end{tikzpicture}%
    }%
  }%
}%
\makeatother

\begin{document}
\chapterimage{chapter_head_1}

\tableofcontents
\addchap*{Unnumbered Chapter without entry in table of contents}
\Blindtext
\addchap{Unnumbered Chapter with entry in table of contents}
\Blindtext[2]
\chapter{Numbered chapter}
\blindtext
\chapter[Numbered chapter with long title]{Numbered chapter that is really long and needs more than one line}
\chapterimage{chapter_head_2}% change the image
\colorlet{chapterbordercolor}{purple!80!black}% change the bordercolor
\Blindtext[10]
\blinddocument
\end{document}

运行两次(因为\Ifthispageodd)得到

在此处输入图片描述

答案2

这是一个解决方案

\documentclass[a4paper]{scrbook}
\usepackage{tikz}
\usepackage{xcolor}
\definecolor{ocre}{RGB}{243,102,25}

\newcommand{\mychapheader}[2][]{%  #1 chapter's number #2 title of chapter
\begin{tikzpicture}[remember picture,overlay]
  \node at (current page.north west)
  {\begin{tikzpicture}[remember picture,overlay]
    \node[anchor=north west,inner sep=0pt] at (0,0) {\includegraphics[width=\paperwidth]{pic}}; 
    \draw[anchor=west] (5cm,-9cm) node [line width=2pt,rounded corners=15pt,draw=ocre,fill=white,fill opacity=0.5,inner sep=15pt]{\strut\makebox[13cm]{}};
    \draw[anchor=west] (5.3cm,-9.1cm) node {\huge\sffamily\bfseries\color{black}#1 #2\strut};
  \end{tikzpicture}};
\end{tikzpicture}
\vspace*{10cm}
}
\makeatletter
\renewcommand*{\@@makechapterhead}[1]{% for numbered chapter
\mychapheader[\thechapter.\ ]{#1}}

\renewcommand*{\@@makeschapterhead}[1]{%  for unnumbered (stared) chapter
\mychapheader{#1}}
\makeatother

\begin{document}
\chapter*{Title of chapter}

Content of the chapter.
\chapter{Title of chapter}

Content of the chapter.

\end{document}

相关内容