使用 subfigure 包引用子图

使用 subfigure 包引用子图

我对 LaTeX 还不熟悉,遇到了一点小问题。我正在使用软件包subfigure并尝试使用 引用我的子图\label{key},但这样做时出现了“(??)”。

代码如下:

\documentclass[11pt,twocolumn]{article}
\usepackage[spanish]{babel}
\usepackage{graphicx, multicol, latexsym, amsmath, amssymb}
\usepackage{blindtext}
\usepackage{subfigure}
\usepackage{caption}
\usepackage{capt-of}
\usepackage{tabu}
\usepackage{hyperref}
\usepackage{booktabs}% for better rules in the table
\usepackage{anysize} % Soporte para el comando \marginsize
\setlength\parindent{0pt}
\spanishdecimal{.}


%===================================================  


\begin{document}


\begingroup
\centering
\begin{figure}[htbp]
\centering
\subfigure[first caption.]{\includegraphics[width=0.2\textwidth]{fig1a}}\label{fig:1a}
\subfigure[second caption.] {\includegraphics[width=0.185\textwidth]{fig1b}}\label{fig:1b}
\subfigure[third caption.]{\includegraphics[width=0.2\textwidth]{fig1c}}\label{fig:1c}
\caption{General caption.} \label{fig:1}
\end{figure}

\endgroup

Using \ref{fig:1a} appears ``(??)'', but using \ref{fig1}, appears ``(1)''.

\end{document}

如果有人能帮助我,我将不胜感激。

来自南美的问候。

答案1

这是subcaption解决方案,必须在自己的盒子或环境中使用(有点繁琐)否则,一切都像正常工作一样。

的可选参数\subcaption,即括在 中的参数,[...]将出现在图片列表 (Lof) 中。如果没有给出这样的选项,则强制参数的值{...}将归于 LoF。

若去掉\begingroup...\endgroup对,则自已\begin{figure}...\end{figure}已建立分组。

\documentclass[11pt,twocolumn]{article}
\usepackage[spanish]{babel}
\usepackage[demo]{graphicx}
\usepackage{multicol, latexsym, amsmath, amssymb}
\usepackage{blindtext}
\usepackage{subcaption}
\usepackage{caption}
\usepackage{tabu}
   \usepackage{booktabs}% for better rules in the table
\usepackage{anysize} % Soporte para el comando \marginsize
\usepackage{hyperref}
\setlength\parindent{0pt}
\spanishdecimal{.}


%===================================================  


\begin{document}


\begin{figure}[htbp]
\centering
\begin{minipage}{0.3\textwidth}
  \centering
\includegraphics[width=0.2\textwidth]{fig1a}
\subcaption[first caption.]{First}\label{fig:1a}
\end{minipage}%
\begin{minipage}{0.3\textwidth}
  \centering
\includegraphics[width=0.185\textwidth]{fig1b}
\subcaption[second caption.]{Second}\label{fig:1b}
\end{minipage}%
\begin{minipage}{0.3\textwidth}
  \centering
\includegraphics[width=0.185\textwidth]{fig1c}
\subcaption[third caption.]{Third}\label{fig:1c}
\end{minipage}

\caption{General caption.} \label{fig:1}
\end{figure}

Using \verb|\ref{fig:1a}| now appears as ``\ref{fig:1a}'' and using \verb|\ref{fig:1}|, appears ``\ref{fig:1}''.

\end{document}

enter image description here

答案2

不要使用subfigure,它已经过时15年左右了。

使用subfig及其\subfloat命令来替代过时的包,标签应该放在可选参数中(子标题的参数)。

\documentclass[11pt,twocolumn]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc} % ensure your document is UTF-8
\usepackage[spanish]{babel}

\usepackage[demo]{graphicx} % demo option just for testing
\usepackage{subfig}
\usepackage{caption}

\begin{document}

\begin{figure}[htbp]
\centering
\subfloat[first caption.\label{fig:1a}]{\includegraphics[width=0.2\textwidth]{fig1a}}\hfill
\subfloat[second caption.\label{fig:1b}] {\includegraphics[width=0.185\textwidth]{fig1b}}\hfill
\subfloat[third caption.\label{fig:1c}]{\includegraphics[width=0.2\textwidth]{fig1c}}
\caption{General caption.} \label{fig:1}
\end{figure}

Subfloat reference: \ref{fig:1a}

Figure reference: \ref{fig:1}

\end{document}

注意,\begingroup\centering...\endgroup图的周围是错误的。

enter image description here

但是,您可能想要使用subcaption,它与 配合使用效果也更好hyperref

\documentclass[11pt,twocolumn]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc} % ensure your document is UTF-8
\usepackage[spanish]{babel}

\usepackage[demo]{graphicx} % demo option just for testing
\usepackage{caption}
\usepackage{subcaption}

\begin{document}

\begin{figure}[htbp]
\centering
\setlength{\lineskip}{\medskipamount}
\subcaptionbox{first caption.\label{fig:1a}}{\includegraphics[width=0.2\textwidth]{fig1a}}\hfill
\subcaptionbox{second caption.\label{fig:1b}}{\includegraphics[width=0.185\textwidth]{fig1b}}\hfill
\subcaptionbox{third caption.\label{fig:1c}}{\includegraphics[width=0.2\textwidth]{fig1c}}
\caption{General caption.} \label{fig:1}
\end{figure}

Subfloat reference: \ref{fig:1a} 

Figure reference: \ref{fig:1}

\end{document}

答案3

对于任何必须使用包子图的人来说,可以通过将标签移到括号中来解决此问题,如下所示:

\subfigure[first caption.]{\includegraphics[width=0.2\textwidth]{fig1a}\label{fig:1a}}

相关内容