[Tex/LaTex] Alternative to \includegraphics

tikz-pgf

I'm using TikZ to include an image in a header and have found that if an image rolls onto the next page then TikZ includes it in place of the header on the next page (basically, TikZ appears to just grab the wrong image). Are there alternatives to \includegraphics that I could use in hopes that I don't can hack my way around this?

minimal example:

\documentclass[12pt, letterpaper]{article}
\usepackage{graphicx}
\usepackage{lipsum}
\usepackage{tikz}
\usepackage{tikzpagenodes}
\usepackage{atbegshi}

\usetikzlibrary{calc}

\newcommand\HeadAndFoot{
\begin{tikzpicture}[overlay,remember picture]
% logo
\node[anchor=north west, xshift=250, yshift=-20] (logo) at (current page.north west) {\includegraphics[width=100pt]{figA}};
\end{tikzpicture}
}


\pagestyle{empty}
\AtBeginShipout{\HeadAndFoot}

\begin{document}

\includegraphics[width=\textwidth]{figB}

\includegraphics[width=\textwidth]{figB}

\includegraphics[width=\textwidth]{figB}

\includegraphics[width=\textwidth]{figB}

\includegraphics[width=\textwidth]{figB}

\includegraphics[width=\textwidth]{figB}

\includegraphics[width=\textwidth]{figB}

\includegraphics[width=\textwidth]{figB}

\includegraphics[width=\textwidth]{figB}


\end{document} 

figA.png is 401×146 pixels
figB.png is 630×128 pixels

When I do this I get a title page with no logo (expected), a second page with "figB" in the logo splot (surprise) and a third page with "figA" in the logo spot.

Best Answer

Since you're using tikz, then you also have the pgf basic layer commands, so instead of using \includegraphics you can declare an image with \pgfdeclareimage and later use it with \pgfuseimage. (This actually makes more sense here given that you're repeatedly using the same image with the same scaling applied.)

\documentclass[12pt, letterpaper]{article}
\usepackage{lipsum}
\usepackage{tikz}
\usepackage{tikzpagenodes}
\usepackage{atbegshi}

\usetikzlibrary{calc}

\pgfdeclareimage[width=100pt]{A}{figA}
\pgfdeclareimage[width=\textwidth]{B}{figB}

\newcommand\HeadAndFoot{
\begin{tikzpicture}[overlay,remember picture]
% logo
\node[anchor=north west, xshift=250, yshift=-20] (logo) at (current page.north west) 
{\pgfuseimage{A}};
\end{tikzpicture}
}


\pagestyle{empty}
\AtBeginShipout{\HeadAndFoot}

\begin{document}

\pgfuseimage{B}

\pgfuseimage{B}

\pgfuseimage{B}

\pgfuseimage{B}

\pgfuseimage{B}

\pgfuseimage{B}

\pgfuseimage{B}

\pgfuseimage{B}

\pgfuseimage{B}

\end{document} 

This uses the figA image at the top of the second and third pages.

As for what's causing the problem, at first I thought it might have been an interaction with the remember picture option, but the issue can be reproduced without it:

\documentclass[12pt, letterpaper]{article}
\usepackage[draft]{graphicx}
\usepackage{atbegshi}

\newcommand\HeadAndFoot{\includegraphics[width=100pt]{figA}}


\pagestyle{empty}
\AtBeginShipout{\HeadAndFoot}

\begin{document}

\includegraphics[width=\textwidth]{figB}

\includegraphics[width=\textwidth]{figB}

\includegraphics[width=\textwidth]{figB}

\includegraphics[width=\textwidth]{figB}

\includegraphics[width=\textwidth]{figB}

\includegraphics[width=\textwidth]{figB}

\includegraphics[width=\textwidth]{figB}

\includegraphics[width=\textwidth]{figB}

\includegraphics[width=\textwidth]{figB}

\includegraphics[width=\textwidth]{figB}

\includegraphics[width=\textwidth]{figB}

\includegraphics[width=\textwidth]{figB}

\includegraphics[width=\textwidth]{figB}

\includegraphics[width=\textwidth]{figB}

\includegraphics[width=\textwidth]{figB}

\end{document} 

So I'm guessing it's something to do with the shipout stuff. Are you using the image as a watermark or a header? If it's a header, perhaps it would be simpler to incorporate it into the page style.