tufte-book: 캡션의 tikz 참조

tufte-book: 캡션의 tikz 참조

documentclass를 사용하면 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를 만들려고 했습니다.

보시다시피,해결책이 없어요하지만 조금 더 나아갔습니다. 명령 3개 중 2개가 \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}{---}}

완전히 동일하지는 않지만 간단한 상황에서는 갈 수 있는 방법이 될 수 있습니다.

관련 정보