4

Using a \ref to a tikz/pgfplots maker works fine in normal text, but it seems not to scale with the text size e.g. the marker is too large in a footnote as in the following MWE

\documentclass[14pt]{article}
\usepackage{pgfplots}

\pgfplotsset{compat=1.13}
\usepgfplotslibrary{external}

% these commands take care if `externalize` is used
\DeclareRobustCommand{\tikzcaption}[1]{\tikzset{external/export next=false}#1}
\DeclareRobustCommand{\tikzref}[1]{\tikzcaption{\ref{#1}}}

\begin{document}
\begin{figure}[!ht]
\centering
\begin{tikzpicture}
\begin{axis}
\addplot[only marks, scatter] table[meta=label] {
x y label
0.1 0.15 a
0.45 0.27 c
0.02 0.17 a
0.06 0.1 a
0.9 0.5 b
0.5 0.3 c
0.85 0.52 b
0.12 0.05 a
0.73 0.45 b
0.53 0.25 c
0.76 0.5 b
0.55 0.32 c
}; \label{data}
\end{axis}
\end{tikzpicture}
\end{figure}

\begin{description}
\item[normal:] Lorem (\tikzref{data}) ipsum dolor sit amet.
\item[tiny:] {\tiny Lorem (\tikzref{data}) ipsum dolor sit amet.}
\end{description}

\footnote{Lorem (\tikzref{data}) ipsum dolor sit amet.}

\end{document}

enter image description here

How can I automatically scale the tikz ref with the font size?

1 Answer 1

2

First you need to find out how large the \ref is in font dependent units like ex, or at least how large you would like it to appear. Then use \resizebox to scale it to that size. (graphicx is loaded with tikz.)

\documentclass[14pt]{article}
\usepackage{pgfplots}

\pgfplotsset{compat=1.13}
\usepgfplotslibrary{external}

% these commands take care if `externalize` is used
\DeclareRobustCommand{\tikzcaption}[1]{\tikzset{external/export next=false}#1}
\DeclareRobustCommand{\tikzref}[1]{\tikzcaption{\resizebox{!}{\refsize}{\ref{#1}}}}

\begin{document}
\begin{figure}[!ht]
\centering
\begin{tikzpicture}
\begin{axis}
\addplot[only marks, scatter] table[meta=label] {
x y label
0.1 0.15 a
0.45 0.27 c
0.02 0.17 a
0.06 0.1 a
0.9 0.5 b
0.5 0.3 c
0.85 0.52 b
0.12 0.05 a
0.73 0.45 b
0.53 0.25 c
0.76 0.5 b
0.55 0.32 c
}; \label{data}
\end{axis}
\end{tikzpicture}
\end{figure}

\bgroup% compute size of \ref in ex
\sbox0{\ref{data}}%
\pgfmathparse{\ht0/1ex}%
\xdef\refsize{\pgfmathresult ex}%
\egroup

\begin{description}
\item[normal:] Lorem (\tikzref{data}) ipsum dolor sit amet.
\item[tiny:] {\tiny Lorem (\tikzref{data}) ipsum dolor sit amet.}
\end{description}

\footnote{Lorem (\tikzref{data}) ipsum dolor sit amet.}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.