仅针对 \section 标题更改 headsep

仅针对 \section 标题更改 headsep

问题

我想增加以节\小节或段落标题开头的页面上的标题。

我根据自己的意愿重新定义了章节间距设置(before 和 afterskip),文本看起来很棒。如果标题位于页面顶部,beforeskip 似乎不会影响标题行的间距。以下是示例图片:

在此处输入图片描述

问题

有没有办法重新定义以某种部分标题开头的页面的 headsep,或者是否可以在 \sections 的设置中以某种方式定义它?我正在使用 koma-script-report-class:

这是完整代码:

代码

\documentclass[11pt,twoside,english,openright, bibliography=totoc]  {scrreprt}
\usepackage{helvet}
\renewcommand{\familydefault}{\sfdefault}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage[a4paper]{geometry}
\geometry{verbose,tmargin=2.5cm,bmargin=2.5cm,lmargin=2.75cm,rmargin=2.5cm,headheight=18pt,headsep=8pt,footskip=26pt}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\setlength{\parskip}{\smallskipamount}
\setlength{\parindent}{0pt}
\usepackage{verbatim}
\usepackage{setspace}
\usepackage[authoryear]{natbib}
\onehalfspacing

\makeatletter
\usepackage{lscape} 
\usepackage[automark, headsepline, footsepline, plainfootsepline]{scrlayer-scrpage}
\pagestyle{scrheadings}
\clearscrheadfoot
\ohead{\headmark}
\ifoot[Test]{Test}
\cfoot[]{}
\ofoot[\pagemark]{\pagemark}
\ihead[]{}
\chead[]{}
\automark[chapter]{chapter} 
\usepackage{pdfpages}
\RedeclareSectionCommand[beforeskip=12pt,afterskip=12pt]{chapter}
\setkomafont{chapter}{\sffamily\LARGE}
\RedeclareSectionCommand[beforeskip=12pt,afterskip=10pt]{section}
\RedeclareSectionCommand[beforeskip=12pt,afterskip=8pt]{subsection}
\RedeclareSectionCommand[beforeskip=-12pt,afterskip=8pt]{paragraph}
\setkomafont{paragraph}{\sffamily\normalsize}
\usepackage {blindtext} 

\setkeys{Gin}{width=\textwidth} 
\raggedbottom
\usepackage[hyphens]{url}
\usepackage[colorlinks=true, urlcolor=blue, linkcolor=black,  citecolor=black]{hyperref} 
\makeatother
\usepackage{babel}
\begin{document}

\renewcommand{\thepage}{\roman{page}}
\chapter{Introduction}
\setcounter{page}{1}
\renewcommand{\thepage}{\arabic{page}}
\section{This is a Section}
\blindtext
\blindtext
\blindtext
\blindtext
\subsection{This is a Sub-section}
\blindtext
\end{document}

答案1

请注意,这种情况是不常见的。最好不要使用这么小的吸头。

但如果你真的想这样做,你可以使用

\usepackage{xpatch}
\xpretocmd\sectionlinesformat{\vspace*{0pt}}{}{\PatchFailed}

如果章节标题(章节、小节等)位于新页面的顶部,则还会插入 beforeskip。

在此处输入图片描述

补充说明:

请勿\parskip手动设置。请改用 KOMA-Script 选项parskip=half-

替换\clearscrheadfoot\clearpairofpagestyles。两个命令\cfoot[]{}都不需要。如果等的可选参数和强制参数\ifoot相等,则可以使用带星号的版本。

要重新开始页码编排,请使用\pagenumbering并在此命令前插入\cleardoublepage\cleardoubleoddpage以确保它在右侧页面上执行。

代码:

\documentclass[11pt,twoside,english,openright, bibliography=totoc,
  parskip=half-
]{scrreprt}

\usepackage{helvet}
\renewcommand{\familydefault}{\sfdefault}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage[a4paper]{geometry}
\geometry{verbose,margin=2.5cm,lmargin=2.75cm,headheight=18pt,headsep=8pt,footskip=26pt}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\usepackage{verbatim}
\usepackage{setspace}
\usepackage[authoryear]{natbib}
\onehalfspacing

\makeatletter
\usepackage{lscape} 
\usepackage[automark, headsepline, footsepline, plainfootsepline]{scrlayer-scrpage}
\pagestyle{scrheadings}
\automark[chapter]{chapter} 
\clearpairofpagestyles
\ohead{\headmark}
\ifoot*{Test}
\ofoot*{\pagemark}

