在 Latex KOMA 演示文稿脚本的页眉中使用章节标题

在 Latex KOMA 演示文稿脚本的页眉中使用章节标题

我想使用 Latex KOMA 演示模板 [1] 进行演示。但我想替换页眉位于(子)部分标题的顶部。

目前 Latex KOMA 演示模板[1]如下所示:

\documentclass[
paper=128mm:96mm, % The same paper size as used in the beamer class
fontsize=11pt, % Font size
pagesize, % Write page size to dvi or pdf
parskip=half-, % Paragraphs separated by half a line
]{scrartcl} % KOMA script (article)

\linespread{1.12} % Increase line spacing for readability

%------------------------------------------------
% Colors
\usepackage{xcolor}  % Required for custom colors
% Define a few colors for making text stand out within the presentation
\definecolor{mygreen}{RGB}{44,85,17}
\definecolor{myblue}{RGB}{34,31,217}
\definecolor{mybrown}{RGB}{194,164,113}
\definecolor{myred}{RGB}{255,66,56}
% Use these colors within the presentation by enclosing text in the commands below
\newcommand*{\mygreen}[1]{\textcolor{mygreen}{#1}}
\newcommand*{\myblue}[1]{\textcolor{myblue}{#1}}
\newcommand*{\mybrown}[1]{\textcolor{mybrown}{#1}}
\newcommand*{\myred}[1]{\textcolor{myred}{#1}}
%------------------------------------------------

%------------------------------------------------
% Margins
\usepackage[ % Page margins settings
includeheadfoot,
top=3.5mm,
bottom=3.5mm,
left=5.5mm,
right=5.5mm,
headsep=6.5mm,
footskip=8.5mm
]{geometry}
%------------------------------------------------

%------------------------------------------------
% Fonts
\usepackage[T1]{fontenc}     % For correct hyphenation and T1 encoding
\usepackage{lmodern} % Default font: latin modern font
%\usepackage{fourier} % Alternative font: utopia
%\usepackage{charter} % Alternative font: low-resolution roman font
\renewcommand{\familydefault}{\sfdefault} % Sans serif - this may need to be commented to see the alternative fonts
%------------------------------------------------

%------------------------------------------------
% Various required packages
\usepackage{amsthm} % Required for theorem environments
\usepackage{bm} % Required for bold math symbols (used in the footer of the slides)
\usepackage{graphicx} % Required for including images in figures
\usepackage{tikz} % Required for colored boxes
\usepackage{booktabs} % Required for horizontal rules in tables
\usepackage{multicol} % Required for creating multiple columns in slides
\usepackage{lastpage} % For printing the total number of pages at the bottom of each slide
\usepackage[english]{babel} % Document language - required for customizing section titles
\usepackage{microtype} % Better typography
\usepackage{tocstyle} % Required for customizing the table of contents
%------------------------------------------------

%------------------------------------------------
% Slide layout configuration
\usepackage{scrpage2} % Required for customization of the header and footer
\pagestyle{scrheadings} % Activates the pagestyle from scrpage2 for custom headers and footers
\clearscrheadfoot % Remove the default header and footer
\setkomafont{pageheadfoot}{\normalfont\color{black}\sffamily} % Font settings for the header and footer

% Sets vertical centering of slide contents with increased space between paragraphs/lists
\makeatletter
\renewcommand*{\@textbottom}{\vskip \z@ \@plus 1fil}
\newcommand*{\@texttop}{\vskip \z@ \@plus .5fil}
\addtolength{\parskip}{\z@\@plus .25fil}
\makeatother

% Remove page numbers and the dots leading to them from the outline slide
\makeatletter
\newtocstyle[noonewithdot]{nodotnopagenumber}{\settocfeature{pagenumberbox}{\@gobble}}
\makeatother
\usetocstyle{nodotnopagenumber}

\AtBeginDocument{\renewcaptionname{english}{\contentsname}{\Large Outline}} % Change the name of the table of contents
%------------------------------------------------

%------------------------------------------------
% Header configuration - if you don't want a header remove this block
\ihead{
\hspace{-2mm}
\begin{tikzpicture}[remember picture,overlay]
\node [xshift=\paperwidth/2,yshift=-\headheight] (mybar) at (current page.north west)[rectangle,fill,inner sep=0pt,minimum width=\paperwidth,minimum height=2\headheight,top color=mygreen!64,bottom color=mygreen]{}; % Colored bar
\node[below of=mybar,yshift=3.3mm,rectangle,shade,inner sep=0pt,minimum width=128mm,minimum height =1.5mm,top color=black!50,bottom color=white]{}; % Shadow under the colored bar
shadow
\end{tikzpicture}
\color{white}\runninghead} % Header text defined by the \runninghead command below and colored white for contrast
%------------------------------------------------

%------------------------------------------------
% Footer configuration
%\newlength{\footheight}
\setlength{\footheight}{8mm} % Height of the footer
\addtokomafont{pagefoot}{\footnotesize} % Small font size for the footnote

\ifoot{% Left side
\hspace{-2mm}
\begin{tikzpicture}[remember picture,overlay]
\node [xshift=\paperwidth/2,yshift=\footheight] at (current page.south west)[rectangle,fill,inner sep=0pt,minimum width=\paperwidth,minimum height=3pt,top color=mygreen,bottom color=mygreen]{}; % Green bar
\end{tikzpicture}
\myauthor\ \raisebox{0.2mm}{$\bm{\vert}$}\ \myuni % Left side text
}

\ofoot[\pagemark/\pageref{LastPage}\hspace{-2mm}]{\pagemark/\pageref{LastPage}\hspace{-2mm}} % Right side
%------------------------------------------------

%------------------------------------------------
% Section spacing - deeper section titles are given less space due to lesser importance
\usepackage{titlesec} % Required for customizing section spacing
\titlespacing{\section}{0mm}{0mm}{0mm} % Lengths are: left, before, after
\titlespacing{\subsection}{0mm}{0mm}{-1mm} % Lengths are: left, before, after
\titlespacing{\subsubsection}{0mm}{0mm}{-2mm} % Lengths are: left, before, after
\setcounter{secnumdepth}{0} % How deep sections are numbered, set to no numbering by default - change to 1 for numbering sections, 2 for numbering sections and subsections, etc
%------------------------------------------------

%----------------------------------------------------------------------------------------
%   PRESENTATION INFORMATION
%----------------------------------------------------------------------------------------
\newcommand*{\mytitle}{Presentation Title} % Title
\newcommand*{\runninghead}{Running Head} % Running head displayed on almost all slides
\newcommand*{\myauthor}{John Smith} % Presenters name(s)
\newcommand*{\mydate}{\today} % Presentation date
\newcommand*{\myuni}{University of California --- Department of Statistics} % University or department
%----------------------------------------------------------------------------------------

\begin{document}

%----------------------------------------------------------------------------------------
\section{Displaying Text}
\clearpage
%----------------------------------------------------------------------------------------

\end{document}

我曾尝试更换页眉通过以下自定义\currtitle命令:

\makeatletter
\newcommand{\currtitle}{\ttl@savetitle}
\makeatother

%------------------------------------------------
% Header configuration - if you don't want a header remove this block
\ihead{
\hspace{-2mm}
\begin{tikzpicture}[remember picture,overlay]
\node [xshift=\paperwidth/2,yshift=-\headheight] (mybar) at (current page.north west)[rectangle,fill,inner sep=0pt,minimum width=\paperwidth,minimum height=2\headheight,top color=mygreen!64,bottom color=mygreen]{}; % Colored bar
\node[below of=mybar,yshift=3.3mm,rectangle,shade,inner sep=0pt,minimum width=128mm,minimum height =1.5mm,top color=black!50,bottom color=white]{}; % Shadow under the colored bar
shadow
\end{tikzpicture}
\color{white}\currtitle} % Header text defined by the \runninghead command below and colored white for contrast

但是,我怎样才能隐藏幻灯片中的章节标题?(在绿色标题栏下方)或者我怎样才能将(子)章节标题移动到页眉位置?

谢谢!

[1]http://www.latextemplates.com/template/koma-script-presentation

答案1

我在评论中问过您是否需要生成目录,并且一直坚持要求您给出答案。这样做是有充分理由的。

目前,(使用此解决方案/解决方法)根本没有打印任何章节标题(使用 的传统意义\@startsection)。每次调用新命令时,sectiona页面都会被清除(即开始新的页面/幻灯片),运行头会更新并创建目录条目。您可以只更新章节定义,但这意味着会弄乱 的定义\tableofcontents,甚至弄乱图表/表格列表或参考书目。

Markus 的原始论文已有数年历史,其中许多内容都已发生改变。例如,KOMA 现在会发出巨大警告,因为titlesec使用了 。一个名为 的新软件包scrlayer-scrpage已加入 KOMA 软件包,为运行头做出了巨大贡献。

总而言之,本文介绍了使用 KOMA 文章类进行演示的原型。有一些粗糙的地方需要打磨。作为原型,几年前它相当不错,但现在,特别是在提供的模板中,我会说:“别碰它!”

回到主题,我做了什么?我使用 xparse 包来检查加星号的版本。加星号的版本会更新运行标题(类似于框架标题),但不放置目录条目。此外,计数器section(反正也没用)会前进一格。
如果不使用加星号的命令sectiona,则可以为目录条目选择一个可选标题。这在某种程度上等同于 section 命令的标准行为。
subsectiona更新标题(略小一些),并在目录中添加子节条目。

免责声明:提供的模板有一些缺点,特别是如果您认为覆盖和类似的东西很棒,请切换到专门为此设计的类。
别误会我的意思,使用 scrartcl 进行演示是一个好主意,但您永远不会获得它提供的所有花哨功能 beamer

对 MWE 来说重要的只是以下内容,说实话,虽然不多,但仍然......

\usepackage{xparse}
%
\DeclareDocumentCommand\sectiona{s o m}{%
    \clearpage%
    \IfBooleanTF{#1}{%
        \renewcommand{\runninghead}{#3}%
    }{%
        \refstepcounter{section}%JB: Please don't aske mw, %
%why i am doing this, as they aren't printed anyway%
        \renewcommand{\runninghead}{#3}%always use the%
%       mandatory argument for the runninghead%
        \IfNoValueTF{#2}{%
            \addsectiontocentry{}{#3}%
        }{%
            \addsectiontocentry{}{#2}%
        }%
    }%
}%
\newcommand\subsectiona[1]{%
    \clearpage%
    \refstepcounter{subsection}%
    \renewcommand{\runninghead}{\small #1\par}%
    \addsubsectiontocentry{}{#1}%
}%
%

现在是完整的示例,可供复制/粘贴/编译:

\documentclass[
paper=128mm:96mm, 
fontsize=11pt, 
pagesize, 
parskip=half-, 
]{scrartcl} 

\linespread{1.12} 

\usepackage{bm}  
\usepackage{xcolor}  

\definecolor{mygreen}{RGB}{44,85,17}
\definecolor{myblue}{RGB}{34,31,217}
\definecolor{mybrown}{RGB}{194,164,113}
\definecolor{myred}{RGB}{255,66,56}

\newcommand*{\mygreen}[1]{\textcolor{mygreen}{#1}}
\newcommand*{\myblue}[1]{\textcolor{myblue}{#1}}
\newcommand*{\mybrown}[1]{\textcolor{mybrown}{#1}}
\newcommand*{\myred}[1]{\textcolor{myred}{#1}}




\usepackage[ 
includeheadfoot,
top=3.5mm,
bottom=3.5mm,
left=5.5mm,
right=5.5mm,
headsep=6.5mm,
footskip=8.5mm
]{geometry}




\usepackage[T1]{fontenc}     
\usepackage{lmodern} 


\renewcommand{\familydefault}{\sfdefault} 




\usepackage{tikz} 
\usepackage{lastpage} 
\usepackage[english]{babel} 
\usepackage{microtype} 
\usepackage{tocstyle} 
\usepackage{scrpage2} 
\pagestyle{scrheadings} 
\clearscrheadfoot 
\setkomafont{pageheadfoot}{\normalfont\color{black}\sffamily} 

\makeatletter
\renewcommand*{\@textbottom}{\vskip \z@ \@plus 1fil}
\newcommand*{\@texttop}{\vskip \z@ \@plus .5fil}
\addtolength{\parskip}{\z@\@plus .25fil}
\makeatother

\makeatletter
\newtocstyle[noonewithdot]{nodotnopagenumber}{\settocfeature{pagenumberbox}{\@gobble}}
\makeatother
\usetocstyle{nodotnopagenumber}

\AtBeginDocument{\renewcaptionname{english}{\contentsname}{Outline}} 




\ihead{
\hspace{-2mm}
\begin{tikzpicture}[remember picture,overlay]
\node [xshift=\paperwidth/2,yshift=-\headheight] (mybar) at (current page.north west)[rectangle,fill,inner sep=0pt,minimum width=\paperwidth,minimum height=2\headheight,top color=mygreen!64,bottom color=mygreen]{}; 
\node[below of=mybar,yshift=3.3mm,rectangle,shade,inner sep=0pt,minimum width=128mm,minimum height =1.5mm,top color=black!50,bottom color=white]{}; 
shadow
\end{tikzpicture}
\color{white}\runninghead} 





\setlength{\footheight}{8mm} 
\addtokomafont{pagefoot}{\footnotesize} 

\ifoot{
\hspace{-2mm}
\begin{tikzpicture}[remember picture,overlay]
\node [xshift=\paperwidth/2,yshift=\footheight] at (current page.south west)[rectangle,fill,inner sep=0pt,minimum width=\paperwidth,minimum height=3pt,top color=mygreen,bottom color=mygreen]{}; 
\end{tikzpicture}
\myauthor\ \raisebox{0.2mm}{$\bm{\vert}$}\ \myuni 
}

\ofoot[\pagemark/\pageref{LastPage}\hspace{-2mm}]{\pagemark/\pageref{LastPage}\hspace{-2mm}} 




\usepackage{titlesec} 
\titlespacing{\section}{0mm}{0mm}{0mm} 
\titlespacing{\subsection}{0mm}{0mm}{-1mm} 
\titlespacing{\subsubsection}{0mm}{0mm}{-2mm} 
\setcounter{secnumdepth}{0} 





\newcommand*{\mytitle}{Presentation Title} 
\usepackage{nameref}
\newcommand*{\runninghead}{}
\newcommand*{\myauthor}{John Smith} 
\newcommand*{\mydate}{\today} 
\newcommand*{\myuni}{University of California --- Department of Statistics} 


\usepackage{xparse}
%
\DeclareDocumentCommand\sectiona{s o m}{%
    \clearpage%
    \IfBooleanTF{#1}{%
        \renewcommand{\runninghead}{#3}%
    }{%
        \refstepcounter{section}%JB: Please don't aske mw, %
%why i am doing this, as they aren't printed anyway%
        \renewcommand{\runninghead}{#3}%always use the%
%       mandatory argument for the runninghead%
        \IfNoValueTF{#2}{%
            \addsectiontocentry{}{#3}%
        }{%
            \addsectiontocentry{}{#2}%
        }%
    }%
}%
\newcommand\subsectiona[1]{%
    \clearpage%
    \refstepcounter{subsection}%
    \renewcommand{\runninghead}{\small #1\par}%
    \addsubsectiontocentry{}{#1}%
}%
%




\begin{document}
\tableofcontents
\sectiona{a section}
Text in a section, runninghead updated

\sectiona{a different section}
Text in another section, runninghead updated
\subsectiona{a subsection}
The runninghead is now smaller, to distiguish it a bit from a
section
\sectiona*{a starred section}
Text in a starred section, runninghead updated, but no toc entry

\sectiona[toc entry]{running head}
an optional argument? REALLY?
\end{document}

相关内容