tufte-book: tikz-Referenzen in der Bildunterschrift

tufte-book: tikz-Referenzen in der Bildunterschrift

Unter Verwendung der articleDokumentklasse funktioniert der folgende Code wie erwartet.

\documentclass{article}
\usepackage{lipsum}
\usepackage{caption}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}
\usepgfplotslibrary{external}
% fix problems when tikzexternal is used
\newcommand{\tikzcaption}[1]{\protect\tikzset{external/export next=false}#1}
\newcommand{\tikzref}[1]{\tikzcaption{\ref{#1}}}

\tikzset{pointille/.style={dash pattern = on 2pt off 2pt on 6pt off 2pt}}
\tikzset{points/.style={dash pattern = on 1pt off 1pt}}
\tikzset{tirets/.style={dash pattern = on 5pt off 5pt}}

\begin{document}
\begin{figure}[!ht]
\centering
\captionsetup{width=9.5cm}
\pgfplotsset{every axis plot post/.append style={mark=none,line width=1.5pt}}
\begin{tikzpicture}
\begin{axis}
\addplot[tirets,color=blue]{2*x};\label{p4}
\addplot[pointille,color=green]{0.5*x*x};\label{p5}
\addplot[points,color=red]{-0.125*x*x*x};\label{p6}
\end{axis}
\end{tikzpicture}
\caption{This is a plot about colored curves: $f(x)=2 x$ (\tikzref{p4}),  $f(x)=0.5 x^2$ (\tikzref{p5}), and $f(x)=-0.125 x^3$ (\tikzref{p6})}
\end{figure}
\end{document}

Bildbeschreibung hier eingeben

\documentclass{tufte-book}Bei Verwendung der Referenzen funktioniert es jedoch nicht:

Bildbeschreibung hier eingeben

Wie kann ich das beheben?

Antwort1

Das Problem besteht darin, dass pgfplotsmit jongliert wird \label, in der Annahme, dass es dasselbe bedeutet wie im LaTeX-Kernel, was bei leider nicht der Fall ist tufte-book.

\documentclass{tufte-book}
\usepackage{lipsum}
\usepackage{pgfplots}
\usepackage{etoolbox}

% patch pgfplots so that \label does the original job
% tufte-book saves the original meaning of \label in
% \@tufte@orig@label
\makeatletter
\patchcmd{\pgfplots@environment@opt}{\label}{\@tufte@orig@label}{}{}
\makeatother

\pgfplotsset{compat=1.13}
\usepgfplotslibrary{external}
% fix problems when tikzexternal is used
\DeclareRobustCommand{\tikzcaption}[1]{\tikzset{external/export next=false}#1}
\DeclareRobustCommand{\tikzref}[1]{\tikzcaption{\ref{#1}}}

\tikzset{pointille/.style={dash pattern = on 2pt off 2pt on 6pt off 2pt}}
\tikzset{points/.style={dash pattern = on 1pt off 1pt}}
\tikzset{tirets/.style={dash pattern = on 5pt off 5pt}}

\begin{document}

\begin{figure}[!ht]
\centering
\pgfplotsset{every axis plot post/.append style={mark=none,line width=1.5pt}}
\begin{tikzpicture}
\begin{axis}
\addplot[tirets,color=blue]{2*x};\label{p4}
\addplot[pointille,color=green]{0.5*x*x};\label{p5}
\addplot[points,color=red]{-0.125*x*x*x};\label{p6}
\end{axis}
\end{tikzpicture}

\caption{This is a plot about colored curves: $f(x)=2 x$ (\tikzref{p4}), 
  $f(x)=0.5 x^2$ (\tikzref{p5}), and $f(x)=-0.125 x^3$ (\tikzref{p6})}

\end{figure}
\end{document}

Ich habe es auch gemacht \tikzrefund \tikzcaptionrobust.

Bildbeschreibung hier eingeben

Antwort2

Ich denke, Sie haben Ihren Code auf der Frage basiertHier. Ich habe versucht, mit Code aus dem pgfplots-Handbuch ein saubereres MWE zu erstellen.

Wie du sehen kannst,Ich habe keine Lösungaber ich bin ein Stück weitergekommen. 2 von 3 \refBefehlen funktionierten wie erwartet. In diesem Fall funktionierte es nicht, wenn eine Linie und Markierungen vorhanden waren.

Vielleicht hilft dies anderen, sich eingehender mit dem Thema zu befassen.

\documentclass{tufte-book}
\usepackage{lipsum}
\usepackage{caption}
\usepackage{pgfplots}
\pgfplotsset{compat=1.3}

\begin{document}

\chapter{Without a \texttt{figure} Environment}

% Taken from the pgfplots manuel section 4.9.6 (Legends with \label and \ref)

\begin{tikzpicture}
    \begin{axis}
        \addplot+[only marks,
            samples=15,
            error bars/y dir=both,
            error bars/y fixed=2.5]
            {3*x+2.5*rand};
        \label{pgfplots:label1}
        \addplot+[mark=none] {3*x};
        \label{pgfplots:label2}
        \addplot {4*cos(deg(x))};
        \label{pgfplots:label3}
    \end{axis}
\end{tikzpicture}

Label 1: \ref{pgfplots:label1}; Label 2: \ref{pgfplots:label2}; Label 3: \ref{pgfplots:label3}

\chapter{With a \texttt{figure} Environment}

% Taken from the pgfplots manuel section 4.9.6 (Legends with \label and \ref)

\begin{figure}
\centering
\begin{tikzpicture}
    \begin{axis}
        \addplot+[only marks,
            samples=15,
            error bars/y dir=both,
            error bars/y fixed=2.5]
            {3*x+2.5*rand};
        \label{pgfplots:label1}
        \addplot+[mark=none] {3*x};
        \label{pgfplots:label2}
        \addplot {4*cos(deg(x))};
        \label{pgfplots:label3}
    \end{axis}
\end{tikzpicture}
% Caption
\caption{Label 1: \ref{pgfplots:label1}; Label 2: \ref{pgfplots:label2}; Label 3: \ref{pgfplots:label3}}
\end{figure}

Label 1: \ref{pgfplots:label1}; Label 2: \ref{pgfplots:label2}; Label 3: \ref{pgfplots:label3}

\end{document}

Bildbeschreibung hier eingeben Bildbeschreibung hier eingeben

Antwort3

Ich konnte die oben genannten Lösungen nicht zum Laufen bringen. Ich bin mir nicht ganz sicher, warum, aber ich habe eine einfache Lösung für das obige Problem gefunden, die vielleicht auch jemandem hilft.

Ich habe nur sehr einfache Plots und habe mich deshalb letztendlich für farbige Geviertstriche im Beschriftungstext entschieden.

\caption{Ref to a plot \textcolor{blue}{---}}

Es ist nicht ganz dasselbe, aber für einfache Situationen kann es ein möglicher Weg sein.

verwandte Informationen