有没有办法使章节和节的缩进使两者的标题以相同的宽度开始?例如:Einleitung 的 E 和 Zielstellung 的 Z 直接对齐。
我正在使用这个 KOMA 级:
\documentclass[12pt, numbers=noenddot,parskip,headings=small,headsepline,listof=nochaptergap, listof=totoc,index=totoc]{scrreprt}
\usepackage[a4paper, includehead, left=3.5cm, right=1.7cm, top=2.5cm, bottom=2.0cm]{geometry}
\RedeclareSectionCommand[
beforeskip=-1sp,
afterskip=.25\baselineskip]{chapter}
\RedeclareSectionCommand[
beforeskip=-\baselineskip,
afterskip=.5\baselineskip]{section}
\RedeclareSectionCommand[
beforeskip=-.75\baselineskip,
afterskip=.5\baselineskip]{subsection}
\RedeclareSectionCommand[
beforeskip=-.5\baselineskip,
afterskip=.25\baselineskip]{subsubsection}
\RedeclareSectionCommand[
beforeskip=.5\baselineskip,
afterskip=-1em]{paragraph}
\RedeclareSectionCommand[
beforeskip=-.5\baselineskip,
afterskip=-1em]{subparagraph}
\begin{document}
\chapter{Einleitung}
\section{Zielstellung}
\end{document}
答案1
您可以将数字放在宽度相同的框中。请注意,您不能在此处使用em
或ex
,因为这将取决于标题的字体大小,因此只有当所有节级的字体大小相同时,数字才会相同,例如,
\newcommand*{\chapterformat}{%
\IfChapterUsePrefixLine{\chapapp\nobreakspace\thechapter\autodot}{%
\makebox[40pt][l]{\thechapter\autodot\hfil}%
}%
}
\newcommand*{\sectionformat}{\makebox[40pt][l]{\thesection\autodot\hfil}}
这可以扩展到所有级别,但在这种情况下 40pt 是不够的:
\renewcommand*{\chapterformat}{%
\IfUsePrefixLine{\chapapp\nobreakspace\thechapter\autodot}{%
\makebox[80pt][l]{\thechapter\autodot\hfil}%
}%
}
\renewcommand*{\sectionformat}{\makebox[80pt][l]{\thesection\autodot\hfil}}
\renewcommand*{\subsectionformat}{\makebox[80pt][l]{\thesubsection\autodot\hfil}}
\renewcommand*{\subsubsectionformat}{\makebox[80pt][l]{\thesubsubsection\autodot\hfil}}
\renewcommand*{\paragraphformat}{\makebox[80pt][l]{\theparagraph\autodot\hfil}}
\renewcommand*{\subparagraphformat}{\makebox[80pt][l]{\thesubparagraph\autodot\hfil}}
但是如果(且仅当)您希望从章节到小段的所有级别都使用相同的缩进量,您也可以重新定义\chapterlinesformat
,\sectionlinesformat
和\sectioncatchphraseformat
:
\documentclass[12pt, numbers=noenddot,parskip,headings=small,headsepline,listof=nochaptergap, listof=totoc,index=totoc]{scrreprt}
\usepackage[a4paper, includehead, left=3.5cm, right=1.7cm, top=2.5cm, bottom=2.0cm]{geometry}
\RedeclareSectionCommand[
beforeskip=-1sp,
afterskip=.25\baselineskip]{chapter}
\RedeclareSectionCommand[
beforeskip=-\baselineskip,
afterskip=.5\baselineskip]{section}
\RedeclareSectionCommand[
beforeskip=-.75\baselineskip,
afterskip=.5\baselineskip]{subsection}
\RedeclareSectionCommand[
beforeskip=-.5\baselineskip,
afterskip=.25\baselineskip]{subsubsection}
\RedeclareSectionCommand[
beforeskip=.5\baselineskip,
afterskip=-1em]{paragraph}
\RedeclareSectionCommand[
beforeskip=-.5\baselineskip,
afterskip=-1em]{subparagraph}
\newlength{\allsectionnumberwidth}
\setlength{\allsectionnumberwidth}{80pt}
\makeatletter
\renewcommand{\chapterlinesformat}[3]{%
\IfArgIsEmpty{#2}{#3}{%
\@hangfrom{\makebox[\allsectionnumberwidth][l]{#2}}{#3}%
}%
}
\renewcommand{\sectionlinesformat}[4]{%
\IfArgIsEmpty{#3}{\@hangfrom{\hskip #2}{#4}}{%
\@hangfrom{\makebox[\allsectionnumberwidth][l]{\hskip #2#3}}{#4}%
}%
}
\renewcommand{\sectioncatchphraseformat}[4]{%
\IfArgIsEmpty{#3}{\hskip #2#3#4}{%
\makebox[\allsectionnumberwidth][l]{\hskip #2#3}#4%
}%
}
\makeatother
\setcounter{secnumdepth}{\subparagraphnumdepth}% To show it for all levels
\begin{document}
\chapter{Chapter Heading}
\section{Section Heading}
\subsection{Subsection Heading}
\subsubsection{Subsubsection Heading}
\paragraph{Paragraph Heading}
\subparagraph{Subparagraph Heading}
\end{document}
您甚至可以自动检测所需的数字宽度:
\documentclass[12pt, numbers=noenddot,parskip,headings=small,headsepline,listof=nochaptergap, listof=totoc,index=totoc]{scrreprt}
\usepackage[a4paper, includehead, left=3.5cm, right=1.7cm, top=2.5cm, bottom=2.0cm]{geometry}
\RedeclareSectionCommand[
beforeskip=-1sp,
afterskip=.25\baselineskip]{chapter}
\RedeclareSectionCommand[
beforeskip=-\baselineskip,
afterskip=.5\baselineskip]{section}
\RedeclareSectionCommand[
beforeskip=-.75\baselineskip,
afterskip=.5\baselineskip]{subsection}
\RedeclareSectionCommand[
beforeskip=-.5\baselineskip,
afterskip=.25\baselineskip]{subsubsection}
\RedeclareSectionCommand[
beforeskip=.5\baselineskip,
afterskip=-1em]{paragraph}
\RedeclareSectionCommand[
beforeskip=-.5\baselineskip,
afterskip=-1em]{subparagraph}
\newlength{\allsectionnumberwidth}
\setlength{\allsectionnumberwidth}{40pt}% use at least 40pt
\newlength{\maxallsectionnumberwidth}
\setlength{\maxallsectionnumberwidth}{\allsectionnumberwidth}
\makeatletter
\renewcommand{\chapterlinesformat}[3]{%
\IfArgIsEmpty{#2}{#3}{%
\updateallsectionnumberwidth{#2}%
\@hangfrom{\makebox[\allsectionnumberwidth][l]{#2}}{#3}%
}%
}
\renewcommand{\sectionlinesformat}[4]{%
\IfArgIsEmpty{#3}{\@hangfrom{\hskip #2}{#4}}{%
\updateallsectionnumberwidth{\hskip #2#3}%
\@hangfrom{\makebox[\allsectionnumberwidth][l]{\hskip #2#3}}{#4}%
}%
}
\renewcommand{\sectioncatchphraseformat}[4]{%
\IfArgIsEmpty{#3}{\hskip #2#3#4}{%
\updateallsectionnumberwidth{\hskip #2#3}%
\makebox[\allsectionnumberwidth][l]{\hskip #2#3}#4%
}%
}
\newcommand*{\updateallsectionnumberwidth}[1]{%
\begingroup
\settowidth{\@tempdima}{#1}%
\ifdim\@tempdima>\maxallsectionnumberwidth
\global\maxallsectionnumberwidth\@tempdima
\fi
\endgroup
}
\BeforeClosingMainAux{%
\if@filesw
\ifdim\maxallsectionnumberwidth>\allsectionnumberwidth
\typeout{Rerun to get section number width right!}%
\immediate\write\@auxout{\unexpanded{%
\providecommand*\setallsectionnumberwidth[1]{}^^J%
}%
\string\setallsectionnumberwidth{\the\maxallsectionnumberwidth}%
}%
\fi
\fi
}
\newcommand*{\setallsectionnumberwidth}[1]{%
\setlength{\allsectionnumberwidth}{#1}%
\global\allsectionnumberwidth\allsectionnumberwidth
}
\makeatother
\setcounter{secnumdepth}{\subparagraphnumdepth}% To show it for all levels
\begin{document}
\chapter{Chapter Heading}
\section{Section Heading}
\subsection{Subsection Heading}
\subsubsection{Subsubsection Heading}
\paragraph{Paragraph Heading}
\subparagraph{Subparagraph Heading}
% Compare after adding
%\setcounter{section}{99}\setcounter{subparagraph}{999}\subparagraph{More}
\end{document}
注意:您至少需要运行两次 LaTeX 才能获得正确的数字宽度,例如,在激活 之前的注释行之后\end{document}
。
看https://tex.stackexchange.com/a/357254/9057如果您希望按页面而不是按文档执行此类操作。
答案2
你可以使用类似
\newdimen\sectionnumberwdmax
\setlength\sectionnumberwdmax{1.25cm}% <- space needed for the section numbers
\renewcommand*{\chapterformat}{%
\mbox{\chapappifchapterprefix{\nobreakspace}%
\IfUsePrefixLine
{\thechapter\autodot}
{\makebox[\sectionnumberwdmax][l]{\thechapter\autodot\hfil}}%
}%
}
\renewcommand*\sectionformat{\makebox[\sectionnumberwdmax][l]{\thesection\autodot\hfil}}
例子:
代码:
\documentclass[12pt, numbers=noenddot,parskip,headings=small,headsepline,listof=nochaptergap, listof=totoc,index=totoc]{scrreprt}
\usepackage[a4paper, includehead, left=3.5cm, right=1.7cm, top=2.5cm, bottom=2.0cm]{geometry}
\RedeclareSectionCommand[
beforeskip=-1sp,
afterskip=.25\baselineskip
]{chapter}
\RedeclareSectionCommand[
beforeskip=-\baselineskip,
afterskip=.5\baselineskip
]{section}
\RedeclareSectionCommand[
beforeskip=-.75\baselineskip,
afterskip=.5\baselineskip
]{subsection}
\RedeclareSectionCommand[
beforeskip=-.5\baselineskip,
afterskip=.25\baselineskip
]{subsubsection}
\RedeclareSectionCommands[
beforeskip=.5\baselineskip,
afterskip=-1em
]{paragraph,subparagraph}
\newdimen\sectionnumberwdmax
\setlength\sectionnumberwdmax{1.25cm}% <- space needed for the section numbers
\renewcommand*{\chapterformat}{%
\mbox{\chapappifchapterprefix{\nobreakspace}%
\IfUsePrefixLine
{\thechapter\autodot}
{\makebox[\sectionnumberwdmax][l]{\thechapter\autodot\hfil}}%
}%
}
\renewcommand*\sectionformat{\makebox[\sectionnumberwdmax][l]{\thesection\autodot\hfil}}
\begin{document}
\chapter{Einleitung}
\section{Zielstellung}
\setcounter{section}{9}
\section{Abschnitt mit zweistelliger Nummer}
\end{document}