我正在尝试定义一个像这样的自定义章节样式(\documentclass{book}
):
我发现最接近的方法是使用
\usepackage[Glenn]{fncychap}
生成结果:
我已经在图像编辑器中创建了图片,因此忽略字体。
答案1
\documentclass{book}
\usepackage[explicit]{titlesec}
\usepackage{tikz}
\titleformat{\chapter}[display]
{\normalfont\Large\bfseries}
{}
{0pt}
{%
\begin{tikzpicture}
\node[draw,thick,rounded corners=15pt,,text width=\the\dimexpr\textwidth-12pt\relax,inner ysep=10pt]
(chaptitle)
{%
\\\parbox{3cm}{\centering\Huge \thechapter}%
\parbox{\dimexpr\linewidth-3cm\relax}{#1}%
};
\node[anchor=west,fill=white]
at ([xshift=15pt]chaptitle.north west) {\chaptertitlename};
\end{tikzpicture}%
}
\titleformat{name=\chapter,numberless}[display]
{\normalfont\Large\bfseries}
{}
{0pt}
{%
\begin{tikzpicture}
\node[draw,thick,rounded corners=15pt,,text width=\the\dimexpr\textwidth-12pt\relax,inner ysep=10pt]
(chaptitle)
{#1};
\end{tikzpicture}%
}
\begin{document}
\chapter*{Test unnumbered chapter}
\chapter{Test numbered chapter}
\end{document}
未编号章节的图片:
编号章节的图像: