附录 A 后面的点与章节标题“数据源”之间的水平距离与目录中 1 后面的点与章节标题“数据源”之间的水平距离不同。有没有办法只针对附录 A 调整此距离,以使两个距离相等?
\documentclass[12pt,a4paper,DIV=12,BCOR=0mm,numbers=endperiod]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage[onehalfspacing]{setspace}
%appendix
\usepackage[title,titletoc]{appendix}
\usepackage{etoolbox}
\patchcmd{\appendices}{\quad}{. }{}{}
\begin{document}
\tableofcontents
\section{Data Sources}
\begin{appendices}
\section{Data Sources}
\end{appendices}
\end{document}
答案1
通常情况下,目录中章节条目的编号会打印在宽度为 1.5em 的框中。因此,您可以使用相同宽度的框来显示目录中的附录编号:
\documentclass[12pt,a4paper,DIV=12,BCOR=0mm,numbers=endperiod]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[onehalfspacing]{setspace}
\usepackage[english]{babel}% <- added
\usepackage{xpatch}
\xapptocmd\appendix
{%
\xpretocmd\sectionformat{\appendixname\enskip}{}{\PatchFailed}%
\xpatchcmd{\addsectiontocentry}
{\addtocentrydefault{section}{#1}{#2}}
{%
\ifstr{#1}{}
{\addtocentrydefault{section}{}{#2}}
{\addtocentrydefault{section}{}{\appendixname\ \makebox[1.5em][l]{#1\autodot}#2}}%
}{}{\PatchFailed}%
}{}{\PatchFailed}
\begin{document}
\tableofcontents
\section{Data Sources}
%\setcounter{section}{9}
%\section{Other section}
\appendix
\section{Data Sources}
\end{document}
但请注意,如果目录中有两位数的部分,则数字和文本之间的分隔符也会较小。如果也应该有相同的分隔符,您可以使用:
\documentclass[12pt,a4paper,DIV=12,BCOR=0mm,numbers=endperiod]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[onehalfspacing]{setspace}
\usepackage[english]{babel}% <- added
\renewcommand*\addsectiontocentry[2]{%
\ifstr{#1}{}
{\addtocentrydefault{section}{}{#2}}
{\addtocentrydefault{section}{}{#1\autodot\enskip#2}}%
}
\usepackage{xpatch}
\xapptocmd\appendix
{%
\xpretocmd\sectionformat{\appendixname\enskip}{}{\PatchFailed}%
\xpatchcmd{\addsectiontocentry}{#1\autodot}{\appendixname~#1\autodot}{}{\PatchFailed}%
}{}{\PatchFailed}
\begin{document}
\tableofcontents
\section{Data Sources}
\setcounter{section}{9}
\section{Other section}
\appendix
\section{Data Sources}
\end{document}