当页面包含 \section 时隐藏标题

当页面包含 \section 时隐藏标题

我使用{scrlayer-scrpage}标题和脚注包,并希望在我的页面包含时隐藏标题和脚注\section

我在这里发现了类似的问题:当页面包含章节标题时使用 titlesec 隐藏标题但我遇到的问题是之后无法激活标题。

这是一个简单的例子:

\documentclass[a4paper, twoside=false, DIV=12, BCOR=5mm, bibliography=totocnumbered, numbers=autoendperiod]{scrartcl}

% Set up headers and footers
\usepackage[automark, autooneside=false, headsepline, footsepline]{scrlayer-scrpage}
\usepackage{xpatch}
\headheight=1cm
\footheight=1cm
\clearpairofpagestyles
\ihead{\ifstr{\rightmark}{\leftmark}{}{\leftmark}}
\ohead{\ifstr{\rightmark}{\leftmark}{}{\rightmark}}
\ofoot{\pagemark} 

% Page Style for page which shall contain the page number only
\newpairofpagestyles{pagenumbersonly}{
    \KOMAoptions{headsepline=false}
    \ofoot{\pagemark}
}

% Fixing pagestyle for pages containing \section command
\xpretocmd{\section}{\thispagestyle{pagenumbersonly}\KOMAoptions{headsepline=true}}{}{}

我使用 来处理标题的内容\ihead{\ifstr{\rightmark}{\leftmark}{}{\leftmark}},这适用于所有样式。否则,标题会打印两次。但是,如何激活以下页面的标题行?我尝试\KOMAoptions{headsepline=true}在 中应用页面样式后添加xpretocmd,但标题行不会显示。

举个例子:

\section{sec}
\subsection{subsec}
\lipsum{}\lipsum{}

产生结果:

编辑:根据要求,完整示例:

%% Based on a TeXnicCenter-Template by Tino Weinkauf.

\documentclass[a4paper, twoside=false, DIV=12, BCOR=5mm, bibliography=totocnumbered, numbers=autoendperiod]{scrartcl}

% Options:
% Paper Size: a4paper / a5paper / b5paper / letterpaper / legalpaper / executivepaper
% Duplex: oneside / twoside
% Base Font Size: 10pt / 11pt / 12pt
% DIV 12 normed content- and margin size
% BCOR Bindekorrektur - 5mm more space on the left


\usepackage[ngerman]{babel}                             % German language support
\usepackage[utf8]{inputenc}                             % UTF-8 encoding
\usepackage[T1]{fontenc}                                    % Westeuropean encoding support
\usepackage{lmodern}                                            % Font-fix
\addtokomafont{disposition}{\rmfamily}      % Fix for chapter font
\usepackage{microtype}                                      % Better letters
\usepackage{graphicx}                                           % For loading graphic files
\usepackage{siunitx}                                            % For units

% Please note:
% Images can be included using \includegraphics{Dateiname}
% resp. using the dialog in the Insert menu.
% 
% The mode "LaTeX => PDF" allows the following formats:
%   .jpg  .png  .pdf  .mps
% 
% The modes "LaTeX => DVI", "LaTeX => PS" und "LaTeX => PS => PDF"
% allow the following formats:
%   .eps  .ps  .bmp  .pict  .pntg

\usepackage{listings, lstautogobble}            % For formatting Code, for formatting Indents
\usepackage{lscape}                                             % Single page landscape layout support
\usepackage{pdflscape}                                      % Single page landscape layout support for PDF files
\usepackage{pdfpages}                                           % Embedding PDF documents in the final document


% Set up headers and footers
\usepackage[automark, autooneside=false, headsepline, footsepline]{scrlayer-scrpage}
\usepackage{xpatch}
\headheight=1cm
\footheight=1cm
\clearpairofpagestyles
\ihead{\ifstr{\rightmark}{\leftmark}{}{\leftmark}}
\ohead{\ifstr{\rightmark}{\leftmark}{}{\rightmark}}
\ofoot{\pagemark} 

