TikZ-PGF – Modifications of PDFs Included in TikZ Environments

tikz-pgf

I have a PDF generated with the TikZ code:

\documentclass[tikz]{standalone}

\begin{document}
    \begin{tikzpicture}
        \draw [line width=10pt] (0,0)--(2,2)--(4,1)--(6,3);
    \end{tikzpicture}
\end{document}

The output PDF is (the file name is file01.pdf):

enter image description here

If I insert this PDF into another TikZ environment with \includegraphics in another file using the following code (please note the [line join=round] option):

\documentclass[tikz]{standalone}

\begin{document}
    \begin{tikzpicture} [line join=round]
        \node (file1) at (0,0) {\includegraphics[]{file01.pdf}};
    \end{tikzpicture}
\end{document}

and the output PDF is:

enter image description here

How is this possible? How can TikZ environment change the included PDF contents in the final output? I have tried using color and line width options as well, but they had no effect on the final output.

Best Answer

TikZ (or rather pgf) resets some aspects of the drawing state at the start of a tikzpicture. This includes the colour and line width, but not the line-joining approach. PDFs do not 'reset' these values automatically when included inside other PDFs, and so the 'child' PDF inherits whatever is set in the 'parent'. As such, if you change the line-joining setting, this will show up in any included PDF that does not explicitly set it. The same would be true for colour or line width in the abstract, but the TikZ reset means that effectively the 'child' is insulated from any change in the 'parent'.


This general point was discussed in https://github.com/pgf-tikz/pgf/issues/870. One could apply

\tikzset{
    every picture/.style={%
        execute at begin picture={%
            \pgfsetbuttcap%
            \pgfsetmiterjoin%
            \pgfsetmiterlimit{10}%
            \pgfsetdash{}{0pt}%
        }
    }
}

to force appropriate defaults.