Testatine e marche

  • Creatore
    Topic
  • #16419
    lorenzo.pantieri
    Partecipante
      Up
      0
      Down
      ::


      Ciao a tutti, ho un documento così strutturato:
      `\documentclass{book}

      \usepackage{fancyhdr,lipsum}

      \pagestyle{fancy}
      \renewcommand{\chaptermark}[1]{\markboth{#1}{}}
      \renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}}
      \fancyhf{}
      \fancyhead[LE,RO]{\scshape\thepage}
      \fancyhead[LO]{\bfseries\footnotesize\nouppercase{\rightmark}}
      \fancyhead[RE]{\bfseries\footnotesize\nouppercase{\leftmark}}

      \begin{document}

      \chapter{Pizza}
      \lipsum[1]
      \section{Margherita}
      \lipsum
      \section{Quattro stagioni}
      \lipsum

      \chapter{Birra}
      \lipsum[1]
      \section{Heineken}
      \lipsum
      \section{Tuborg}
      \lipsum

      \appendix
      \chapter{Caffè} % Appendice senza sezioni
      \lipsum
      \lipsum
      \lipsum
      \end{document}
      `
      Dal momento che l’appendice non ha sezioni, vorrei che sia le testatine delle pagine pari, sia quelle delle pagine dispari recassero la scritta “Caffè”. Ci sono riuscito con un “manuale”
      `\markboth{Caffè}{Caffè}`
      subito dopo
      `\appendix
      \chapter{Caffè}
      `
      ma mi chiedevo se c’è un modo più elegante, usando il nome “interno” che LaTeX usa per indicare il titolo del capitolo. Ho provato invano con
      `\markboth{\thechapter}{\thechapter}`

      `\markboth{\chaptermark}{\chaptermark}`

      `\markboth{\markright}{\markright}`
      Grazie mille,
      L.

    Visualizzazione 2 filoni di risposte
    • Autore
      Risposte
      • #16420
        DMW
          Up
          0
          Down
          ::


          Lorenzo,

          Una sezione non definita è uguale a zero, o meglio \thechapter.0, e quindi basta sfruttare il pacchetto ifthen. Quindi puoi scrivere:
          `
          \documentclass{book}

          \usepackage{fancyhdr,lipsum}
          \usepackage{ifthen}

          \pagestyle{fancy}
          \renewcommand{\chaptermark}[1]{
          \ifthenelse{\equal{\thesection}{\thechapter.0}}{\markboth{#1}{#1}}{\markboth{#1}{}}
          }
          \renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}}
          \fancyhf{}
          \fancyhead[LE,RO]{\scshape\thepage}
          \fancyhead[LO]{\bfseries\footnotesize\nouppercase{\rightmark}}
          \fancyhead[RE]{\bfseries\footnotesize\nouppercase{\leftmark}}

          \begin{document}
          …..`

          che fa tutto in automatico. Vedi se funziona bene perché ho fatto poche prove.

          Ciao

          Andrea
          ________________________
          Inoltre vi annuncio, che oltre al pacchetto ifthen, esiste anche xifthen
          http://tug.ctan.org/macros/latex/contrib/xifthen/xifthen.pdf
          gli ho dato un’occhiata e sembra ottimo.

        • #16421
          DMW
            Up
            0
            Down
            ::


            Ancora meglio:
            `
            \renewcommand{\chaptermark}[1]{
            \ifthenelse{\equal{\arabic{section}}{0}}{\markboth{#1}{#1}}{\markboth{#1}{}}
            }
            `

            Ciao

            Andrea

          • #16422
            lorenzo.pantieri
            Partecipante
              Up
              0
              Down
              ::


              Ti ringrazio Andrea, il tuo codice funziona perfettamente!

              Un salutone,
              Lorenzo

          Visualizzazione 2 filoni di risposte
          • Devi essere connesso per rispondere a questo topic.

          Go to top