% Page Style for page which shall contain the page number only
\newpairofpagestyles{pagenumbersonly}{
    \KOMAoptions{headsepline=false}
    \ofoot{\pagemark}
}

% Fixing pagestyle for pages containing \section command
\xpretocmd{\section}{\thispagestyle{pagenumbersonly}\KOMAoptions{headsepline=true}}{}{}

% Automark fills the \leftmark and \rightmark placeholders with the section and subsection
% Autooneside is needed by automark
% Headsepline adds a line under the headline
% Footsepline adds a line over the footline
% Headheight defines an additional spacing over the headline

\usepackage{tikz-er2}                                           % TIKZ for figures
\usetikzlibrary{shadows, positioning}                           % TIKZ libraries

\usepackage{lipsum}                                             % For testing purposes. Remove if finished

% Math Packages
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{textcomp}

% Line Spacing
\usepackage{setspace}
%\singlespacing        %% 1-spacing (default)
%\onehalfspacing       %% 1,5-spacing
%\doublespacing        %% 2-spacing

% Other Packages

%\usepackage{soul}
%\usepackage[multiple]{footmisc}
\usepackage[colorlinks=false, pdfborder={0 0 0}]{hyperref}


% Babelbib for German citation style
\usepackage[fixlanguage]{babelbib}
\selectbiblanguage{ngerman}
\addto\captionsngerman{\renewcommand{\refname}{Literaturverzeichnis}}
\bibliographystyle{alphadin} % Using modified alphadin compiler


% Abb. instead of Abbildung as Caption
\addto\captionsngerman{\renewcommand{\figurename}{Abb.}}

% Bracket on the right

%\newenvironment{rcases}
%  {\left.\begin{aligned}}
%  {\end{aligned}\right\rbrace}


\usepackage{hyperref}
\hypersetup{
    pdftitle={hidden},
    pdfauthor={hidden},
    pdfkeywords={hiddén},
    bookmarksopen=true
}

\makeatletter 
\renewcommand\section{
    ~\vspace{1cm}
    \@startsection 
   {section}{1}{0mm}%         % name, ebene, einzug 
   {\baselineskip}%            % vor-abstand 
   {2\baselineskip}%            % nach-abstand 
   {\bfseries\sffamily\LARGE}%      % layout 
   } 
\makeatother 

\makeatletter 
\renewcommand\subsection{\@startsection 
   {subsection}{2}{0mm}%      % name, ebene, einzug 
   {2\baselineskip}%            % vor-abstand 
   {1.33\baselineskip}%            % nach-abstand 
   {\bfseries\sffamily\large}%           % layout 
   } 
\makeatother 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% DOCUMENT
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

    %% Title Page %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


    %% TOC %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    \pagestyle{pagenumbersonly}

    \tableofcontents
    \listoffigures
    \listoftables

    \newpage


    %% Main Content %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    \pagestyle{scrheadings} % Now display headings: headings / fancy / ...

    %Hauptinhalt

    \section{sec}
    \subsection{subsec}
    \lipsum{}\lipsum{}\lipsum{}\lipsum{}

    %\input{Content}
    %\newpage
    %\includepdf[scale=0.7, pagecommand=\thispagestyle{scrheadings}\section{Entity-Relationship Diagramm}]{resources/images/ER.pdf}

    \newpage

    %% Literature %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    \pagestyle{scrheadings}

    \interlinepenalty 10000             % Avoid a pagebreak in a source
    %\bibliography{literature}

    \newpage


    %% Disclaimer %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    %\appendix

\end{document}

包含 \section 的页面

包含 \section 的页面之后的页面

两个页面的 headercontent 都是正确的。但是,如何再次为以下页面(不包含\section)启用 headersepline?

编辑2:我发现当我删除这些行时,它就能完美地工作

\makeatletter 
\renewcommand\section{
    ~\vspace{1cm}
    \@startsection 
     {section}{1}{0mm}%         % name, ebene, einzug 
     {\baselineskip}%            % vor-abstand 
     {2\baselineskip}%            % nach-abstand 
     {\bfseries\sffamily\LARGE}%      % layout 
     } 
