
我正在學習 LaTeX。我正在fancyhdr
書籍文檔類中使用 , 。
我希望水平線能夠延伸,以便佔據整個頁面寬度。
我已經嘗試過\fancyheadoffset
,但標題內容不再與頁面的主要內容對齊。
我也嘗試過使用 a\makebox
並更新\headrule
命令,但它會創建我無法控制的不需要的垂直空間(解決方案基於此答案問題)。
我怎麼才能只延長 hrule 呢?
文件
基於書籍的文檔類
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{novel}[2024/02/01 Novel]
\LoadClass[12pt,a5paper,twoside,openright]{book}
% UTF-8 support.
\RequirePackage[utf8]{inputenc}
%%%%%%%%%%%
% Layout. %
%%%%%%%%%%%
% Basic layout.
\RequirePackage[
papersize={152mm,214mm},
layout=a5paper,
layouthoffset=2mm,
layoutvoffset=2mm,
bindingoffset=8mm,
left=17mm,
right=17mm,
top=17mm,
bottom=17mm,
%showframe
]{geometry}
%%%%%%%%%%%%%%%
% Formatting. %
%%%%%%%%%%%%%%%
% Helps build better header and footer; places the page number in the footer.
\RequirePackage{fancyhdr}
% Redefine fancy style.
\fancypagestyle{fancy}{
\fancyheadoffset[loh,reh]{27mm}
\fancyheadoffset[roh,leh]{19mm}
\fancyhf{}
\fancyhead[EL]{\smaller{\smaller{\textit{\MakeUppercase{\vspace{\baselineskip} \\ \thetitle}}}}}
\fancyhead[OR]{\smaller{\smaller{\MakeUppercase{\chaptername\ \thechapter\ \\ \leftmark}}}}
\renewcommand{\headrulewidth}{1pt}
\fancyfoot[LE,RO]{\smaller{\thepage}}}
% Redefine plain style to match fancy style.
\fancypagestyle{plain}{
\addtolength{\headwidth}{0cm}
\fancyhf{}
\renewcommand{\headrulewidth}{0pt}
\fancyfoot[LE,RO]{\smaller{\thepage}}}
% Removes headers on empty pages.
\RequirePackage{emptypage}
% Used for convenient title management.
\RequirePackage{titling}
% Font size adjustment commands.
\RequirePackage{relsize}
% Reduces widows and orphans.
\RequirePackage[all]{nowidow}
% Change the chapter title in the header to only the chapter title.
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
%%%%%%%%%%%%%%%
% Typography. %
%%%%%%%%%%%%%%%
% Fixes some hyphenation issues (lines longer than body width).
\sloppy
% Micro-typographical adjustments. TODO: reevaluate usefulness
\RequirePackage{microtype}
% Remove space between paragraphs.
\RequirePackage[skip=0pt,indent=15pt]{parskip}
主 TeX 文件
\documentclass[]{novel}
% This is necessary for proper language-specific hyphenation.
\usepackage[french]{babel}
\usepackage[]{lipsum}
%%%%%%%%%%%%%
% Metadata. %
%%%%%%%%%%%%%
\author{NemuLumeN}
\title{Title of the book}
\date{2022}
\pagestyle{fancy}
\begin{document}
\maketitle
\tableofcontents
\chapter{First chapter title}
\lipsum[1-10]
\chapter{Second chapter}
Oh yeah
\end{document}
答案1
因此,根據@Tom的建議,我再次嘗試使用另一個問題中的makebox解決方案,應用“shift”選項,並且它起作用了(我認為)。
\makeatletter
\def\headrule{{\if@fancyplain\let\headrulewidth\plainheadrulewidth\fi
\makebox[\linewidth]{\rule[\linewidth]{\dimexpr(\paperwidth + 8mm)}{\headrulewidth}}
\vskip-315.69928pt}}%
\makeatother
解釋
我通過將原始包\headrule
封裝到.我不確定該規則是否完全適合實際頁面寬度,但至少沒有明顯的間隙。 (我認為該規則超出了紙張限制。)fancyhdr
\rule
\makebox
我必須調整包\vskip
的原始內容fancyhdr
,因為日誌顯示了以下輸出:
Package fancyhdr Warning: \headheight is too small (12.0pt):
(fancyhdr) Make it at least 301.59924pt, for example:
(fancyhdr) \setlength{\headheight}{301.59924pt}.
(fancyhdr) You might also make \topmargin smaller to compensate:
(fancyhdr) \addtolength{\topmargin}{-289.59924pt}.
將原始值更改\vskip
為 -315.69928pt “修復”了該錯誤。不過,我不知道為什麼也不知道到底修復了什麼,因為無論是否設定了該值,視覺上都沒有任何變化。