\usepackage{pdfpages}
\RedeclareSectionCommand[beforeskip=12pt,afterskip=12pt]{chapter}
\setkomafont{chapter}{\sffamily\LARGE}
\RedeclareSectionCommand[beforeskip=-12pt,afterskip=10pt]{section}
\RedeclareSectionCommands[beforeskip=-12pt,afterskip=8pt]{subsection,subsubsection,paragraph}
\setkomafont{paragraph}{\sffamily\normalsize}

\usepackage{xpatch}
\xpretocmd\sectionlinesformat{\vspace*{0pt}}{}{\PatchFailed}

\usepackage{blindtext}% only for dummy text
\setkeys{Gin}{width=\textwidth}% default width for \includegraphics
\raggedbottom
\usepackage{babel}
\usepackage[hyphens]{url}
\usepackage[colorlinks=true, urlcolor=blue, linkcolor=black,citecolor=black]{hyperref} 

\begin{document}

\pagenumbering{roman}
\chapter{Introduction}
\Blindtext
\cleardoubleoddpage
\pagenumbering{arabic}
\chapter{A Chapter}
\section{This is a Section}
\blindtext
\blindtext
\blindtext
\blindtext
\section{A Second Section}
\subsection{This is a Sub-section}
\blindtext
\section{A Second Section}
\subsection{This is a Sub-section}
\Blindtext
\end{document}

如果你想在新页面上使用比正常情况下更小的节标题前跳过beforeskip,你可以使用类似

\usepackage{xpatch}
\makeatletter
\xpatchcmd\sectionlinesformat
  {\@hangfrom{\hskip #2#3}{#4}}
  {\parbox[b]{\textwidth}{\vspace*{7pt}\raggedsection\@hangfrom{\hskip #2#3}{#4}}}
  {}{\PatchFailed}
\makeatother

但随后您必须减少beforeskip相同的长度。本例中beforeskip为 12pt-7pt=5pt。

\RedeclareSectionCommand[beforeskip=-5pt,afterskip=10pt]{section}
\RedeclareSectionCommands[beforeskip=-5pt,afterskip=8pt]{subsection,subsubsection,paragraph}

在此处输入图片描述

代码:

\documentclass[11pt,twoside,english,openright, bibliography=totoc,
  parskip=half-
]{scrreprt}

\usepackage{helvet}
\renewcommand{\familydefault}{\sfdefault}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage[a4paper]{geometry}
\geometry{verbose,margin=2.5cm,lmargin=2.75cm,headheight=18pt,headsep=8pt,footskip=26pt}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\usepackage{verbatim}
\usepackage{setspace}
\usepackage[authoryear]{natbib}
\onehalfspacing

\makeatletter
\usepackage{lscape} 
\usepackage[automark, headsepline, footsepline, plainfootsepline]{scrlayer-scrpage}
\pagestyle{scrheadings}
\automark[chapter]{chapter} 
\clearpairofpagestyles
\ohead{\headmark}
\ifoot*{Test}
\ofoot*{\pagemark}

\usepackage{pdfpages}

\RedeclareSectionCommand[beforeskip=12pt,afterskip=12pt]{chapter}
\setkomafont{chapter}{\sffamily\LARGE}
\RedeclareSectionCommand[beforeskip=-5pt,afterskip=10pt]{section}
\RedeclareSectionCommands[beforeskip=-5pt,afterskip=8pt]{subsection,subsubsection,paragraph}
\setkomafont{paragraph}{\sffamily\normalsize}

\usepackage{xpatch}
\makeatletter
\xpatchcmd\sectionlinesformat
  {\@hangfrom{\hskip #2#3}{#4}}
  {\parbox[b]{\textwidth}{\vspace*{7pt}\raggedsection\@hangfrom{\hskip #2#3}{#4}}}
  {}{\PatchFailed}
\makeatother

\usepackage{blindtext}% only for dummy text
\setkeys{Gin}{width=\textwidth}% default width for \includegraphics
\raggedbottom
\usepackage{babel}
\usepackage[hyphens]{url}
\usepackage[colorlinks=true, urlcolor=blue, linkcolor=black,citecolor=black]{hyperref} 

\begin{document}

\pagenumbering{roman}
\chapter{Introduction}
\Blindtext
\cleardoubleoddpage
\pagenumbering{arabic}
\chapter{A Chapter}
\section{This is a Section}
\blindtext
\blindtext
\blindtext
\blindtext
\section{A Second Section}
\subsection{This is a Sub-section}
\blindtext
\section{A Second Section}
\subsection{This is a Sub-section}
\Blindtext
\end{document}

相关内容