章节标题格式

章节标题格式

我正在上回忆录课,想将章节标题格式化如下:

作者的姓名和生卒年份位于顶部,然后是与上述详细信息长度相同的水平线,然后是标题,后面是可选的副标题。

答案1

一种可能性是实现一个“类似章节”的命令,以绕过必须有两个强制参数和一个可选参数的要求:

\documentclass[12pt,openany]{memoir}
\usepackage[T1]{fontenc}
\usepackage{lipsum}
\usepackage{etoolbox}
\usepackage{xparse}
\usepackage[colorlinks]{hyperref}
\usepackage{bookmark}

% Basic header-footer
\makepagestyle{title}
\makeevenhead{title}{}{\leftmark}{}
\makeevenfoot{title}{}{\thepage}{}
\makeoddhead{title}{}{\leftmark}{}
\makeoddfoot{title}{}{\thepage}{}
\pagestyle{title}


% the \chapterhead command (partially memoir-dependent)
\makeatletter
\NewDocumentCommand {\chapterhead} {mmo}
{\IfNoValueTF{#3}%
  {\clearforchapter
    \phantomsection
    \addcontentsline{toc}{chapter}{%
      % \numberline{}% <-- required if 'chapters' are numbered...
      \texorpdfstring{\MakeUppercase{#1}}{#1}\space #2}
    \markboth{#2}{#2}%
    \thispagestyle{chapter}%
    \insertchapterspace
    \chapterheadstart
    \setauthorname{#1}%
    \printauthorname
    \settowidth{\authornamelength}{#1}%
    \afterauthorname
    \setmainchaptertitle{#2}%
    \printchapterheadtitle
    \afterchapterheadtitle
    \printsubtitle
    \finchapterhead
    \@afterindentfalse\@afterheading% <-- prevent indentation at start of paragraph
  }%
  {\clearforchapter
    \phantomsection
    \addcontentsline{toc}{chapter}{%
      % \numberline{}%
      \texorpdfstring{\MakeUppercase{#1}}{#1}\space #2\space #3}
    \markboth{#2}{#2}%
    \thispagestyle{chapter}%
    \insertchapterspace
    \chapterheadstart
    \setauthorname{#1}%
    \printauthorname
    \settowidth{\authornamelength}{#1}%
    \afterauthorname
    \setmainchaptertitle{#2}%
    \printchapterheadtitle
    \afterchapterheadtitle
    \setsubtitle{#3}%
    \printsubtitle
    \finchapterhead
    \@afterindentfalse\@afterheading% <-- prevent indentation
  }%
}
\makeatother

% Auxiliary formatting macros:
\newlength\authornamelength
\newcommand*{\authornamefont}{\normalsize\normalfont}
\newcommand*{\mainchaptertitlefont}{\normalfont\large}
\newcommand*{\subtitlefont}{\normalsize\normalfont}
\newcommand{\afterauthorname}{%
  \par\centerline{\parbox{\authornamelength}{\hrulefill}}\par}%
\newcommand{\afterchapterheadtitle}{%
  {\par\addvspace{0.75\baselineskip}\noindent}}
\newcommand{\finchapterhead}{%
  {\par\addvspace{2\baselineskip}\noindent}}


% ARG. #1: Author name
\newcommand*{\setauthorname}[1]{\csdef{authorname}{#1}}
\newcommand{\printauthorname}{{\par\centering
  \authornamefont \scshape\MakeLowercase{\csuse{authorname}}\par}}%

% ARG. #2: Title
\newcommand*{\setmainchaptertitle}[1]{\csdef{mainchaptertitle}{#1}}
\newcommand{\printchapterheadtitle}{%
  {\par\centering \mainchaptertitlefont
    \MakeUppercase{\csuse{mainchaptertitle}}\par}}

% ARG. #3 (optional): Source
\newcommand*{\setsubtitle}[1]{\csdef{subtitle}{#1}}
\newcommand{\printsubtitle}{%
  {\par\centering \subtitlefont
    \textit{from} \csuse{subtitle}\par}}


\begin{document}

\tableofcontents

\chapterhead{Geoffrey Chaucer}{Roundel}[The Parliament of Fowls]

\lipsum

\chapterhead{Marcus Tullius Cicero}{Dream of Scipio}[On the Republic]

\lipsum[2]

\chapterhead{Plato}{The Myth of Er}
%[Republic] % <-- optional argument not needed

\lipsum[3]

% regular chapter
\chapter{ROUNDEL}

\lipsum[4]

\end{document}

相关内容