我希望我的 pgfplot 图例能够根据文章中使用的语言自动翻译。因此,我使用翻译包,这是一个非常简单和令人愉快的解决方案。它非常有效,直到我将图例外部化为参考。
在以下 MWE 中,可以观察到该命令在、 中translate
有效,但在 中无效。nameref
legend entries
legend to name
\documentclass{article}
\usepackage[english,french]{babel}
\usepackage{translator}
\languagepath{French}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{tikz,pgfplots}
\usepackage{nameref}
\begin{document}
\providetranslation[to=French]{My section}{Ma section}%
\section{\translate{My section}\label{marker}}
In section \nameref{marker} we defined...
\begin{figure}[!h]
\centering
\begin{tikzpicture}
\providetranslation[to=French]{Zero line}{Ligne zéro}%
\providetranslation[to=French]{Quadratic line}{Ligne quadratique}%
\begin{axis}[ymin=0, ymax=80,legend entries={\translate{Zero line},\translate{Quadratic line}}]
\addplot {x*0};
\addplot {x^2+50};
\end{axis}
\end{tikzpicture}
\caption{Figure with internal legend}
\end{figure}
\begin{figure}[!h]
\centering
\begin{tikzpicture}
\providetranslation[to=French]{Zero line}{Ligne zéro}%
\providetranslation[to=French]{Quadratic line}{Ligne quadratique}%
\begin{axis}[ymin=0, ymax=80,legend entries={\translate{Zero line},\translate{Quadratic line}},legend to name=legend]
\addplot {x*0};
\addplot {x^2+50};
\end{axis}
\end{tikzpicture}
\caption{Figure with external legend}
\ref{legend}\newline
\end{figure}
\end{document}
生产:
有办法解决这个问题吗?
答案1
外部图例会被放入其自己的tikzpicture
环境中,因此在将图例组合在一起时,您的翻译不可用。如果您在 之外提供翻译tikzpicture
,则一切正常:
\documentclass{article}
\usepackage[english,french]{babel}
\usepackage{translator}
\languagepath{French}
\usepackage[utf8]{inputenc}
\usepackage{tikz,pgfplots}
\usepackage{nameref}
\providetranslation[to=French]{Zero line}{Ligne zéro}%
\providetranslation[to=French]{Quadratic line}{Ligne quadratique}%
\begin{document}
\providetranslation[to=French]{My section}{Ma section}%
\section{\translate{My section}\label{marker}}
In section \nameref{marker} we defined...
\begin{figure}[!h]
\centering
\begin{tikzpicture}
\begin{axis}[ymin=0, ymax=80,legend entries={\translate{Zero line},\translate{Quadratic line}},legend to name=legend]
\addplot {x*0};
\addplot {x^2+50};
\end{axis}
\end{tikzpicture}
\caption{Figure with external legend}
\ref{legend}\newline
\end{figure}
\end{document}