Marcas de capítulo e apêndice

Marcas de capítulo e apêndice

Estou criando um documento usando bookdocumentclass. Neste documento adicionei marcas de capítulo usando a resposta de @TomBombadil emComo alguém pode colocar um marcador em cada página de um capítulo?.

O estranho é que embora o código funcione bem nos capítulos, ao adicionar um apêndice, não consigo produzir um documento devido a um erro estranho e pouco claro, pelo menos para mim,

Erro matemático do pacote PGF: Função desconhecida `A' (em '-A/20*29.69974').

Meu código é

\documentclass[11pt,a4paper]{book}
\usepackage{lipsum}


\let\MakeUppercase\relax
\usepackage{etex}%Makes able the use of many packages
\usepackage[toc,page]{appendix}
% \input{Preamble/tikz}
\usepackage{tikz}
\usepackage{pgf}
\usepackage{background}
\usetikzlibrary{calc}
\usepackage{xifthen}
\usepackage{totcount}
\regtotcounter{chapter}

\backgroundsetup%
{   contents={%
        \begin{tikzpicture}[overlay]
            \pgfmathtruncatemacro{\mytotalchapters}{\totvalue{chapter} > 0 ? \totvalue{chapter} : 20}
            \pgfmathsetmacro{\mypaperheight}{\paperheight/28.453}
            \pgfmathsetmacro{\mytop}{-(\thechapter-1)/\mytotalchapters*\mypaperheight}
            \pgfmathsetmacro{\mybottom}{-\thechapter/\mytotalchapters*\mypaperheight}
            \ifcase\thechapter
                \xdef\mycolor{white}
                \or \xdef\mycolor{red}
                \or \xdef\mycolor{orange}
                \or \xdef\mycolor{yellow}
                \or \xdef\mycolor{green}
                \or \xdef\mycolor{blue}
                \or \xdef\mycolor{violet}
%                 \or \xdef\mycolor{magenta}
%                 \or \xdef\mycolor{cyan}
                \else \xdef\mycolor{black}
            \fi
            \ifthenelse{\isodd{\value{page}}}
            {\fill[\mycolor] ($(current page.north east)+(0,\mytop)$) rectangle ($(current page.north east)+(-0.5,\mybottom)$);}
            {\fill[\mycolor] ($(current page.north west)+(0,\mytop)$) rectangle ($(current page.north west)+(0.5,\mybottom)$);}
        \end{tikzpicture}
    },
    scale=1,
    angle=0
}
\begin{document}
 \chapter{First chapter}
 \lipsum[1]
 \appendix
 \chapter{Appendix Chapter}
 \lipsum[1]
\end{document}

Quando eu removo \appendixtudo funciona bem. Alguma idéia de por que isso está acontecendo e como pode ser corrigido?

Responder1

O \appendixcomando define o \value{chapter}to 0e o torna \Alph. Daí você recebe o erro. Em vez de usar o chaptercontador, use outro contador. Aqui eu defini um countere aumentei após cada capítulo usando \xpatchcmd.

\documentclass[11pt,a4paper]{book}
\usepackage{lipsum}
\usepackage{xpatch}
\makeatletter
\xpatchcmd{\chapter}{\thispagestyle{plain}}
                    {\thispagestyle{plain}\stepcounter{counter}}
                    {}{}
\makeatother


\let\MakeUppercase\relax
\usepackage{etex}%Makes able the use of many packages
\usepackage[toc,page]{appendix}
% \input{Preamble/tikz}
\usepackage{tikz}
\usepackage{pgf}
\usepackage{background}
\usetikzlibrary{calc}
\usepackage{xifthen}
\usepackage{totcount}
\regtotcounter{counter}
\newcounter{counter}

\backgroundsetup%
{   contents={%
        \begin{tikzpicture}[overlay]
            \pgfmathtruncatemacro{\mytotalcounter}{\totvalue{counter} > 0 ? \totvalue{counter} : 20}
            \pgfmathsetmacro{\mypaperheight}{\paperheight/28.453}
            \pgfmathsetmacro{\mytop}{-(\thecounter-1)/\mytotalcounter*\mypaperheight}
            \pgfmathsetmacro{\mybottom}{-\thecounter/\mytotalcounter*\mypaperheight}
            \ifcase\thecounter
                \xdef\mycolor{white}
                \or \xdef\mycolor{red}
                \or \xdef\mycolor{orange}
                \or \xdef\mycolor{yellow}
                \or \xdef\mycolor{green}
                \or \xdef\mycolor{blue}
                \or \xdef\mycolor{violet}
%                 \or \xdef\mycolor{magenta}
%                 \or \xdef\mycolor{cyan}
                \else \xdef\mycolor{black}
            \fi
            \ifthenelse{\isodd{\value{page}}}
            {\fill[\mycolor] ($(current page.north east)+(0,\mytop)$) rectangle ($(current page.north east)+(-0.5,\mybottom)$);}
            {\fill[\mycolor] ($(current page.north west)+(0,\mytop)$) rectangle ($(current page.north west)+(0.5,\mybottom)$);}
        \end{tikzpicture}
    },
    scale=1,
    angle=0
}
\begin{document}
 \chapter{First chapter}

 \lipsum[1]
 \chapter{second chapter}
 \lipsum[1]
 \appendix
 \chapter{Appendix Chapter}
 \lipsum[1]
 %\showthe\value{counter}
\end{document}

insira a descrição da imagem aqui

informação relacionada