# Alternative to \includegraphics

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}

\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}

\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 401x146 pixels figB.png is 630x128 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.

• Can you make a small compilable example that illustrates your problem? Perhaps it is easier to solve the underlying problem instead of looking for an alternative to \includegraphic. – samcarter_is_at_topanswers.xyz Sep 16 '16 at 23:05
• Welcome! I'm using tikz to include an image in a header ... This sounds like a mistake. (Though it is hard to tell without an example.) You might use TikZ in a header, but it sounds as if you might be using it to create the header. – cfr Sep 16 '16 at 23:31
• Actually, \includegraphics is from the graphicx package and can be used independently of TikZ. – John Kormylo Sep 17 '16 at 3:22
• I suspect your header is using the image in some sort of a savebox, and your code is overwriting the contents of the box. Perhaps just post the code that does the header if you can't make a small example that shows the problem. – Aubrey Blumsohn Sep 17 '16 at 8:07

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}

\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}

\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}

\pagestyle{empty}

\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.

• When you wrote, "perhaps it would be simpler to incorporate it into the page style." I could not find an example of that. I was looking here where the answer suggested this method. I also wonder if there is an advantage to that. – pdb Sep 20 '16 at 17:44
• I should mention that all of my distances are from a graphic designer and measured relative to the page's "north west". So, I'm not hoping for help form LaTeX in laying out the header and footer. – pdb Sep 20 '16 at 17:50
• @pdb Depends on your document, but have you considered flowfram? See, for example, the sample-brochure file in ctan.org/tex-archive/macros/latex/contrib/flowfram/samples. There's also a GUI to help with the layout. – Nicola Talbot Sep 21 '16 at 7:38