使用 KOMA 脚本类,我想要自定义目录中页码的显示。
我的页码每节都会重置一次,表示为 ,2-3
表示3
节的页码2
。这不是通过更改\thepage
命令来实现的,而是简单地在页脚中写入即可{\thesection-\thepage}
。
创建目录时,显然只\thepage
显示 -number。我想要实现的是这样的数值格式:
1 Sectiontitle
1.1 Subsectiontitle .............. 1-1
1.2 Other title .................. 1-2
2 Next Section
2.1 This Section ................. 2-1
我想保留其\thepage
默认定义,因为我可能需要该号码用于其他应用程序。
我已经找到了各种帖子(这里或者这里或者这里) 关于目录的格式,但我没有找到任何关于页码格式的信息。
编辑1:
我相信,使用-packagepagenumberbox
中的命令tocstyle
应该可以在页码前面添加一些内容。但是,我仍然不知道如何获得要放入的正确章节编号pagenumberbox
编辑2:
梅威瑟:
\documentclass[english,footsepline,listof=totoc]{scrartcl}
\usepackage{helvet}
\renewcommand{\familydefault}{\sfdefault}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{float}
\makeatletter
\usepackage{geometry}
\geometry{a4paper,verbose=true,nomarginpar,tmargin=4cm,bmargin=2.2cm,footskip=1.1cm,lmargin=3cm,rmargin=2.5cm,headheight=3cm}
\setlength{\footheight}{1cm}
%% Begin of way to indent all body but no headings
\newcommand\LeftMargin{.5cm}
\renewcommand*\sectionlinesformat[4]{ \ifstr{#3}{}{}{\hspace*{-\LeftMargin}}#3#4}
\usepackage[ headwidth=\the\textwidth+\LeftMargin:-\LeftMargin:\LeftMargin,footwidth=\the\textwidth+\LeftMargin:-\LeftMargin:\LeftMargin]{scrlayer-scrpage}
%% Define how deep the numeration in the document should be.
\setcounter{secnumdepth}{5}
%% Define how deep the numeration in the table of contents should be.
\setcounter{tocdepth}{3}
\pagestyle{scrheadings} %same as above
%% Define customized pagenumbering
\let\stdsection\section
\renewcommand\section{%
\clearpage%
\setcounter{page}{1}%
\stdsection%
}
\clearscrheadfoot
\ofoot{\raisebox{-2mm}{\thesection-\thepage}}
\cfoot{\raisebox{-2mm}{Footer}}
\setkomafont{pageheadfoot}{\normalfont}
\usepackage[nohyperlinks]{acronym}
\begin{document}
\tableofcontents{}
\section{First}
\newpage
\section{Second}
Content
\end{document}
编辑3:
根据以下回答,我能够实现我想要的页码。唯一的问题是目录中的页码似乎以某种方式对齐(见下图)。
这看起来显然很奇怪,有没有办法将页码右对齐而不是左对齐?
答案1
免责声明:我不推荐这种奇怪的页码编号,当然不改变的话也不行\thepage
。
但可以使用KOMA-Script 3.20 的当前预发布版本。
\documentclass[english,footsepline,plainfootsepline,listof=totoc,
footheight=1cm,% <- added
oneside,% <- added
headings=small% <- added
]{scrbook}[2016/04/01]% <- changed
\usepackage{helvet}
\renewcommand{\familydefault}{\sfdefault}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{float}
\usepackage{geometry}
\geometry{
a4paper,verbose=true,nomarginpar,
tmargin=4cm,bmargin=2.2cm,
footskip=1.3cm,% <- changed
lmargin=3cm,rmargin=2.5cm,
headheight=3cm}
%% Define how deep the numeration in the document should be.
\setcounter{secnumdepth}{5}
%% Define how deep the numeration in the table of contents should be.
\setcounter{tocdepth}{3}
%% Begin of way to indent all body but no headings
\newcommand\LeftMargin{.5cm}
\renewcommand*\chapterlinesformat[3]{% <- added
\ifstr{#2}{}{}{\hspace*{-\LeftMargin}}#2#3%
}
\renewcommand*\sectionlinesformat[4]{%
\ifstr{#3}{}{}{\hspace*{-\LeftMargin}}#3#4%
}
\usepackage[
headwidth=\the\textwidth+\LeftMargin:-\LeftMargin:\LeftMargin,
footwidth=\the\textwidth+\LeftMargin:-\LeftMargin:\LeftMargin
]{scrlayer-scrpage}
\clearpairofpagestyles
\ModifyLayer[addvoffset=-2mm]{scrheadings.foot.above.line}% <- added
\ModifyLayer[addvoffset=-2mm]{plain.scrheadings.foot.above.line}% <- added
\ofoot*{\pagemark}% <- changed
\cfoot*{Footer}% <- changed
\setkomafont{pageheadfoot}{\normalfont}
%% strange page numbering (added)
\usepackage{xpatch}
\makeatletter
\renewcommand\pagemark{\if@mainmatter\thechapter-\thepage\else\thepage\fi}
\xpretocmd{\chapterheadstartvskip}
{\if@mainmatter\setcounter{page}{1}\fi}{}{}
\renewcommand\addchaptertocentry[2]{%
\if@mainmatter
{\addtocontents{toc}{\protect\chapterinpagenumber{#1-}}}
\else
{\addtocontents{toc}{\protect\chapterinpagenumber{}}}
\fi%
\addtocentrydefault{chapter}{#1}{#2}%
}
\newcommand\@chapterinpagenumber{}
\newcommand\chapterinpagenumber[1]{%
\renewcommand\@chapterinpagenumber{#1}%
}
\newcommand\pagenumbertocformat[1]{\@chapterinpagenumber#1}
\makeatother
\RedeclareSectionCommands[
tocpagenumberformat=\pagenumbertocformat%
]{chapter,section,subsection,subsubsection,paragraph,subparagraph}
\RedeclareSectionCommand[
beforeskip=1sp
]{chapter}
\usepackage{blindtext}% dummy text
\begin{document}
\frontmatter
\tableofcontents
\listoffigures
\listoftables
\mainmatter
\blinddocument
\blinddocument
\end{document}
更新关于目录中页码的对齐
条目的页码打印在宽度为 的框中,右对齐
\@pnumwidth
。因此,您可能想\@pnumwidth
使用例如
\renewcommand\@pnumwidth{3em}
或者您可以使用\mbox
as tocpagenumberbox
。
\RedeclareSectionCommands[
tocpagenumberformat=\pagenumbertocformat,%
tocpagenumberbox=\mbox% <- added
]{chapter,section,subsection,subsubsection,paragraph,subparagraph}
代码:
\documentclass[english,footsepline,plainfootsepline,listof=totoc,
footheight=1cm,% <- added
oneside,% <- added
headings=small% <- added
]{scrbook}[2016/04/01]% <- changed
\usepackage{helvet}
\renewcommand{\familydefault}{\sfdefault}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{scrhack}
\usepackage{float}
\usepackage{geometry}
\geometry{
a4paper,verbose=true,nomarginpar,
tmargin=4cm,bmargin=2.2cm,
footskip=1.3cm,% <- changed
lmargin=3cm,rmargin=2.5cm,
headheight=3cm}
%% Define how deep the numeration in the document should be.
\setcounter{secnumdepth}{5}
%% Define how deep the numeration in the table of contents should be.
\setcounter{tocdepth}{3}
%% Begin of way to indent all body but no headings
\newcommand\LeftMargin{.5cm}
\renewcommand*\chapterlinesformat[3]{% <- added
\ifstr{#2}{}{}{\hspace*{-\LeftMargin}}#2#3%
}
\renewcommand*\sectionlinesformat[4]{%
\ifstr{#3}{}{}{\hspace*{-\LeftMargin}}#3#4%
}
\usepackage[
headwidth=\the\textwidth+\LeftMargin:-\LeftMargin:\LeftMargin,
footwidth=\the\textwidth+\LeftMargin:-\LeftMargin:\LeftMargin
]{scrlayer-scrpage}
\clearpairofpagestyles
\ModifyLayer[addvoffset=-2mm]{scrheadings.foot.above.line}% <- added
\ModifyLayer[addvoffset=-2mm]{plain.scrheadings.foot.above.line}% <- added
\ofoot*{\pagemark}% <- changed
\cfoot*{Footer}% <- changed
\setkomafont{pageheadfoot}{\normalfont}
%% strange page numbering (added)
\usepackage{xpatch}
\makeatletter
\renewcommand\pagemark{\if@mainmatter\thechapter-\thepage\else\thepage\fi}
\xpretocmd{\chapterheadstartvskip}
{\if@mainmatter\setcounter{page}{1}\fi}{}{}
\renewcommand\addchaptertocentry[2]{%
\if@mainmatter
{\addtocontents{toc}{\protect\chapterinpagenumber{#1-}}}
\else
{\addtocontents{toc}{\protect\chapterinpagenumber{}}}
\fi%
\addtocentrydefault{chapter}{#1}{#2}%
}
\newcommand\@chapterinpagenumber{}
\newcommand\chapterinpagenumber[1]{%
\renewcommand\@chapterinpagenumber{#1}%
}
\newcommand\pagenumbertocformat[1]{\@chapterinpagenumber#1}
\makeatother
\RedeclareSectionCommands[
tocpagenumberformat=\pagenumbertocformat,%
tocpagenumberbox=\mbox%
]{chapter,section,subsection,subsubsection,paragraph,subparagraph}
\RedeclareSectionCommand[
beforeskip=1sp
]{chapter}
\usepackage{blindtext}% dummy text
\begin{document}
\frontmatter
\tableofcontents
\listoffigures
\listoftables
\mainmatter
\blinddocument
\setcounter{chapter}{9}% only for this example
\blinddocument
\clearpage
\setcounter{page}{100}% % only for this example
\section{Only for testing}
\end{document}