tufte-book:標題中的 tikz 參考文獻

tufte-book:標題中的 tikz 參考文獻

使用article文件類,以下程式碼可以如預期般運作。

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

在此輸入影像描述

但是,使用\documentclass{tufte-book}引用時將無法運作:

在此輸入影像描述

我怎樣才能解決這個問題?

答案1

問題是,在假設它與 LaTeX 內核中的含義相同的情況下,pgfplots與 進行一些雜耍,不幸的是,這對於 來說是錯誤的。\labeltufte-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}

我也做了\tikzref並且\tikzcaption健壯。

在此輸入影像描述

答案2

我認為你的程式碼是基於這個問題這裡。我嘗試使用 pgfplots 手冊中的程式碼製作一個更清晰的 MWE。

如你看到的,我沒有解決辦法但我更進一步了。三分之二的\ref命令按預期工作。在這種情況下,如果有一條線和標記,它就不起作用。

也許這有助於其他人更深入地研究這個問題。

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

在此輸入影像描述 在此輸入影像描述

答案3

我無法使上述解決方案發揮作用。我不太清楚為什麼,但我想出了一個窮人對上述問題的解決方案,這可能也對某人有幫助。

我只有非常簡單的圖,因此最終在標題文字中使用了彩色破折號。

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

這並不完全相同,但對於簡單的情況,這可能是一種方法。

相關內容