仅在附录页面上使用章节标签(titlesec、书籍类别)

仅在附录页面上使用章节标签(titlesec、书籍类别)

我对 LaTeX 并不像我希望的那样熟悉,并且在使用我继承的文档模板撰写论文时遇到了一些麻烦。

使用book类和titlesecappendix(如下所示),我试图删除章节中的“章节”,但保留附录中的“附录”一词。目录应该只包含章节编号和附录字母。

这段代码删除了“章节”一词......但自然,附录页面也未能幸免。

\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage{titlesec}
\usepackage[titletoc, title]{appendix}
\usepackage{lipsum}t
\titleformat{\chapter}[block]{\normalfont\bfseries\Large}{\thechapter}{15pt}{}  % Not allowed to use the word 'chapter'.

\begin{document}  
\tableofcontents
\chapter{Chapters are cool.}
\lipsum[1-2]
\chapter{Books rock.}
\lipsum[1-3] 
\appendix
\chapter{Appendectomy info.}
It's good to have an appendix.
\end{document}

阅读此处的帖子后,我尝试了以下操作,但似乎不起作用。

\makeatletter
\newcommand{\setchapter}{\thechapter.~}
\newcommand{\setappendix}{Appendix~\thechapter:~}

\titleformat{\chapter}[display]{\normalfont\bfseries}{%
  \ifnum\pdfstrcmp{\@currenvir}{appendices}=0
    \setappendix
  \else
    \setchapter
  \fi}{2em}{\LARGE}
\makeatother

我读过一些页面来寻求见解,但是没有多大收获:

感谢任何见解!

答案1

\titleformat在使用新格式开始附录之前,只需重复该命令。

\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage{titlesec}
\usepackage[titletoc, title]{appendix}
\usepackage{lipsum}
\titleformat{\chapter}[block]{\normalfont\bfseries\Large}{\thechapter.}{0.5em}{}  % Not allowed to use the word 'chapter'.

\begin{document}  
\tableofcontents
\chapter{Chapters are cool.}
\lipsum[1-2]
\chapter{Books rock.}
\lipsum[1-3] 
\titleformat{\chapter}[block]{\normalfont\bfseries\Large}{Appendix~\thechapter:}{0.5em}{}  \appendix
\chapter{Appendectomy info.}
It's good to have an appendix.
\end{document}

在此处输入图片描述

在此处输入图片描述

在此处输入图片描述

在此处输入图片描述

相关内容