使用 tikz 自定义章节样式

使用 tikz 自定义章节样式

我如何才能自定义章节样式,如下图所示? 在此处输入图片描述

先感谢您。

答案1

一种可能性是使用TikZepigraph包;顶部的圆角矩形是使用 pgf 库生成的,该库qrr.shapes.openrectangle奎伯比尔贝尔his answerTikz 形状类似于矩形,可选择绘制边框(可以在链接的答案中找到该图书馆的链接):

\documentclass{book}
\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{\chapter}[display]
  {\normalfont\huge\sffamily}
  {}
  {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) {\fontsize{30}{36}\selectfont#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]
  {\normalfont\huge\sffamily}
  {}
  {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 (titlerect.south west) {\Huge#1};
  \end{tikzpicture}%
  }
\titlespacing*{\chapter}
  {0pt}{-20pt}{60pt}

\setlength\beforeepigraphskip{1.5\baselineskip}
\setlength\afterepigraphskip{2\baselineskip}
\setlength\epigraphwidth{6.8cm}
\setlength\epigraphrule{0pt}
\renewcommand\epigraphsize{\large}
\renewcommand\textflush{flushright}

\let\oldepigraph\epigraph \renewcommand\epigraph[2]{%
  \oldepigraph{\color{mybluei}\itshape #1}{#2}}


\begin{document}

\chapter{From the Ground Up!}
\epigraph{In theory there is no difference \\ between theory and practice. \\ In practice there is.}{Lawrence ``Yogui'' Berra,1925 \\ New York Yankees baseball player}
\chapter*{A test unnumbered chapter}

\end{document}

在此处输入图片描述

答案2

我写了一个蒂克兹右上角圆角框的代码,因为我不想使用

\usepgflibrary{qrr.shapes.openrectangle}

这是我的代码:

\documentclass{book}

\usepackage{tikz}
\usetikzlibrary{positioning,calc,backgrounds}
\definecolor{mybluei}{RGB}{0,173,239}

\newcommand{\newtab}[2]{%
\begin{tikzpicture}
    \node[inner sep=2mm,text=white] (#1) {#2};
    \begin{scope}[on background layer]
        \draw[fill=mybluei] 
        ($ (#1.north east) $) 
        --($ (#1.north west) $)
        to[out=180,in=90]  ([xshift=-1cm]$(#1.south west) $)
          -- ($ (#1.south east) $)
          -- cycle;
    \end{scope}
\end{tikzpicture}% 
}

\begin{document}
\newtab{test}{CHAPTER 1}
\newtab{test}{This is another test} 
\newtab{test}{This is yet another test}
\end{document}

在此处输入图片描述

相关内容