在脚注中缩放 tikz 引用

在脚注中缩放 tikz 引用

使用\reftikz/pgfplots 制作器在普通文本中工作正常,但它似乎不能随文本大小缩放,例如标记是在脚注中大写,如以下 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}

在此处输入图片描述

我怎样才能根据字体大小自动缩放 tikz ref?

答案1

首先,您需要找出 的大小\ref(以字体相关单位表示),例如ex,或者至少您希望它显示的大小。然后使用\resizebox将其缩放到该大小。(graphicx加载了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}

相关内容