我目前正在尝试在 PGFPlot 的标签中使用词汇表条目。例如ylabel={$\gls{F}_h\ in\ \glsunit{F}}
。
我按照如何在 siunitx 命令中使用词汇表条目?。在文本中,此功能运行良好,但在 PGFPlot 中则不行。在那里,符号仅显示为???
。
更多信息:我正在使用 tikz externalize 绘制图表并使用 bib 文件和 bib2gls 绘制符号。
有没有办法解决 PGFPlot 里面的符号?
简化的示例:
\begin{filecontents*}{symbols.bib}
@entry{F,
name={\ensuremath{F}},
description={Force},
unit={\si{\newton}}
}
@entry{s,
name={\ensuremath{s}},
description={Normalised Distance},
unit={}
}
\end{filecontents*}
\documentclass{article}
\usepackage[british]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
%\usepackage[colorlinks=true, linkcolor=black, citecolor=blue, urlcolor=blue]{hyperref}
\usepackage{siunitx}
\usepackage[record, abbreviations, nonumberlist]{glossaries-extra}
\setabbreviationstyle{long-short}
\newglossary[slg]{symbols}{syi}{syg}{Symbols}
\glsaddkey{unit}{\glsentrytext{\glslabel}}{\glsentryunit}{\GLsentryunit}{\glsunit}{\Glsunit}{\GLSunit}
\glssetnoexpandfield{unit}
\newglossarystyle{symbunitlong}{%
\setglossarystyle{long3col}% base this style on the list style
\renewenvironment{theglossary}{% Change the table type --> 3 columns
\begin{longtable}{lp{\glsdescwidth}>{\centering\arraybackslash}p{2cm}}}%
{\end{longtable}}%
%
\renewcommand*{\glossaryheader}{% Change the table header
\bfseries Sign & \bfseries Description & \bfseries Unit \\
\hline
\endhead%
}
\renewcommand*{\glossentry}[2]{% Change the displayed items
\glstarget{##1}{\glossentryname{##1}} %
& \glossentrydesc{##1}% Description
& \glsunit{##1} \tabularnewline
}
}
\GlsXtrLoadResources[src={symbols}, type={symbols}]
\usepackage{pgfplots}
\usepgfplotslibrary{external}
\pgfplotsset{compat=1.16}
% \tikzexternalize[
% mode=list and make,
%% force remake,
% ]
\begin{document}
\printunsrtglossary[type=symbols, style=symbunitlong]
Just a test with \gls{s} and \gls{F} in \glsunit{F}. \\
%
\begin{tikzpicture}
\begin{axis}[
xlabel={\gls{s}},
ylabel={$\gls{F}\ in\ \glsunit{F}$},
]
\addplot[color=red,mark=x] coordinates {
(2,-2.8559703)
(3,-3.5301677)
(4,-4.3050655)
(5,-5.1413136)
(6,-6.0322865)
(7,-6.9675052)
(8,-7.9377747)
};
\end{axis}
\end{tikzpicture}
\end{document}