pgfplot の ylabel で \ref を使用する

pgfplot の ylabel で \ref を使用する

\label2 つの Y 軸を区別するためにとを使用すると、ラベルの残りの部分と一緒に回転させると、\refで描画されたマーク\refが線上になくなります (以下の例を参照)。何かアイデアはありますか?

\documentclass{article}

\usepackage{pgfplots}

\begin{document}
  \begin{tikzpicture}
    \begin{axis}[axis y line*=left, scale only axis,
                 ylabel={estimation 2 \ref{pgf:allsamples}}]
      \addplot[blue,mark=+] table {data2.csv};
      \label{pgf:allsamples}
    \end{axis}
    \begin{axis}[axis y line*=right, scale only axis,
             ylabel={estimation 1 \ref{pgf:swingvotes}}, ylabel near ticks]
      \addplot[red,mark=x] table {data1.csv};
      \label{pgf:swingvotes}
    \end{axis}
  \end{tikzpicture}
\end{document}

ref が期待通りに動作しない

答え1

pgfplotsには確かにバグがあります。\refコマンドは「tikz画像内から呼び出された」かどうかをチェックします。しかし、このチェックは、まあ、tikzpicture 内から呼び出されましたが、tikzpicture はノードを表示するために中断されました。

バグの結果、ラベルが予期せずずれてしまいます。

バグが修正されるまで、次の回避策を使用できます。

\documentclass{article}

\usepackage{pgfplots}

\def\fixcheck{%
    \def\tikzifinpicture##1##2{##2}%
}%

\begin{document}
  \begin{tikzpicture}
    \begin{axis}[axis y line*=left, scale only axis,
                 ylabel={\fixcheck estimation 2 \ref{pgf:allsamples}}]
      \addplot[blue,mark=+] {x+5};
      \label{pgf:allsamples}
    \end{axis}
    \begin{axis}[axis y line*=right, scale only axis,
             ylabel={\fixcheck estimation 1 \ref{pgf:swingvotes}}, ylabel near ticks]
      \addplot[red,mark=x] {x};
      \label{pgf:swingvotes}
    \end{axis}
  \end{tikzpicture}
\end{document}

すべてのラベルに、\fixcheckチェックが「false」を返すだけのマクロを追加します。その場合、\ref一時的な tikzpicture が追加されます。

関連情報