如果我将 cleverref 与 subcaption 和 minted 结合起来,那么\cref{lst:subfigure}
解析为“?? 1a”,而它应该是“listing 1a”。我该如何修复这个问题?
最小的非工作示例
\documentclass{book}
\usepackage[newfloat=true]{minted}
\usepackage{subcaption}
\usepackage{caption}
\usepackage{cleveref}
\begin{document}
\begin{listing}
\begin{subfigure}{.49\textwidth}
\begin{minted}{cpp}
void foo() {};
\end{minted}
\caption{Left figure caption}
\label{lst:foo}
\end{subfigure}
\begin{subfigure}{.49\textwidth}
\begin{minted}{cpp}
void bar() {};
\end{minted}
\caption{Right figure caption}
\label{lst:bar}
\end{subfigure}
\caption{Overall Caption}
\label{lst:foo-bar}
\end{listing}
\begin{itemize}
\item Overall: \cref{lst:foo-bar}
\item Foo: \cref{lst:foo}
\item Bar: \cref{lst:bar}
\end{itemize}
\end{document}
答案1
你得到
LaTeX Warning: cref reference format for label type `sublisting' undefined on input line 35.
LaTeX Warning: cref reference format for label type `sublisting' undefined on input line 36.
教cleveref
你想教的内容:
\documentclass{book}
\usepackage[newfloat=true]{minted}
\usepackage{subcaption}
%\usepackage{caption}
\usepackage{cleveref}
\crefname{sublisting}{sublisting}{sublistings}
\Crefname{sublisting}{Sublisting}{Sublistings}
\begin{document}
\begin{listing}
\begin{subfigure}{.49\textwidth}
\begin{minted}{cpp}
void foo() {};
\end{minted}
\caption{Left figure caption}
\label{lst:foo}
\end{subfigure}
\begin{subfigure}{.49\textwidth}
\begin{minted}{cpp}
void bar() {};
\end{minted}
\caption{Right figure caption}
\label{lst:bar}
\end{subfigure}
\caption{Overall Caption}
\label{lst:foo-bar}
\end{listing}
\begin{itemize}
\item Overall: \cref{lst:foo-bar}
\item Foo: \cref{lst:foo}
\item Bar: \cref{lst:bar}
\end{itemize}
\end{document}
你可能想要
\crefname{sublisting}{listing}{listings}
\Crefname{sublisting}{Listing}{Listings}
或者
\crefname{sublisting}{Listing}{Listings}
如果您总是想要大写,请自行选择。