arquivos

arquivos

Estou aprendendo LaTeX. Estou usando fancyhdr, em uma classe de documento de livro.

Quero que a regra horizontal se estenda para ocupar toda a largura da página.

captura de tela mostrando a regra do cabeçalho estendida até os limites da página

Eu tentei \fancyheadoffset, mas o conteúdo do cabeçalho não está mais alinhado com o conteúdo principal da página.

todo o cabeçalho ocupa a largura da página, incluindo o conteúdo do cabeçalho

Também tentei usar um comando \makeboxe renovar \headrule, mas ele cria um espaço vertical indesejado que não consegui controlar (solução baseada em uma resposta nestepergunta).

Como posso ter apenas a extensão do hrule?

explicação visual do resultado esperado

arquivos

Classe de documento baseada em livro

\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}

Arquivo TeX principal

\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}

Responder1

Então, seguindo a sugestão do @Tom, tentei novamente usando a solução makebox da outra pergunta, apliquei a opção “shift” e funcionou (eu acho).

\makeatletter
    \def\headrule{{\if@fancyplain\let\headrulewidth\plainheadrulewidth\fi
        \makebox[\linewidth]{\rule[\linewidth]{\dimexpr(\paperwidth + 8mm)}{\headrulewidth}}
        \vskip-315.69928pt}}%
\makeatother

Explicação

Eu renovei \headruleo fancyhdrpacote, encapsulando o original \ruleno arquivo \makebox. Não tenho certeza se a regra se ajusta exatamente à largura real da página, mas pelo menos não há lacunas visíveis. (Acho que a regra vai além dos limites do papel.)

Tive que ajustar o original \vskipdo fancyhdrpacote porque o log mostrou esta saída:

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}.

Alterar o original \vskippara -315.69928pt “corrige” o erro. Não sei por que nem o que exatamente é corrigido, pois nada muda visualmente, esteja o valor definido ou não.

Resultado

capturar na página par

capturar em página ímpar

informação relacionada