再現羅格朗橙皮書章圖風格

再現羅格朗橙皮書章圖風格

我正在嘗試重現章節圖片風格羅格朗橙皮書但隨著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}

相關內容