我一直在寻找这个问题的答案,但我能想到的关键词却让我找到了与我需要的答案相关但相反的答案。我试图实现这样的目标:
也就是说,我希望介绍有一个标题,并且在通常找到“第 n 章”的位置有“介绍”这个词(如果我使用,那么这正是被删除的内容\chapter*
)。
我可以控制计数器,以便下一个将是第 1 章,并且我可以暂时用 重命名标题\renewcommand{\chaptername}{Introduction}
,但我得到的是“简介 0”,我怎样才能摆脱那个“0”?当然,我希望目录中的外观连贯,如下所示:
我该如何实现这一点?我想要一个尽可能独立于我所在的文档类别的解决方案,但万一我需要它,我会说在“书籍”或“八度”中。
非常感谢!
一个可行的例子可能是这样的,但实际上它是不是工作时,它做了我所描述的错误的事情!我会需要一些输出像我发布的图像一样的代码!
\documentclass[11pt,twoside]{book}
\usepackage[a5paper,inner=14mm,outer=20mm,top=20mm,bottom=25mm]{geometry}
\begin{document}
\tableofcontents
\setcounter{chapter}{-1}
\renewcommand{\chaptername}{Introduction}
\chapter{A wonderful journey}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua...
\renewcommand{\chaptername}{Chapter}
\chapter{Let's go}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua...
\chapter{Keep going}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua...
\end{document}
答案1
如果您想要使用“Introduzione”而不是“Capitolo 0”并且还想要一个附加标题,那么使用标准类,book
您可以重新定义\@chapapp
为“Introduzione”并且\thechapter
在前面有一个空字符串\chapter
,例如:
\documentclass{book}
\usepackage[italian]{babel}% or english instead of italian for an English example
\usepackage{mwe}
\begin{document}
\chapter*{Prefazione}% or Preface instead of Prefazione for an English example
\addcontentsline{toc}{chapter}{Prefazione}% add ToC entry (see comment above to switch to English)
\lipsum
\tableofcontents
\setcounter{chapter}{-1}% the introduction will be chapter 0
\renewcommand*{\thechapter}{}% Get rid of the page number
\makeatletter
\renewcommand*{\@chapapp}{Introduzione}% replace "Chapter" (or "Appendix") by "Introdutione" (use "Introduction" instead of "Introduzione" for an English example)
\makeatother
\chapter{Un viaggio nella matematica}% or "A Trip to Math" in English
\lipsum
\renewcommand*{\thechapter}{\arabic{chapter}}% bring back the chapter numbers
\makeatletter\renewcommand*{\@chapapp}{\chaptername}\makeatother% and the chapter name
\blinddocument
\end{document}
对于标题来说这就足够了:
但不适用于目录:
因此您需要一个额外的包来更改 ToC 条目。
使用 KOMA-Script 类,您不仅可以重新配置 ToC 条目,还可以定义仅用于介绍的新章节命令:
\documentclass[chapterprefix]{scrbook}
\usepackage[italian]{babel}% or \usepackage[english]{babel} for English
\usepackage{mwe}
\DeclareNewSectionCommand[%
style=chapter,% use chapter heading style for the new command
level=0,% same level as chapter (could also use \chapternumdepth)
pagestyle=plain,% use page style plain for the starting page like \chapter does
% following options are only needed, if you are using scrbook before 3.24.2626
% With KOMA-Script 3.24.2626 or newer you should remove the following 5 lines.
beforeskip=\dimexpr\csname scr@chapter@beforeskip\endcsname,%
innerskip=\dimexpr\csname scr@chapter@innerskip\endcsname,%
afterskip=\dimexpr\csname scr@chapter@afterskip\endcsname,%
prefixfont=\usekomafont{chapterprefix},%
font=\usekomafont{chapter},%
% following options are from tocbasic but with prefix `toc`:
tocstyle=chapter,% use chapter entry style for the ToC entry
tocindent=0pt,% do not indent the ToC entry
tocnumwidth=8em,% enough for "Introduzione" or "Introduction"
tocpagenumberbox=\underlinepagenumberbox% use a special kind of page number (see below)
]{introduction}
\RedeclareSectionCommand[%
tocnumwidth=8em,% enough for "Capitolo" or "Chapter" + Number
tocentrynumberformat=\chapapp\enskip,% add "Chapter" before the number of the ToC entry
tocpagenumberbox=\underlinepagenumberbox
]{chapter}
\RedeclareSectionCommand[tocindent=0pt]{section}% don't indent section entries to the ToC
\RedeclareSectionCommand[tocindent=2.3em]{subsection}% not used in this example
\setcounter{tocdepth}{\sectiontocdepth}% show only chapter and section in ToC (like the image in the question)
\makeatletter
% The following command is used to print the page numbers of chapter
% and introduction entries to the ToC. It does not only format the
% page number but additionally add a rule below the entry.
\newcommand*{\underlinepagenumberbox}[1]{%
\makebox[\@pnumwidth][r]{#1}% page number as usual
\nobreak
\makebox[0pt][r]{%
\raisebox{-\dp\strutbox}[0pt][2\dp\strutbox]{\rule{\columnwidth}{.5pt}}}% rule
}
\makeatother
\setkomafont{chapterprefix}{\Large\mdseries}% make the prefix line of the headings less strong
\renewcommand*{\theintroduction}{Introduzione}% text instead of number (use "Introduction" for an English example)
\begin{document}
\addchap{Prefazione}% use "Preface" for an English example
\lipsum
\tableofcontents
\introduction{Un viaggio nella matematica}% or \introduction{Trip to Math} for an English example
\lipsum
\blinddocument
\end{document}
这将产生一个目录:
以及介绍:
与你在问题中展示的图像非常相似。对于所有命令,如\DeclareNewSectionCommand
或\RedeclareSectionCommand
见英文版 KOMA-Script 手册或者德语 KOMA-Script 手册。注意,一些选项(所有带有前缀的)都继承自包的toc
TOC 样式。KOMA-Script 手册有一章关于。tocline
tocbasic
tocbasic
下面是另一个使用其他 KOMA-Script 命令执行几乎相同操作但不需要新章节命令的示例:
\documentclass[chapterprefix]{scrbook}
\usepackage[english]{babel}
\usepackage{mwe}
\makeatletter
% scrbook internally does not use \@chapapp directly but \chapapp
% So we can redefine it to change the result depending on whether counter
% chapter is 0 or -1 or (else) > 0:
\renewcommand*{\chapapp}{%
\ifcase -\value{chapter}\relax
\introductionname
\or
\prefacename
\else
\@chapapp
\fi
}
% But \thechapter should output nothing, if counter chapter is <= 0
\renewcommand*{\thechapter}{%
\ifnum \value{chapter}>\z@\arabic{chapter}\else\fi
}
% We do want to have \chapapp also before the number in the ToC entry.
% So we add it, if the first argument (this is the number argument) of
% \addchaptertocentry is not empty. If it is empty, we do not need to change
% anything:
\let\orig@addchaptertocentry\addchaptertocentry% Todo: better use letltxmacro
\renewcommand*{\addchaptertocentry}[2]{%
\IfArgIsEmpty{#1}{\orig@addchaptertocentry{#1}{#2}}{%
\orig@addchaptertocentry{\chapapp\nobreakspace#1}{#2}%
}%
}
\makeatother
\newcommand*{\introductionname}{Introduction}% The new name for introduction
\RedeclareSectionCommand[%
tocnumwidth=8em,% enough for "Chapter" + Number or "Introduction" or "Preface"
tocpagenumberbox=\underlinepagenumberbox
]{chapter}
\RedeclareSectionCommand[tocindent=0pt]{section}% don't indent section entries to the ToC
\RedeclareSectionCommand[tocindent=2.3em]{subsection}% not used in this example
\setcounter{tocdepth}{\sectiontocdepth}% show only chapter and section in ToC (like the image in the question)
\makeatletter
% The following command is used to print the page numbers of chapter
% and introduction entries to the ToC. It does not only format the
% page number but additionally add a rule below the entry.
\newcommand*{\underlinepagenumberbox}[1]{%
\makebox[\@pnumwidth][r]{#1}% page number as usual
\nobreak
\makebox[0pt][r]{%
\raisebox{-\dp\strutbox}[0pt][2\dp\strutbox]{\rule{\columnwidth}{.5pt}}}% rule
}
\makeatother
\setkomafont{chapterprefix}{\Large\mdseries}% make the prefix line of the headings less strong
\begin{document}
\setcounter{chapter}{-2}% We start with a preface
\chapter{About how to do it a bit more complicate}
\lipsum
\tableofcontents
\chapter{Trip to math}
\lipsum
\blinddocument
\end{document}
其结果为以下序言、目录、介绍和第一章页面:
对于最后一个例子,即使 KOMA-Script 3.22 就足够了。