我希望能够打印我的 \thetitle,这样fancyheader
如果我更改标题,它也会自动更改标题。
准备发布这篇文章时,我注意到如果我删除我的 MWE,\tableofcontents
它就会立即起作用。但由于我在实际文档中需要它,我不确定该怎么做?
我还注意到我同时使用了titlesec
和titling
。这样可以吗,还是会破坏程序?
在我的真实文档中,标题页后面也没有摘要,这似乎也打断了“标题制作”,因此之后\thetitle
也不起作用。
有任何想法吗?
谢谢 :)
% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
%
\documentclass[a4paper, 12pt, oneside]{article}
\usepackage[a4paper, portrait, margin=1in]{geometry}
\usepackage{caption}
\usepackage{titling}
\author{ReaderGuy42}
\title{An interesting title}
% HEADINGS & SECTIONS%
\usepackage[onehalfspacing]{setspace}
\usepackage{titlesec}
\usepackage{color}
%\newcommand{\hsp}{\hspace{20pt}}
\definecolor{gray75}{gray}{0.75}
\titleformat{\section}[hang]{\filleft\Huge\bfseries}{\thesection\hsp\textcolor{gray75}{|}\hsp}{0pt}{\Huge\bfseries}
\AddToHook{cmd/section/before}{\clearpage\setcounter{footnote}{0} }
%% FANCY HEADER %%
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf[]{}
\fancyhead[R]{ReaderGuy \thepage}
\fancyhead[C]{Proposal}
\fancyhead[L]{Working Title: \emph{\thetitle}}
\fancyfoot[]{}
\usepackage[a4paper, portrait, margin=1in]{geometry}
\fontsize{12pt}{12pt}\selectfont
\usepackage{setspace}
%\doublespacing
\newlength\FHoffset
\setlength\FHoffset{1cm}
\fancyheadoffset{\FHoffset}
\AtBeginEnvironment{quote}{\par\singlespacing\small}
\setlength{\parindent}{5em}
% START DOCUMENT %
\makeatletter
\begin{document}
\setlength{\footnotesep}{2mm} % shrinks gap between footnotes
\pagenumbering{roman}
\begin{titlepage}
\begin{center}
\vfill
{\large \scshape School”}\\[1.4cm]
{\Large Essay}\\[0.5cm]
\rule{\textwidth}{1.5pt}\\[0cm]
{\huge \bfseries \thetitle \par \Large A subtitle\ }\\[-0.5cm]
\rule{\textwidth}{1.5pt}\\[2.5cm]
{\Large by}\\[1cm]
{\huge \bfseries\theauthor}\\
\vfill
\vspace{1cm}
\end{center}
\end{titlepage}
\pagenumbering{roman}
\tableofcontents <------------------ the problem!!!?
\newpage
% START BODY %
\pagenumbering{arabic}
\begin{spacing}{2}
$body$
\thetitle
\end{spacing}
\clearpage
\end{document}
\makeatother
答案1
titling
和包titlesec
相互冲突,因为它们都定义了\thetitle
。
titling
在不同的命令中保存含义。
下面的代码重新组织了你的前言,先加载包,然后再设置。这避免了不必要的、潜在的有害重复。
我稍微改变了标题页部分,使间距更好。
我还删除了一些有害部分,即
\fontsize{12pt}{12pt}\selectfont
\makeatletter
footnote
并展示了在每个部分重置计数器的更好方法。
% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
%
\documentclass[a4paper, 12pt, oneside]{article}
\usepackage[a4paper, portrait, margin=1in,headheight=14.5pt]{geometry}
\usepackage{caption}
\usepackage{titling}
\usepackage[onehalfspacing]{setspace}
\usepackage{titlesec}
\usepackage{color}
\usepackage{fancyhdr}
\newcommand{\hsp}{\hspace{20pt}}
\definecolor{gray75}{gray}{0.75}
\titleformat{\section}[hang]
{\filleft\Huge\bfseries}
{\thesection\hsp\textcolor{gray75}{|}\hsp}
{0pt}
{\Huge\bfseries}
\AddToHook{cmd/section/before}{\clearpage\setcounter{footnote}{0}}
%% FANCY HEADER %%
\pagestyle{fancy}
\fancyhf[]{}
\fancyhead[R]{ReaderGuy \thepage}
\fancyhead[C]{Proposal}
\fancyhead[L]{Working Title: \emph{\THETITLE}}
\newlength\FHoffset
\setlength\FHoffset{1cm}
\fancyheadoffset{\FHoffset}
\AtBeginEnvironment{quote}{\par\singlespacing\small}
\setlength{\parindent}{5em}
\setlength{\footnotesep}{2mm} % shrinks gap between footnotes
%% metadata
\author{ReaderGuy42}
\title{An interesting title}
\AtBeginDocument{\NewCommandCopy{\THETITLE}{\thetitle}}
% START DOCUMENT %
\begin{document}
\pagenumbering{roman}
\begin{titlepage}
\begin{center}
\vfill
{\large \scshape School”}\\[1.4cm]
{\Large Essay}\\[0.5cm]
\rule{\textwidth}{1.5pt}\\[0cm]
{\huge \bfseries \thetitle \par \Large A subtitle\\}
\rule{\textwidth}{1.5pt}\\[2.5cm]
{\Large by}\\[1cm]
{\huge \bfseries\theauthor}\\
\vfill
\vspace{1cm}
\end{center}
\end{titlepage}
\pagenumbering{roman}
\tableofcontents
\newpage
% START BODY %
\pagenumbering{arabic}
$body$
\thetitle
\clearpage
\end{document}