Re: fancyhdr: testatine di opera collettanea

#23671
DMW
    Up
    0
    Down
    ::


    Ridefinire quei comandi dei capitoli mi sembra un po’ una porcata. Basta usare leftmark e rightmark.
    Questo codice funziona sia con bibtex sia con thebibliography, però non ho provato con l’indice analitico.
    `\documentclass[twoside, a4paper, openany]{report}

    \usepackage{fancyhdr}
    \usepackage{lipsum}

    \makeatletter
    \def\cleardoublepage{\clearpage\if@twoside \ifodd\c@page\else
    \hbox{}
    \vspace*{\fill}
    \vspace{\fill}
    \thispagestyle{empty}
    \newpage
    \if@twocolumn\hbox{}\newpage\fi\fi\fi}
    \makeatother

    \newcommand{\autoreattuale}{}
    \newcommand{\autorecapitolo}[1]{
    \if!#1!
    \let\autoreattuale\rightmark
    \else
    \renewcommand{\autoreattuale}{#1}
    \fi}

    \pagestyle{fancy}
    \renewcommand{\chaptermark}[1]{\markboth{\thechapter. #1}{}}
    \renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}}
    \fancyhf{}
    \fancyhead[LE,RO]{\scshape\thepage}
    \fancyhead[LO]{\bfseries\footnotesize\nouppercase{\autoreattuale}}
    \fancyhead[RE]{\bfseries\footnotesize\nouppercase{\leftmark}}
    %\renewcommand{\headrulewidth}{0.5pt}
    %\renewcommand{\footrulewidth}{0pt}
    %\addtolength{\headheight}{1.6pt}

    \makeatletter
    \renewenvironment{thebibliography}[1]
    {\chapter*{\bibname}\autorecapitolo{}%
    \@mkboth{\MakeUppercase\bibname}{\MakeUppercase\bibname}%
    \list{\@biblabel{\@arabic\c@enumiv}}%
    {\settowidth\labelwidth{\@biblabel{#1}}%
    \leftmargin\labelwidth
    \advance\leftmargin\labelsep
    \@openbib@code
    \usecounter{enumiv}%
    \let\p@enumiv\@empty
    \renewcommand\theenumiv{\@arabic\c@enumiv}}%
    \sloppy
    \clubpenalty4000
    \@clubpenalty \clubpenalty
    \widowpenalty4000%
    \sfcode`\.\@m}
    {\def\@noitemerr
    {\@latex@warning{Empty `thebibliography' environment}}%
    \endlist}
    \makeatother

    \begin{document}
    \tableofcontents
    \chapter{a}\autorecapitolo{Lorenzo Pantieri}
    \lipsum
    \lipsum

    \chapter{b}\autorecapitolo{Daniele Ferone}
    \lipsum
    \lipsum

    \begin{thebibliography}{a}
    \bibitem{a} a
    \bibitem{b} \lipsum\lipsum
    \end{thebibliography}

    \chapter{c}\autorecapitolo{Andrea Tonelli}
    \lipsum\lipsum

    \chapter{d}\autorecapitolo{}
    \section{titolo}
    \lipsum\lipsum

    \end{document}`

    ho messo l’autore al posto di \rightmark, quindi nella pagina dispari in alto a sinistra (LO) c’è lautore, mentre in quella pari in alto a destra (RE) c’è la marca del capitolo.
    Se l’autore è vuoto, compare automaticamente il \leftmark originale, che hai definito in alto.
    Prova a vedere l’ultimo capitolo.
    Se vuoi posso modificare la definizione di chapter in modo tale da evitare di scrivere
    `\autorecapitolo{}`
    dopo \chapter, nel caso in cui non ci sia bisogno di specificare l’autore.

    Ciao

    Andrea

    Go to top