\makeatother 

\makeatletter 
\renewcommand\subsection{\@startsection 
     {subsection}{2}{0mm}%      % name, ebene, einzug 
     {2\baselineskip}%            % vor-abstand 
     {1.33\baselineskip}%            % nach-abstand 
     {\bfseries\sffamily\large}%           % layout 
     } 
\makeatother 

有人能向我解释为什么现在这样做有效吗以及我除了删除这些行之外还能做什么?

答案1

不要重新定义\section\subsection。您可以使用\RedeclareSectionCommand来更改beforeskipafterskip

\RedeclareSectionCommand[
  beforeskip=-1\baselineskip,
  afterskip=2\baselineskip,
  font=\sffamily\LARGE
]{section}

\RedeclareSectionCommand[
  beforeskip=-2\baselineskip,
  afterskip=1.33\baselineskip,
  font=\sffamily\large
]{subsection}

必须在将代码添加到之前插入此代码\section

要删除headsepline仅具有样式的页面,pagenumbersonly您可以使用

\newpairofpagestyles{pagenumbersonly}{\ofoot{\pagemark}}
\AddToLayerPageStyleOptions{pagenumbersonly}{oninit=\KOMAoptions{headsepline=false}}

梅威瑟:

\documentclass[DIV=12, BCOR=5mm, bibliography=totocnumbered,
headheight=1cm,
footheight=1cm
]{scrartcl}

\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
%\addtokomafont{disposition}{\rmfamily}% why??
\usepackage{microtype}

\RedeclareSectionCommand[
  beforeskip=-1\baselineskip,
  afterskip=2\baselineskip,
  font=\sffamily\LARGE
]{section}

\RedeclareSectionCommand[
  beforeskip=-2\baselineskip,
  afterskip=1.33\baselineskip,
  font=\sffamily\large
]{subsection}

% Set up headers and footers
\usepackage[automark, autooneside=false, headsepline, footsepline]{scrlayer-scrpage}
\usepackage{xpatch}
\clearpairofpagestyles
\ihead{\leftmark}
\ohead{\ifstr{\rightmark}{\leftmark}{}{\rightmark}}
\ofoot{\pagemark}

% Page Style for page which shall contain the page number only
\newpairofpagestyles{pagenumbersonly}{\ofoot{\pagemark}}
\AddToLayerPageStyleOptions{pagenumbersonly}{oninit=\KOMAoptions{headsepline=false}}

% Fixing pagestyle for pages containing \section command
\xpretocmd{\section}{\vspace*{1cm}\thispagestyle{pagenumbersonly}}{}{}

\usepackage{lipsum}                                             % For testing 

\renewcaptionname{ngerman}{\refname}{Literaturverzeichnis}
\renewcaptionname{ngerman}{\figurename}{Abb.}

\begin{document}

\pagestyle{pagenumbersonly}
\tableofcontents
\listoffigures
\listoftables

\clearpage
\pagestyle{scrheadings}
\section{sec}
\subsection{subsec}
\lipsum[1-6]
\lipsum[1-7]
%\lipsum[1-5]% uncomment to see the problem
\section{sec}
\subsection{subsec}
\lipsum[1-10]
\end{document}

我已经删除了问题中不需要的内容,并且我已经使用了

\ihead{\leftmark}
\ohead{\ifstr{\rightmark}{\leftmark}{}{\rightmark}}

确保仅当和相等时才\leftmark打印。\leftmark\rightmark


另一个建议是使用页面样式plain而不是定义新的样式。

\documentclass[DIV=12, BCOR=5mm, bibliography=totocnumbered,
headheight=1cm,
footheight=1cm
]{scrartcl}

\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
%\addtokomafont{disposition}{\rmfamily}% why??
\usepackage{microtype}

\RedeclareSectionCommand[
  beforeskip=-1\baselineskip,
  afterskip=2\baselineskip,
  font=\sffamily\LARGE
]{section}

