1

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

NOTE: I asked this question here before but cannot access the login to edit it with a MWE (I thought I was logged in, first post on this part of SE). An edit to add a MWE was rejected. A MWE would also not be an "answer" I don't know how to proceed but to repost with an account I have access to.

1
  • Thanks for the heads up. Looks like it will take a bit because the automated system would only let me remove the one i can log into. – pdb Sep 19 '16 at 16:45
1

It isn't clear why you aren't just using the standard latex header mechanism nor quite where tikz is getting confused, but saving the image in a box seems to get things back on track

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

\usetikzlibrary{calc}
\newbox\mybox
\sbox\mybox{\includegraphics[width=100pt]{figA}}
\newcommand\HeadAndFoot{
\begin{tikzpicture}[overlay,remember picture]
% logo
\node[anchor=north west, xshift=250, yshift=-20] (logo) at (current page.north west) {\usebox{\mybox}};
\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} 
6
  • I've tested with eso-pic without TikZ (\AddToShipoutPicture{\put(0,0){\parbox[b][100pt]{100pt}{ \vfill\centering\includegraphics[width=100pt]{figA}\vfill}}}) and the result also shows figA instead of figB. Is it the same problem? – Ignasi Sep 19 '16 at 19:13
  • @Ignasi no idea:-) but why not just put the figure in a heading, you are using \pagestyle{empty} so disabling all latex's standard heading code, – David Carlisle Sep 19 '16 at 19:19
  • This is a minimal working example. There is a lot of other TikZ in the non-minimal case I'm using. I also wanted to be able to place the logo in an exact spot. I didn't see how to do that with a standard header. – pdb Sep 19 '16 at 20:26
  • To more fully answer why I'm using TikZ, I'm doing something similar to this but with an image in there too. – pdb Sep 19 '16 at 20:42
  • @pdb I can see why use tikz to draw the fancy border and text but I'd just add that tikz as the content of a standard header rather then using some overlay code to add it to a page without head or foot. – David Carlisle Sep 19 '16 at 21:45

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.