\part 标题样式

\part 标题样式

我正在使用\documentclass{book}。我喜欢将我的\part风格重新定义为类似于下图中的东西。所以,我喜欢当我使用部分时,我会得到类似于下图的东西,顶部是“部分”,而不是章节,里面有一个灰色矩形,里面有一个数字。有什么想法可以做到这一点吗?

在此处输入图片描述

答案1

\documentclass[a4paper]{book}
\usepackage[T1]{fontenc}
\usepackage{libertine}
\usepackage[table]{xcolor}
\makeatletter
%\renewcommand\thepart{\arabic{part}}
\def\@part[#1]#2{%
    \ifnum \c@secnumdepth >-2\relax
      \refstepcounter{part}%
      \addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%
    \else
      \addcontentsline{toc}{part}{#1}%
    \fi
    \markboth{}{}%
  \reset@font
  \parindent \z@ 
  \vspace*{10\p@}%
  \hbox{%
    \vbox{%
      \hsize=7mm%
      \begin{tabular}{@{}p{7mm}@{}}
        \makebox[7mm]{\scshape\strut\small\partname}\\
        \makebox[7mm]{\cellcolor{black}\Huge\color{white}\bfseries\strut\thepart\rule[-4cm]{0pt}{4cm}}%
      \end{tabular}%
      \makebox(0,0){\put(-10,-100){\fbox{\phantom{\rule[-4cm]{7mm}{4cm}}}}}
      }%
    \kern-2pt
    \vbox to 0pt{%
       \tabular[t]{@{}p{1cm}p{\dimexpr\hsize-2.1cm}@{}}\hline
          & \Huge\itshape\rule{0pt}{1.5\ht\strutbox}#1\endtabular}%
    }%
  \cleardoublepage
%  \vskip 100\p@
}
\makeatother

\begin{document}
\part{Books in \LaTeX}

\end{document}

在此处输入图片描述

答案2

另一种解决方案是使用ebgaramond字体及其字母首字母。我试图让代码尽可能通用,但一些参数(主要用于raisebox)可能取决于字体。我还试图让结果尽可能接近 OP 的图片,再加上一些颜色。部分标题的格式是用 进行的titlesec

添加:我设法epigraphs在部分页面上添加了environetoolbox包。要使用的命令是\thispartepigrah{text}{source}。它将布尔值设置withepi为 true,允许将题词显示为 的可选参数\titleformat,然后使用 epi 重置为falseepigraph命令本身是通过虚假环境捕获的PartEpigraph

    \documentclass[12pt]{book}
    \usepackage[utf8]{inputenc}
    \usepackage{microtype} 
    \usepackage[garamond]{mathdesign}
    \usepackage{garamondx}%%
    \usepackage[x11names]{xcolor}
    \usepackage{graphicx}
    \usepackage{etoolbox}
    \usepackage{epigraph}
    \usepackage{environ} 

    \setlength\epigraphwidth{0.5\linewidth}
    \newbool{withepi}
    \NewEnviron{PartEpigraph}
    {\global\let\mypartepigraph\BODY}%
    \newcommand\thispartepigraph[2]{%
    \setbool{withepi}{true}%
    \begin{PartEpigraph}
      \epigraph{#1}{#2}
    \end{PartEpigraph}}%

    \usepackage{geometry}
    \usepackage{titlesec}%[newparttoc]
    \usepackage{lettrine}
    \renewcommand\LettrineFontHook{\fontfamily{EBGaramondInitials-TLF}\color{titlecolour}}
    %

    \setlength\fboxrule{0.6pt}
    \colorlet{titlecolour}{DarkSeaGreen4!80}
    \newlength\labelframewd
    \settowidth{\labelframewd}{~\footnotesize\textsc{part}~}

    \newsavebox\partlabelbox%

    \newcommand\partlabel{%
    \makebox[0pt]{\fcolorbox{titlecolour}{titlecolour}{%
    \raisebox{8.4ex}[0pt]{\rlap{\hspace{-\fboxsep}\resizebox*{\dimexpr\labelframewd+2\fboxsep\relax}{!}{\color{titlecolour}\lsstyle\scshape\scriptsize{part}}}}%
    \usebox{\partlabelbox}}}
    \hskip-\fboxsep\color{titlecolour}{\raisebox{-9ex}{\fbox{\phantom{\usebox{\partlabelbox}}}}}
    }%

    \titleformat{\part}[display]{}
    {%
    \sbox{\partlabelbox}{\raisebox{0pt}[7ex][27ex]{\resizebox{\labelframewd}{!}{\hfill\color{white}{\arabic{part}}\hfill}}}
    \smash{\partlabel}}%
    {6ex}
    {\thispagestyle{empty}{\color{titlecolour}\titlerule[\fboxrule]}\vskip2.5ex\hspace*{3\labelframewd}\fontsize{32}{40}\itshape}%
    [\ifbool{withepi}{\vspace{4\baselineskip}\mypartepigraph\global\setbool{withepi}{false}}{}]

    \titlespacing{\part}{0pt}{1.25\baselineskip}{10\baselineskip}
    \renewcommand*\thepart{\arabic{part}}

    \begin{document} 

    \thispartepigraph{For the Snark \emph{was} a Boojum,  you see.}{Lewis Carroll     --- \emph{The Hunting of the Snark}}

    \part{Books in \LaTeX}

    \lettrine{T}{ext} text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text.

    \end{document}

在此处输入图片描述

在此处输入图片描述

相关内容