1

I'm trying to create a plot, using pgfplots and the externalize library, which contains a \label to a plot and a corresponding \ref in a legend. I'm also using the frontespizio package to create the first page.

When I run pdflatex the first time, the reference in the plot is not resolved and I get the usual ?? where the \ref should be. After the second run (plus a pdflatex test-frn to create the PDF of the frontispice), that terminates without any error, the label gets placed, but the plot appears with the frontispice (which then appears two times in the output) in the background.

Here's a MWE:

\documentclass{article}
\usepackage{frontespizio}
\usepackage{pgfplots}

\pgfplotsset{%
    compat = 1.14,
}

\usepgfplotslibrary{groupplots}

\usetikzlibrary{external}
\usepgfplotslibrary{external}
\tikzexternalize

\begin{filecontents}{frontespizio-test.tex}
    \begin{frontespizio}
        \Universita{X}
        \Facolta{prova}
        \Corso{x}
        \Titoletto{tesi}
        \Titolo{titolo}
        \Candidato{Io}
        \Relatore{Un altro}
        \Correlatore{Qualcun altro}
        \Annoaccademico{2016-2017}
    \end{frontespizio}
\end{filecontents}

\begin{document}
\input{frontespizio-test}

\begin{figure}
    \centering
    \tikzsetnextfilename{test-figure}
    \begin{tikzpicture}
        \begin{groupplot}[
                group style={
                    group name=prova,
                    rows=2,
                    columns=2
                }
            ]
            \nextgroupplot
            \addplot coordinates {(0,0) (1,1)}; \label{x}
            \nextgroupplot
            \addplot coordinates {(0,0) (1,1)};
            \nextgroupplot
            \addplot coordinates {(0,0) (1,1)};
            \nextgroupplot
            \addplot coordinates {(0,0) (1,1)};
            \addlegendentry{\ref{x}}
        \end{groupplot}
    \end{tikzpicture}
\end{figure}
\end{document}

Unfortunately I really need to externalize the plots, since I'm working with many "heavy" plots, and I need the \label-\ref mechanism to manually create a legend for the groupplot, as in this answer.

Update: the frontispice appears in every plot that is externalised, also those without inner references, without a groupplot environment, even in a drawing of a molecule created with chemfig.

This is how it looks like using the code in egreg's answer: Frontispice on the background of externalised plots

  • 1
    A solution could be based on tex.stackexchange.com/questions/39001/… : perhaps you can move \input{frontespizio-test} into \tikzifexternalizing{}{\input...} such that it is only done for the main file, not for the externalized images – Christian Feuersänger Jun 24 '17 at 9:14
  • Thanks, this works! I have to use mode=list and make and compile many times to get the labels right, but at least I have a correct output. – yellowquark Jun 24 '17 at 12:29
1

I get only one frontispiece, if I use the package according to the documentation.

\documentclass[a4paper]{article}
\usepackage{frontespizio}
\usepackage{pgfplots}

\pgfplotsset{%
    compat = 1.14,
}

\usepgfplotslibrary{groupplots}

\usetikzlibrary{external}
\usepgfplotslibrary{external}
\tikzexternalize


\begin{document}

\begin{frontespizio}
  \Universita{X}
  \Facolta{prova}
  \Corso{x}
  \Titoletto{tesi}
  \Titolo{titolo}
  \Candidato{Io}
  \Relatore{Un altro}
  \Correlatore{Qualcun altro}
  \Annoaccademico{2016-2017}
\end{frontespizio}

\begin{figure}[htp]
    \centering
    \tikzsetnextfilename{test-figure}
    \begin{tikzpicture}
        \begin{groupplot}[
                group style={
                    group name=prova,
                    rows=2,
                    columns=2
                }
            ]
            \nextgroupplot
            \addplot coordinates {(0,0) (1,1)}; \label{x}
            \nextgroupplot
            \addplot coordinates {(0,0) (1,1)};
            \nextgroupplot
            \addplot coordinates {(0,0) (1,1)};
            \nextgroupplot
            \addplot coordinates {(0,0) (1,1)};
            \addlegendentry{\ref{x}}
        \end{groupplot}
    \end{tikzpicture}
\end{figure}
\begin{figure}[htp]
    \centering
    \tikzsetnextfilename{test-figure}
    \begin{tikzpicture}
        \begin{groupplot}[
                group style={
                    group name=prova,
                    rows=2,
                    columns=2
                }
            ]
            \nextgroupplot
            \addplot coordinates {(0,0) (1,1)}; \label{y}
            \nextgroupplot
            \addplot coordinates {(0,0) (1,1)};
            \nextgroupplot
            \addplot coordinates {(0,0) (1,1)};
            \nextgroupplot
            \addplot coordinates {(0,0) (1,1)};
            \addlegendentry{\ref{y}}
        \end{groupplot}
    \end{tikzpicture}
\end{figure}

\end{document}

enter image description here

  • I copied your code verbatim in a new file, but I still see the frontispiece behind the plots. – yellowquark Jun 24 '17 at 11:34
  • @yellowquark I don't. Who wins? – egreg Jul 24 '17 at 12:49

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.