0

I'm producing a latex document through sphinx latex templates. This means I cannot (unless with hacking) edit the latex contents after \begin{document}. I am able to set the background, and even able to differentiate it based on the page numbering with this command

\backgroundsetup{
        contents={
            \ifnum\value{page}=1
                \includegraphics{/utils/tmpl/guide/common/first_page}
            \else 
                \includegraphics{/utils/tmpl/guide/common/background}
            \fi
        }, scale=0.5, opacity=1, angle=0}

My problem is that \ifnum\value{page}=1 is evaluated as true multiple times, first on the front page, than on other pages that apparently reset the page counter (specifically, in the ToC page and in the very first chapter.

I believe that this is caused by the fact that the first page has no page number, the ToC has roman numbering and the first chapter resets the counting to arabic. This causes the value of the counter page to be reset and restart from 1, which is the condition to set the frontpage background.

I don't mind if all pages have same numbering and title page has the page written. I just need the frontpage bg to not appear elsewhere

1

With the help of an extra boolean \iffirstpage,

\documentclass{article}
\usepackage{background}

\newif\iffirstpage
\firstpagetrue

\backgroundsetup{
    contents={%
        \iffirstpage
            \includegraphics{example-image-a}%
            \global\firstpagefalse
        \else 
            \includegraphics{example-image-b}%
        \fi
    }, 
    scale=0.5, opacity=1, angle=0
}

\begin{document}
a \newpage % background image is example-image-a
b \newpage % example-image-b

\pagenumbering{roman}
c \newpage % example-image-b
d          % example-image-b
\end{document}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.