0

I am trying to create a document containing:

  • A cover page image (see 1 below this post) set as background using the package eso-pic.
  • Several tikz pictures that I externalize using \tikzexternalize[up to date check={md5}].

Problem: a part of the cover page image is included in the background of the tikz picture.

How can I solve this problem while keeping the externalization?

Following Tom's answer: In my complete document, I use \AddToShipoutPictureBG inside a macro so I had to set \tikzset{external/optimize command away=\mymacro} after the macro definition instead of in the \tikzexternalize command.

% !TeX TXS-program:compile = txs:///lualatex/[--shell-escape]

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{external}
\tikzexternalize[up to date check={md5}]
\usepackage{eso-pic}
\usepackage{graphicx}

\begin{document}
    
    % Add title image across the complete page
    \AddToShipoutPictureBG*{\AtPageLowerLeft{%
            \includegraphics[width=\paperwidth,height=\paperheight]{my_picture.jpg}}}
    \newpage\null\newpage
        
    \tikzsetnextfilename{tikz_picture}
    \begin{tikzpicture}
        \draw[red, thick] (-1,2) -- (2,-4);
        \draw[red, thick] (-1,-1) -- (2,2);
        \filldraw[red] (0,0) circle (2pt) node[anchor=west]{A tikz picture};
    \end{tikzpicture}
        
\end{document}

1 Answer 1

1

You could use the option optimize command away=\AddToShipoutPictureBG when enable \tikzexternalize. Note the package eso-pic must be loaded before the \tikzexternalize command.

% !TeX TXS-program:compile = txs:///lualatex/[--shell-escape]

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{external}
\usepackage{eso-pic} %%load the 'eso-pic' package before '\tikzexternalize', otherwise the command '\AddToShipoutPictureBG' will not be defined.
\tikzexternalize[
up to date check={md5},
optimize command away=\AddToShipoutPictureBG
]
\usepackage{graphicx}

\begin{document}

    % Add title image across the complete page
    \AddToShipoutPictureBG*{\AtPageLowerLeft{%
            \includegraphics[width=\paperwidth,height=\paperheight]{example-image-a}}}
    \newpage\null\newpage
      
 \tikzsetnextfilename{tikz_picture}

    \begin{tikzpicture}
        \draw[red, thick] (-1,2) -- (2,-4);
        \draw[red, thick] (-1,-1) -- (2,2);
        \filldraw[red] (0,0) circle (2pt) node[anchor=west]{A tikz picture};
    \end{tikzpicture}
        
\end{document}

enter image description here

2
  • Works perfectly. In my complete document, I use '\AddToShipoutPictureBG' inside a macro so I had to set '\tikzset{external/optimize command away=\mymacro}' after the macro definition instead of in the '\tikzexternalize' command.
    – AlMa
    Commented Jan 7 at 16:22
  • 1
    @AlMa Great! You could add the solution for your case in the question. It will be benefit for other people facing the similar problems.
    – Tom
    Commented Jan 7 at 16:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .