我创建了一个自定义浮动环境,但是我所使用的标签的翻译cleveref
不起作用:
\cref@addlanguagedefs{brazilian}{%
\AtBeginDocument{%
\Crefname@preamble{frime}{quadro}{quadros}
\Crefname@preamble{frime}{Quadro}{Quadros}
}
}
figure
一切都与标准“对象”(例如和)配合良好,lstlisting
如下所示:
如何正确添加brazilian
基于 cleveref 的 -type 浮点数交叉引用所使用的标签的翻译frime
?
\documentclass[brazilian,12pt]{memoir}
\usepackage{caption}
\usepackage{newfloat}
\usepackage{graphicx}
\usepackage{listings}
\usepackage[english,main=brazil]{babel}
\usepackage{hyperref}
\usepackage[brazilian]{cleveref}
\def\frimesname{Frame}
\def\listoffrimesname{List of Frames}
\DeclareFloatingEnvironment[fileext=loq,placement={!hbtp},name=\frimesname,
within=chapter,listname=\listoffrimesname]{frime}
\crefname{frime}{frame}{frames}
\Crefname{frime}{Frame}{Frames}
\makeatletter
\addto\captionsbrazil{\renewcommand{\frimesname}{Quadro}}
\addto\captionsbrazil{\renewcommand{\listoffrimesname}{Lista de Quadros}}
\cref@addlanguagedefs{brazilian}{%
\AtBeginDocument{%
\Crefname@preamble{frime}{quadro}{quadros}
\Crefname@preamble{frime}{Quadro}{Quadros}
}
}
\makeatother
\begin{document}
Cref figure \Cref{figuree}
autoref figure \autoref{figuree}
Cref frame \Cref{framee}
autoref frame \autoref{framee}
Cref listing \Cref{listingg}
autoref listing \autoref{listingg}
\begin{figure}[h]
\caption{Opis}
\label{figuree}
\includegraphics{latex.png}
\end{figure}
\begin{frime}[h]
\caption{Stuff.}
\label{framee}
Contents.
\end{frime}
\begin{lstlisting}[caption={Think},label={listingg}]
# If the body of the namespace is longer than this
# number, it won't be indented. Requires
\end{lstlisting}
\end{document}
答案1
由于您使用babel
选项english
和加载包main=brazil
,但cleveref
使用选项加载包brazilian
,我建议您替换
\makeatletter
\addto\captionsbrazil{\renewcommand{\frimesname}{Quadro}}
\addto\captionsbrazil{\renewcommand{\listoffrimesname}{Lista de Quadros}}
\cref@addlanguagedefs{brazilian}{%
\AtBeginDocument{%
\Crefname@preamble{frime}{quadro}{quadros}
\Crefname@preamble{frime}{Quadro}{Quadros}
}
}
\makeatother
和
\addto\captionsbrazil{%
\renewcommand{\frimesname}{Quadro}
\renewcommand{\listoffrimesname}{Lista de Quadros}
\crefname{frime}{quadro}{quadros}
\Crefname{frime}{Quadro}{Quadros}
}
完整的 MWE:
\documentclass[brazilian,12pt,demo]{memoir} % omit 'demo' option in real document
\usepackage{caption}
\usepackage{newfloat}
\usepackage{graphicx}
\usepackage{listings}
\usepackage[english,main=brazil]{babel}
\usepackage[colorlinks]{hyperref}
\usepackage[brazilian]{cleveref}
\def\frimesname{Frame}
\def\listoffrimesname{List of Frames}
\DeclareFloatingEnvironment[fileext=loq,placement={!hbtp},name=\frimesname,
within=chapter,listname=\listoffrimesname]{frime}
\crefname{frime}{frame}{frames}
\Crefname{frime}{Frame}{Frames}
%% new:
\addto\captionsbrazil{%
\renewcommand{\frimesname}{Quadro}
\renewcommand{\listoffrimesname}{Lista de Quadros}
\crefname{frime}{quadro}{quadros}
\Crefname{frime}{Quadro}{Quadros}
\def\lstlistingautorefname{Listagem} % optional
}
\begin{document}
\setcounter{chapter}{2} % just for this example
Cref figure: \Cref{figuree}
autoref figure: \autoref{figuree}
Cref frame: \Cref{framee}
autoref frame: \autoref{framee}
Cref listing: \Cref{listingg}
autoref listing: \autoref{listingg}
\listoffrimes
\bigskip\hrule
\begin{figure}[h]
\centering
\caption{Opis}
\label{figuree}
\includegraphics{latex.png}
\end{figure}
\begin{frime}[h]
\centering
\caption{Stuff.}
\label{framee}
Contents.
\end{frime}
\begin{lstlisting}[caption={Think},label={listingg}]
# If the body of the namespace is longer than this
# number, it won't be indented. Requires ...
\end{lstlisting}
\end{document}