我需要在标题页上添加标题头(请参阅相关问题)这里)和,使用标题包格式化标题页。不幸的是,加载标题包时标题头会消失。
有没有办法用标题包为标题页添加页眉?
PS 由于某种原因,\thetitle 不显示主标题,而是显示最新的 (subsub) 部分标题。这些问题可能相互关联。
\documentclass[a4paper,12pt,bibliography=totoc]{scrartcl}
%----------------------
\usepackage{titling}
\pretitle{\huge \centering \bfseries }
\posttitle{\par \vspace{\baselineskip}} %
\preauthor{\centering \normalsize}
\postauthor{\par}
%--------------------------------
\usepackage{titlesec} % for editing titles
% Following formats titles
\titleformat{\section}{\normalfont\fontsize{14}{12}\bfseries}{\thesection}{1em}{}
\titleformat{\subsection}{\normalfont\fontsize{12}{12}\bfseries}{\thesubsection}{1em}{}
\titleformat{\subsubsection}{\normalfont\fontsize{12}{12}\itshape}{\thesubsubsection}{1em}{}
%----------------------------------
\usepackage[affil-it]{authblk}
\usepackage{blindtext}
\usepackage{newtxtext} % text in Times font
\usepackage{newtxmath} % math in Times font
\setkomafont{disposition}{\bfseries} % Makes sure everything, even fonts are in Times font
%\usepackage{fontspec}
%\setmainfont{Times New Roman}
\titlehead{THIS NEEDS TO BE DISPLAYED \hfill}
\title{Main Title}
\subtitle{Sub Title}
\author[1,2,*]{First Author}
\author[1,2]{Second Author}
\author[1,3]{Third Author}
\author[2,4]{Supervisor Author}
\affil[1]{University}
\affil[2]{College}
\affil[3]{Institute}
\affil[4]{School \break}
\affil[*]{Corresponding author: [email protected] \newline Contributing authors: [email protected], [email protected], [email protected]}
\date{\today}
\begin{document}
\maketitle
\section{Section}
\subsection{Subsection}
\subsubsection{Subsubsection}
Reference to the title, which is: \thetitle % dependent on the titling-package
\end{document}
答案1
该titling
包重新定义了\maketitle
。因此它破坏了 KOMA-Script 命令的使用\titlehead
。
您可以使用包scrlayer
或scrlayer-scrpage
添加标题头:
\usepackage{scrlayer}% or scrlayer-scrpage which loads scrlayer
\DeclareNewLayer[%
headsep,
foreground,
contents={%
\begin{minipage}[t]{\textwidth}%
\usekomafont{titlehead}{\csname @titlehead\endcsname\par}%
\end{minipage}\par}
]{titlehead}
\DeclarePageStyleByLayers{titlepage}{titlehead}
\AddToHook{cmd/maketitle/after}{\thispagestyle{titlepage}}
重要提示:不要将包titlsec
与 KOMA-Script 类一起使用。这会破坏 KOMA-Script 功能。因此,您将收到一堆警告,甚至错误。此外,此包还定义了自己的\thetitle
。所以这是您第二个问题的原因。
这里建议titlesec
用 KOMA-Script 命令替换您的设置:
\documentclass[a4paper,12pt,bibliography=totoc,
numbers=noenddot,% <- added
sfdefaults=false% <- added (replaces \setkomafont{disposition}{\bfseries}), needs version 3.39 or newer
]{scrartcl}
%----------------------
\usepackage{titling}
\pretitle{\huge \centering \bfseries }
\posttitle{\par \vspace{\baselineskip}} %
\preauthor{\centering \normalsize}
\postauthor{\par}
\setkomafont{section}{\fontsize{14}{12}\selectfont}
\setkomafont{subsection}{\fontsize{12}{12}\selectfont}
\setkomafont{subsubsection}{\normalfont\itshape\fontsize{14}{12}\selectfont}
\renewcommand{\sectionformat}{\thesection\autodot\hspace{1em}}
\renewcommand{\subsectionformat}{\thesubsection\autodot\hspace{1em}}
\renewcommand{\subsubsectionformat}{\thesubsubsection\autodot\hspace{1em}}
\usepackage{scrlayer}% or scrlayer-scrpage which loads scrlayer
\DeclareNewLayer[%
headsep,
foreground,
contents={%
\begin{minipage}[t]{\textwidth}%
\usekomafont{titlehead}{\csname @titlehead\endcsname\par}%
\end{minipage}\par}
]{titlehead}
\DeclarePageStyleByLayers{titlepage}{titlehead}
\AddToHook{cmd/maketitle/after}{\thispagestyle{titlepage}}
%----------------------------------
\usepackage[affil-it]{authblk}
\usepackage{blindtext}
\usepackage{newtxtext} % text in Times font
\usepackage{newtxmath} % math in Times font
%\usepackage{fontspec}
%\setmainfont{Times New Roman}
\titlehead{THIS NEEDS TO BE DISPLAYED \hfill}
\title{Main Title}
\subtitle{Sub Title}
\author[1,2,*]{First Author}
\author[1,2]{Second Author}
\author[1,3]{Third Author}
\author[2,4]{Supervisor Author}
\affil[1]{University}
\affil[2]{College}
\affil[3]{Institute}
\affil[4]{School \break}
\affil[*]{Corresponding author: [email protected] \newline Contributing authors: [email protected], [email protected], [email protected]}
\date{\today}
\begin{document}
\maketitle
\section{Section}
\subsection{Subsection}
\subsubsection{Subsubsection}
Reference to the title, which is: \thetitle. % dependent on the titling-package
\end{document}
更新:
如果标题页应该使用与其他页面相同的页脚,请加载包scrlayer-scrpage
并将页脚图层添加到新的图层页面样式中:
\usepackage{scrlayer-scrpage}% sets page style scrheadings automatically
\DeclareNewLayer[%
headsep,
foreground,
contents={%
\begin{minipage}[t]{\textwidth}%
\usekomafont{titlehead}{\csname @titlehead\endcsname\par}%
\end{minipage}\par}
]{titlehead}
\DeclarePageStyleByLayers{titlepage}{titlehead}
\ForEachLayerOfPageStyle{scrheadings}{%
\Ifstrstart{#1}{scrheadings.foot}{\AddLayersToPageStyle{titlepage}{#1}}%
}
\AddToHook{cmd/maketitle/after}{\thispagestyle{titlepage}}
例子:
\documentclass[a4paper,12pt,bibliography=totoc,
numbers=noenddot,% <- added
sfdefaults=false% <- added (replaces \setkomafont{disposition}{\bfseries}), needs version 3.39 or newer
]{scrartcl}
%----------------------
\usepackage{titling}
\pretitle{\huge \centering \bfseries }
\posttitle{\par \vspace{\baselineskip}} %
\preauthor{\centering \normalsize}
\postauthor{\par}
\setkomafont{section}{\fontsize{14}{12}\selectfont}
\setkomafont{subsection}{\fontsize{12}{12}\selectfont}
\setkomafont{subsubsection}{\normalfont\itshape\fontsize{14}{12}\selectfont}
\renewcommand{\sectionformat}{\thesection\autodot\hspace{1em}}
\renewcommand{\subsectionformat}{\thesubsection\autodot\hspace{1em}}
\renewcommand{\subsubsectionformat}{\thesubsubsection\autodot\hspace{1em}}
\usepackage{scrlayer-scrpage}% sets page style scrheadings automatically
\DeclareNewLayer[%
headsep,
foreground,
contents={%
\begin{minipage}[t]{\textwidth}%
\usekomafont{titlehead}{\csname @titlehead\endcsname\par}%
\end{minipage}\par}
]{titlehead}
\DeclarePageStyleByLayers{titlepage}{titlehead}
\ForEachLayerOfPageStyle{scrheadings}{%
\Ifstrstart{#1}{scrheadings.foot}{\AddLayersToPageStyle{titlepage}{#1}}%
}
\AddToHook{cmd/maketitle/after}{\thispagestyle{titlepage}}
%----------------------------------
\usepackage[affil-it]{authblk}
\usepackage{blindtext}
\usepackage{newtxtext} % text in Times font
\usepackage{newtxmath} % math in Times font
%\usepackage{fontspec}
%\setmainfont{Times New Roman}
\titlehead{THIS NEEDS TO BE DISPLAYED \hfill}
\title{Main Title}
\subtitle{Sub Title}
\author[1,2,*]{First Author}
\author[1,2]{Second Author}
\author[1,3]{Third Author}
\author[2,4]{Supervisor Author}
\affil[1]{University}
\affil[2]{College}
\affil[3]{Institute}
\affil[4]{School \break}
\affil[*]{Corresponding author: [email protected] \newline Contributing authors: [email protected], [email protected], [email protected]}
\date{\today}
\begin{document}
\maketitle
\section{Section}
\subsection{Subsection}
\subsubsection{Subsubsection}
Reference to the title, which is: \thetitle. % dependent on the titling-package
\end{document}
答案2
第一个问题可以通过 fancyhdr 包解决。不过,最好不要再引入另一个用于格式化标题的包。
\thetitle 问题仍然存在。
\documentclass[a4paper,12pt,bibliography=totoc]{scrartcl}
%----------------------
\usepackage{titling}
\pretitle{\huge \centering \bfseries }
\posttitle{\par \vspace{\baselineskip}} %
\preauthor{\centering \normalsize}
\postauthor{\par}
%--------------------------------
\usepackage{titlesec} % for editing titles
% Following formats titles
\titleformat{\section}{\normalfont\fontsize{14}{12}\bfseries}{\thesection}{1em}{}
\titleformat{\subsection}{\normalfont\fontsize{12}{12}\bfseries}{\thesubsection}{1em}{}
\titleformat{\subsubsection}{\normalfont\fontsize{12}{12}\itshape}{\thesubsubsection}{1em}{}
%----------------------------------
\usepackage[affil-it]{authblk}
\usepackage{blindtext}
\usepackage{newtxtext} % text in Times font
\usepackage{newtxmath} % math in Times font
\setkomafont{disposition}{\bfseries} % Makes sure everything, even fonts are in Times font
%\usepackage{fontspec}
%\setmainfont{Times New Roman}
\titlehead{THIS NEEDS TO BE DISPLAYED \hfill}
\title{Main Title}
\subtitle{Sub Title}
\author[1,2,*]{First Author}
\author[1,2]{Second Author}
\author[1,3]{Third Author}
\author[2,4]{Supervisor Author}
\affil[1]{University}
\affil[2]{College}
\affil[3]{Institute}
\affil[4]{School \break}
\affil[*]{Corresponding author: [email protected] \newline Contributing authors: [email protected], [email protected], [email protected]}
\date{\today}
%-----Added-------
\fancypagestyle{fancyfirstpage}
{
\fancyhf{}
\renewcommand{\headrulewidth}{0pt}
\pagestyle{fancy}
\lhead{\mytitlehead}
}
%--------
\begin{document}
\maketitle
\thispagestyle{fancy} %ADDED
\section{Section}
\subsection{Subsection}
\subsubsection{Subsubsection}
Reference to the title, which is: \thetitle % dependent on the titling-package
\end{document}