tufte-book: referencias de tikz en el título

tufte-book: referencias de tikz en el título

Usando la articleclase de documento, el siguiente código funciona como se esperaba.

\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}

ingrese la descripción de la imagen aquí

Sin embargo, cuando se utilizan \documentclass{tufte-book}las referencias no funciona:

ingrese la descripción de la imagen aquí

¿Cómo puedo arreglar esto?

Respuesta1

El problema es que pgfplotshace algunos malabarismos con \label, bajo el supuesto de que significa lo mismo que en el kernel LaTeX, lo cual lamentablemente es falso con 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}

También hice \tikzrefy \tikzcaptionrobusto.

ingrese la descripción de la imagen aquí

Respuesta2

Creo que basaste tu código en la pregunta.aquí. Intenté hacer un MWE más limpio usando código del manual de pgfplots.

Como se puede ver,no tengo una soluciónpero llegué un poco más lejos. 2 de cada 3 \refcomandos funcionaron como se esperaba. En este caso no funcionó si había una línea y marcas.

Quizás esto ayude a otros a profundizar en el tema.

\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}

ingrese la descripción de la imagen aquí ingrese la descripción de la imagen aquí

Respuesta3

No pude hacer funcionar las soluciones anteriores. No estoy exactamente seguro de por qué, pero se me ocurrió una solución pobre al problema anterior, que tal vez también ayude a alguien.

Solo tengo argumentos muy simples y, por lo tanto, finalmente elegí guiones de colores en el texto del título.

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

No es exactamente lo mismo, pero para situaciones simples, puede ser un camino a seguir.

información relacionada