仅显示章节编号(而不是名称)作为章节标题?

仅显示章节编号(而不是名称)作为章节标题?

我正在写的书中的章节都是有名字的。但是,虽然我希望名称显示在目录中,但我希望数字和数字只显示为章节标题。(我知道这听起来很奇怪,如果这很重要,我很乐意解释原因。)

例如,第 I 章的名称是“De Puero Superstite”。我希望“De Puero Superstite”显示在目录中,但只显示数字 I 作为章节标题。(我已经将其设置为罗马数字。)

有办法吗?如果需要,我可以使用titlesec重新定义标题格式,完全省略数字,然后执行例如\chapter[De Puero Superstite]{I},但必须有更优雅的方式来做到这一点。

有什么想法吗?

编辑:我所说的“章节标题”不是指页眉——例如,出现在每个左页(或每个右页,或每个页)最顶部的内容,而是在章节文本开始之前出现一次的内容。

答案1

这取决于您是否希望目录条目出现在页眉中。目录条目和页眉条目必须相同。

% chapternameprob.tex  SE 544473 no name in division header
%\documentclass{memoir}
\documentclass{book}
\usepackage{lipsum}
\renewcommand{\chaptername}{} % eliminate Chapter in divisional heading
\begin{document}
\tableofcontents
\chapter[toc and header entry]{} % empty divisional title
\lipsum
\end{document}

为了使它们不同,请使用以下memoir类:

% chapternameprob.tex  SE 544473 no name in division header
\documentclass{memoir}
%\documentclass{book}
\usepackage{lipsum}
\renewcommand{\chaptername}{}
\begin{document}
\tableofcontents
\chapter[toc entry][header entry]{}
\lipsum
\end{document}

该类memoir使您能够在目录、页眉和主文档中为所有部门命令设置不同的条目(\chapter... \subparagraph

答案2

尝试这个。

\documentclass{book}
\usepackage{titlesec}
\usepackage{xpatch} % for \xpatchcmd
\usepackage{lipsum} % for \lipsum to produce dummy texts 

\makeatletter
% hide chapter title (e.g., "first title")
\xpatchcmd\ttl@mkchap
  {\ttl@mkchap@i{#1}{#2}{#3}{#4}{#5}{#6}{#7}}
  {\ttl@mkchap@i{#1}{#2}{#3}{#4}{#5}{#6}{}}
  {}{\fail}
\makeatother

% hide \chaptername (the word "Chapter" followed by a space)
% based on `texdoc titlesec`, sec. 9.2
\titleformat{\chapter}[display]
  {\normalfont\huge\bfseries}
  % before: {\chaptername\ \thechapter}
  {\thechapter}
  {20pt}
  {\Huge}

\renewcommand\thechapter{\Roman{chapter}}

\begin{document}
\chapter{first title}
\lipsum

\chapter{second title}
\lipsum
\end{document}

在此处输入图片描述 在此处输入图片描述

相关内容