ファイル

ファイル

fancyhdr私は LaTeX を学習しています。本のドキュメント クラスでを使用しています。

水平線をページの全幅に渡って拡張したいです。

ページの境界に向かって拡張されたヘッダールールを示すスクリーンショット

試してみました\fancyheadoffsetが、ヘッダーの内容がページのメインの内容と一致しなくなりました。

ヘッダー全体がページ幅を占め、ヘッダーコンテンツも含まれる

\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 に変更すると、エラーが「修正」されます。ただし、値が設定されているかどうかに関係なく、視覚的には何も変わらないため、修正される理由や、正確に何が修正されるのかはわかりません。

結果

偶数ページでキャプチャ

奇数ページでキャプチャ

関連情報