![在标题行中使用 \thetitle (fancyhdr)?在标题页之外 \thetitle 显示为“0”?如果我删除 \tableofcontents 是否可行?](https://linux22.com/image/458790/%E5%9C%A8%E6%A0%87%E9%A2%98%E8%A1%8C%E4%B8%AD%E4%BD%BF%E7%94%A8%20%5Cthetitle%20(fancyhdr)%EF%BC%9F%E5%9C%A8%E6%A0%87%E9%A2%98%E9%A1%B5%E4%B9%8B%E5%A4%96%20%5Cthetitle%20%E6%98%BE%E7%A4%BA%E4%B8%BA%E2%80%9C0%E2%80%9D%EF%BC%9F%E5%A6%82%E6%9E%9C%E6%88%91%E5%88%A0%E9%99%A4%20%5Ctableofcontents%20%E6%98%AF%E5%90%A6%E5%8F%AF%E8%A1%8C%EF%BC%9F.png)
我希望能够打印我的 \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}