[Tex/LaTex] Image on top specified page

graphicspage-breaking

How can i place an image on the top of the specified page. For example odd pages will be filled by image, even with text. Or, i just want to make sure that (lua)latex will place images on page 2,3,6?

Similar problem was discussed here: How to include a picture over two pages, left part on left side, right on right (for books)?

Best Answer

Here is a version of a solution to How do I add an image in the upper, left-hand corner using TikZ and graphicx adapted to only add the specified logo on pages 2,3, and 6. It uses the [some] option to the background package.

To change the pages on which the graphic is placed, you simply need to change the values in the definition of \ListOfPagesWithLogo. With that macro set as:

\newcommand*{\ListOfPagesWithLogo}{2,3,6}

one obtains the logo on pages 2, 3, and 6:

enter image description here

Notes:

  • I used the xstring package for numerical comparisons as I like that syntax but this can be adapted to not require that.
  • This version below places a tikz picture, but you can un-commented the \SetBgContents line if you wish to include an external graphic.
  • Two compile runs are required, the first to obtain the coordinates, the second to do the actual drawing.

Code:

% Modified version of https://tex.stackexchange.com/questions/38751/how-do-i-add-an-image-in-the-upper-left-hand-corner-using-tikz-and-graphicx/38754#38754
\documentclass{book}
\usepackage[demo]{graphicx}
\usepackage[some]{background}

\usepackage{lipsum}
\usepackage{showframe}
\usepackage{tikz}
\usepackage{xstring}

\newcommand{\MyGraphicLogo}{% For imported graphic logo
\begin{tikzpicture}[remember picture,overlay,yshift=-2cm, xshift=2cm]
  \node at (0,0) {\includegraphics[width=2cm,height=2cm]{foo}};
 \end{tikzpicture}
}

\newcommand{\MyTikzLogo}{% For a logo drawn with TikZ
\begin{tikzpicture}[remember picture,overlay,yshift=-1cm, xshift=1cm]
    \draw [cyan,fill=yellow] (0cm,0cm) 
        -- (2cm,  0cm) 
        -- (2cm, -2cm)
        -- (0cm, -2cm)
        -- cycle;
 \end{tikzpicture}
}

%\SetBgContents{\MyGraphicLogo}% Select included image
\SetBgContents{\MyTikzLogo}% Select tikz picture

\SetBgPosition{current page.north west}% Select location
\SetBgOpacity{1.0}% Select opacity
\SetBgAngle{0.0}% Select roation of logo
\SetBgScale{1.0}% Select scale factor of logo

\newcommand*{\ListOfPagesWithLogo}{2,3,6}%

\makeatletter
\newcommand*{\AddLogoIfCurrentPageIsOnList}{%
    \foreach \LogoPage in \ListOfPagesWithLogo {%
        \IfEq{\arabic{page}}{\LogoPage}{%
            \bg@material%
            \breakforeach%
        }{}%
    }%
}%
\makeatother
\AddEverypageHook{\AddLogoIfCurrentPageIsOnList}%


\begin{document}
\section*{Lorem Ipsum}
\lipsum[1-40]
\end{document}
Related Question