2

I'm creating a custom legend for some pgfplots graph by drawing a node containing a shortstack. Inside the node I'm using \ref{} to insert correct line-styles in front of my text labels.

The problem is that while the lines in the graph are printed with line width=1pt, the lines from \ref are the standard thin size of pgfplots.

This does not happen when using the normal pgfplots legend setup (\addlegendentry), but this is not possible in this graph since the legend either needs to contain extra information or is a common legend for 2 different axis.

So how can I control the line width when using \ref?

Caramdir
  • 89,023
  • 26
  • 255
  • 291

1 Answers1

8

Maybe you specified the line width incorrectly. Here's an example that shows that \ref does indeed produce the correct line width:

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}


\begin{document}

\centering 
\begin{tikzpicture}
\begin{axis}
\addplot +[line width=2pt] {rnd}; \label{graph1}
\addplot {rnd}; \label{graph2}
\end{axis}
\end{tikzpicture}

\ref{graph1} 2pt line; \qquad \ref{graph2} normal line
\end{document}
Jake
  • 232,450
  • 1
    and how do you control the length of the ref-lines? – Ktree Jul 27 '17 at 05:54
  • @Ktree It seems the thickness is controlled automatically. But you may need to compile twice to see the legend changes. One does not have to control it explicitly. – WDC Apr 17 '18 at 14:07