如何在 LaTeX 书中创建自定义 \part?

如何在 LaTeX 书中创建自定义 \part?

\part我正在尝试为 中的一本书创建自定义XeLaTeX。我希望能够以通常更大的字体显示零件编号和标题。但是,我还想在零件编号和标题下方添加一个简短的段落。

\documentclass[oneside,12pt,letterpaper,draft]{book}
\begin{document}
  \part{Custom Part}
  Text to be included as a paragraph below custom part. The text should be on the same page just under the heading. 
  \chapter{The first chapter}
  Here is my text for chapter 1. 
\end{document}

这是我想复制的一本书中的例子。

在此处输入图片描述

答案1

未使用包的版本。\partname已移至左边距外!

\documentclass[oneside,12pt,letterpaper,draft]{book}

\newlength{\partheaderrulewidth}
\setlength{\partheaderrulewidth}{0.5pt}
\newlength{\leftheadingshift}
\makeatletter
\newbox\boxtemp


\def\@part[#1]#2#3{%
  \leftheadingshift\z@
  \setbox\boxtemp=\hbox{\nobreakspace}
  \addtolength{\leftheadingshift}{\wd\boxtemp}
  \setbox\boxtemp=\hbox{\huge\bfseries\partname}
  \addtolength{\leftheadingshift}{\wd\boxtemp}

  \ifnum \c@secnumdepth >-2\relax
  \refstepcounter{part}%
  \addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%
  \else
  \addcontentsline{toc}{part}{#1}%
  \fi
  \markboth{}{}%
  {%
    \parindent=0em
    \interlinepenalty \@M
    \normalfont
    \ifnum \c@secnumdepth >-2\relax
    % Shift the partname to the margin (Release the box!)
    \hskip-\leftheadingshift\unhbox\boxtemp\nobreakspace\huge\bfseries\thepart%
    \par
    \vskip 10\p@
    \fi
  }    
  \parindent=0em%
  {\Huge\bfseries #2}%
  \medskip

  \rule{\linewidth}{\partheaderrulewidth}
  {\normalfont #3}
  \vskip-\smallskipamount
  \rule{\linewidth}{\partheaderrulewidth}
  \@endpart
}


\newcommand{\specialpart}[3][]{%
  \@ifnextchar[{\part[#1]{#2}{#3}}{\part{#2}{#3}}%
}

\makeatother 

\begin{document}
\tableofcontents
  \specialpart{Custom Part}{Text to be included as a paragraph below custom part. The text should be on the same page just under the heading.}
  \chapter{The first chapter}
  Here is my text for chapter 1. 

  \specialpart[Foo]{Custom Part}{Text to be included as a paragraph below custom part. The text should be on the same page just under the heading.}
\end{document}

在此处输入图片描述

相关内容