\RedeclareSectionCommand[
  beforeskip=-2\baselineskip,
  afterskip=1.33\baselineskip,
  font=\sffamily\large
]{subsection}

% Set up headers and footers
\usepackage[automark, autooneside=false, headsepline, footsepline,
plainfootsepline
]{scrlayer-scrpage}
\usepackage{xpatch}
\clearpairofpagestyles
\ihead{\leftmark}
\ohead{\ifstr{\rightmark}{\leftmark}{}{\rightmark}}
\ofoot*{\pagemark}


% Fixing pagestyle for pages containing \section command
\xpretocmd{\section}{\vspace*{1cm}\thispagestyle{plain}}{}{}

\usepackage{lipsum} 

\renewcaptionname{ngerman}{\refname}{Literaturverzeichnis}
\renewcaptionname{ngerman}{\figurename}{Abb.}

\begin{document}

\pagestyle{plain}
\tableofcontents
\listoffigures
\listoftables

\clearpage
\pagestyle{scrheadings}
\section{sec}
\subsection{subsec}
\lipsum[1-6]
\lipsum[1-7]
\lipsum[1-5]
\section{sec}
\subsection{subsec}
\lipsum[1-10]
\end{document}

注意,如果在节开始时自动分页,则会出现问题。然后样式pagenumbersonly在之前的页面上设置。取消注释该\lipsum[1-5]命令即可查看此问题。


更新

也许您想使用scrreprt类和\chapters:

\documentclass[DIV=12, BCOR=5mm, bibliography=totocnumbered,
headheight=1cm,
footheight=1cm
]{scrreprt}

\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
%\addtokomafont{disposition}{\rmfamily}% why??
\usepackage{microtype}

\RedeclareSectionCommand[
  beforeskip=\dimexpr-1cm-1\baselineskip\relax,
  afterskip=2\baselineskip,
  font=\sffamily\LARGE
]{chapter}

\RedeclareSectionCommand[
  beforeskip=-2\baselineskip,
  afterskip=1.33\baselineskip,
  font=\sffamily\large
]{section}

% Set up headers and footers
\usepackage[automark, autooneside=false, headsepline, footsepline,
plainfootsepline
]{scrlayer-scrpage}
\clearpairofpagestyles
\ihead{\leftmark}
\ohead{\ifstr{\rightmark}{\leftmark}{}{\rightmark}}
\ofoot*{\pagemark}

\usepackage{lipsum}                                             % For testing 

\renewcaptionname{ngerman}{\refname}{Literaturverzeichnis}
\renewcaptionname{ngerman}{\figurename}{Abb.}

\begin{document}

\begingroup
\renewcommand\clearpage\relax
\pagestyle{plain}
\tableofcontents
\listoffigures
\listoftables
\endgroup

\clearpage
\chapter{sec}
\section{subsec}
\lipsum[1-6]
\lipsum[1-6]
%\lipsum[1-5]% uncomment to see the problem
\chapter{sec}
\section{subsec}
\lipsum[1-10]
\end{document}

答案2

我找到了一个解决我自己的问题的方法。问题是:

\xpretocmd{\section}{\thispagestyle{pagenumbersonly} \KOMAoptions{headsepline=true}}{}{}

干扰线路

\makeatletter 
\renewcommand\section{
    ~\vspace{1cm}
    \@startsection 
     {section}{1}{0mm}%         % name, ebene, einzug 
     {\baselineskip}%            % vor-abstand 
     {2\baselineskip}%            % nach-abstand 
     {\bfseries\sffamily\LARGE}%      % layout 
     } 
\makeatother 

\makeatletter 
\renewcommand\subsection{\@startsection 
     {subsection}{2}{0mm}%      % name, ebene, einzug 
     {2\baselineskip}%            % vor-abstand 
     {1.33\baselineskip}%            % nach-abstand 
     {\bfseries\sffamily\large}%           % layout 
     } 
\makeatother 

我必须使用\xpretocmd 更新命令。然后一切都按预期工作。如果有人能向我解释这种行为,我会很高兴。

相关内容