我想引用子图。假设我有一个图,它有三个子图。要引用这些子图,我想写图 1(a)-(c)代替图 1a、1b 和 1c。我已粘贴代码和输出供您参考。
\documentclass{article}
\usepackage{graphicx} % Required for inserting images
\usepackage{caption}
\usepackage{subcaption}
\title{}
\author{}
\date{}
\begin{document}
\maketitle
\begin{figure}[ht]
\centering
\begin{subfigure}[b]{0.3\textwidth}
\centering
\includegraphics[width=\textwidth]{Picture1.png}
\caption{}
\label{fig: First figure}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.3\textwidth}
\centering
\includegraphics[width=\textwidth]{Picture2.png}
\caption{}
\label{fig: Second figure}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.3\textwidth}
\centering
\includegraphics[width=\textwidth]{Picture3.png}
\caption{}
\label{fig: Third figure}
\end{subfigure}
\caption{Three figures}
\label{fig: All figures}
\end{figure}
I want to write as Fig. \ref{fig: All figures} (a)-(c) instead of Fig. \ref{fig: First figure}, \ref{fig: Second figure}, and \ref{fig: Third figure}.
\end{document}
答案1
根据本手册第 7 节中的示例subcaption
,您可以例如使用:
\documentclass{article}
\usepackage{mwe}
% The old way:
%\usepackage[labelformat=simple]{subcaption}
%\makeatletter
%\renewcommand*{\thesubfigure}{(\alph{subfigure})}
%\renewcommand*{\p@subfigure}{}
%\makeatother
% The new way:
\usepackage{subcaption}
\labelformat{subfigure}{(#1)}% see ltnews30.pdf
\begin{document}
\begin{figure}[ht]
\centering
\begin{subfigure}[b]{0.3\textwidth}
\centering
\includegraphics[width=\textwidth]{example-image-a}
\caption{}
\label{fig: First figure}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.3\textwidth}
\centering
\includegraphics[width=\textwidth]{example-image-b}
\caption{}
\label{fig: Second figure}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.3\textwidth}
\centering
\includegraphics[width=\textwidth]{example-image-c}
\caption{}
\label{fig: Third figure}
\end{subfigure}
\caption{Three figures}
\label{fig: All figures}
\end{figure}
I want to write as Fig. \ref{fig: All figures} \ref{fig: First
figure}-\ref{fig: Third figure}.
\end{document}
要得到
或者,如果您不想改变的结果\ref{…}
,您可以\subref{…}
按照手册第 7.1 节所示使用subcaption
:
\documentclass{article}
\usepackage{mwe}
\usepackage{subcaption}
\captionsetup{subrefformat=parens}
\begin{document}
\begin{figure}[ht]
\centering
\begin{subfigure}[b]{0.3\textwidth}
\centering
\includegraphics[width=\textwidth]{example-image-a}
\caption{}
\label{fig: First figure}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.3\textwidth}
\centering
\includegraphics[width=\textwidth]{example-image-b}
\caption{}
\label{fig: Second figure}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.3\textwidth}
\centering
\includegraphics[width=\textwidth]{example-image-c}
\caption{}
\label{fig: Third figure}
\end{subfigure}
\caption{Three figures}
\label{fig: All figures}
\end{figure}
I want to write as Fig. \ref{fig: All figures} \subref{fig: First
figure}-\subref{fig: Third figure}.
\end{document}
结果将与上面显示的相同。
另一种选择是使用包cleveref
来自动化范围:
\documentclass{article}
\usepackage{mwe}
\usepackage[labelformat=simple]{subcaption}
\renewcommand*{\thesubfigure}{(\alph{subfigure})}
\captionsetup{subrefformat=parens}
\usepackage[capitalize]{cleveref}
\crefrangelabelformat{subfigure}{#3#1#4--#5(\crefstripprefix{#1}{#2}#6}
\begin{document}
\begin{figure}[ht]
\centering
\begin{subfigure}[b]{0.3\textwidth}
\centering
\includegraphics[width=\textwidth]{example-image-a}
\caption{}
\label{fig: First figure}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.3\textwidth}
\centering
\includegraphics[width=\textwidth]{example-image-b}
\caption{}
\label{fig: Second figure}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.3\textwidth}
\centering
\includegraphics[width=\textwidth]{example-image-c}
\caption{}
\label{fig: Third figure}
\end{subfigure}
\caption{Three figures}
\label{fig: All figures}
\end{figure}
I want to write as \cref{fig: First figure,fig: Second figure,fig: Third figure}.
\end{document}