我想将我的子图标签格式化为A,乙, ... 在图的标题中使用\protect\subref{...}
。
考虑以下:
\documentclass{article}
\usepackage{graphicx}
\usepackage{subfig}
\usepackage{cleveref}
\renewcommand{\thesubfigure}{\Alph{subfigure}}
\DeclareSubrefFormat{mybold}{\textbf{#2}}
\captionsetup{subrefformat=mybold}
\begin{document}
See \cref{fig:1a}
\begin{figure}
\subfloat{\label{fig:1a}}
\subfloat{\label{fig:1b}}
\centering
\includegraphics[width=.5\textwidth]{example-image}
\caption{
\protect\subref{fig:1a} First sub caption.
\protect\subref{fig:1b} Second sub caption.
And some more text
}
\label{fig:1}
\end{figure}
\end{document}
即尽管
\DeclareSubrefFormat{mybold}{\textbf{#2}}
\captionsetup{subrefformat=mybold}
标签既不加粗,也不无括号。然而,
\renewcommand{\thesubfigure}{\Alph{subfigure}}
确实有效。
发生了什么事?是因为吗\protect
?我该怎么办?
答案1
您需要使用\subref*
粗体显示并使用适当的选项来\captionsetup
:
\documentclass{article}
\usepackage{graphicx}
\usepackage{subfig}
\usepackage{cleveref}
\renewcommand{\thesubfigure}{\Alph{subfigure}}
\DeclareSubrefFormat{mybold}{\textbf{#2}}
\captionsetup[subfloat]{subrefformat=mybold}
\begin{document}
See \cref{fig:1a}
\begin{figure}
\subfloat{\label{fig:1a}}
\subfloat{\label{fig:1b}}
\centering
\includegraphics[width=.5\textwidth]{example-image}
\caption{
\protect\subref*{fig:1a} First sub caption.
\protect\subref*{fig:1b} Second sub caption.
And some more text
}
\label{fig:1}
\end{figure}
\end{document}