Estou tendo problemas para definir meus cabeçalhos com o pacote fancyhdr. Aqui está o que eu quero: - na página esquerda, no lado esquerdo: partnumber.chapternumber. Nome do capítulo - na página direita, no lado direito:partnumber.chapternumber.sectionnumber Nome da seção
Tentei redefinir a marca do capítulo, sem sucesso. Aqui está um MWE.
\documentclass[twoside,12pt,openright,a4paper,usenames,dvipsnames]{book}
\usepackage[linktoc=all,hyperindex]{hyperref}
\usepackage{chngcntr}
\counterwithin{chapter}{part}
\usepackage{lipsum}
\usepackage{titlesec}
\usepackage[titles]{tocloft}
\renewcommand{\thechapter}{\arabic{chapter}}
\titleformat{name=\chapter}[display]
{\bfseries\LARGE}
{\filleft\MakeUppercase{\chaptertitlename} \Huge\thechapter}
{0ex}
{%\titlerule
\vspace{2ex}%
\filleft}
[\vspace{4ex}%
\titlerule]
\titleformat{name=\chapter,numberless}
{\bfseries\LARGE}
{}
{0ex}
{%\titlerule
\filleft\MakeUppercase}
[\vspace{4ex}%
\titlerule]
\titlespacing*{\chapter}{0pt}{-25pt}{40pt}
\titleformat{\part}[frame]
{\bfseries\Huge}
{\filright\large\enspace{\partname}\enspace}
{40pt}
{\Large\filcenter\MakeUppercase}
\titleclass{\part}{top}
\makeatletter
\renewcommand{\thechapter}{\@arabic\c@chapter}
\renewcommand{\p@chapter}{\thepart.}
\makeatother
\renewcommand{\chaptermark}[1]{%
\markboth{\thepart.\thechapter.\ #1}{}}
\renewcommand{\sectionmark}[1]{%
\markboth{\thechapter.\ #1}{}}
\usepackage{fancyhdr}
\fancypagestyle{bookstyle}{
\fancyhf{}
\fancyhead[LE]{\leftmark}
\fancyhead[RO]{\rightmark}
\fancyfoot[RO,LE]{\thepage}}
\fancypagestyle{plain}{
\renewcommand\headrulewidth{0pt}
\fancyhf{}
}
\begin{document}
\pagestyle{bookstyle}
\part{Part 1}
\chapter{Chap 1}
\label{chap:chapI1}
\section{Sec 1}
\lipsum[1-10]
\chapter{Chap 2}
\part{Part 2}
\chapter{Chap 1}
\chapter{Chap 2}
\end{document}
Talvez haja um conflito com o pacote titlesec, não consigo descobrir.
Responder1
Você está basicamente esquecendo de emitir \pagestyle{fancy}
.
No entanto, também a ordem dos seus pacotes está errada. Aqui está uma versão fixa.
\documentclass[twoside,12pt,openright,a4paper]{book}
\usepackage{titlesec}
\usepackage[titles]{tocloft}
\usepackage{fancyhdr}
\usepackage{chngcntr}
\usepackage{lipsum}
\usepackage[linktoc=all,hyperindex]{hyperref}
\counterwithin*{chapter}{part}
\makeatletter
\renewcommand{\p@chapter}{\thepart.}
\makeatother
\titleformat{name=\chapter}[display]
{\bfseries\LARGE}
{\filleft\MakeUppercase{\chaptertitlename} \Huge\thechapter}
{0ex}
{%\titlerule
\vspace{2ex}%
\filleft}
[\vspace{4ex}%
\titlerule]
\titleformat{name=\chapter,numberless}
{\bfseries\LARGE}
{}
{0ex}
{%\titlerule
\filleft\MakeUppercase}
[\vspace{4ex}%
\titlerule]
\titlespacing*{\chapter}{0pt}{-25pt}{40pt}
\titleformat{\part}[frame]
{\bfseries\Huge}
{\filright\large\enspace{\partname}\enspace}
{40pt}
{\Large\filcenter\MakeUppercase}
\titleclass{\part}{top}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{%
\markboth{\thepart.\thechapter.\ #1}{}}
\renewcommand{\sectionmark}[1]{%
\markright{\thepart.\thesection.\ #1}}
\fancypagestyle{bookstyle}{%
\fancyhf{}%
\fancyhead[LE]{\leftmark}%
\fancyhead[RO]{\rightmark}%
\fancyfoot[RO,LE]{\thepage}%
}
\fancypagestyle{plain}{%
\renewcommand\headrulewidth{0pt}
\fancyhf{}%
}
\setlength{\headheight}{14.5pt}
\pagestyle{bookstyle}
\begin{document}
\part{Part 1}
\chapter{Chap 1}
\label{chap:chapI1}
\section{Sec 1}
\lipsum[1-10]
\chapter{Chap 2}
\part{Part 2}
\chapter{Chap 1}
\chapter{Chap 2}
\end{document}