我使用在本节中列举数字
\renewcommand{\thefigure}{\arabic{section}.\arabic{figure}}
但是,当我使用对子图的引用时,得到的不是 1.1 (a),而是 1(a)。我该如何修复它?
工作示例
\documentclass{article}
\usepackage{amsmath}
\usepackage{subfigure}
\usepackage{graphicx}
\usepackage{caption}
\renewcommand{\thefigure}{\arabic{section}.\arabic{figure}}
\makeatletter
\renewcommand{\thesection}{\arabic{section}.}
\renewcommand{\thesubsection}{\thesection\arabic{subsection}.}
\renewcommand{\section}{%
\@startsection
{section}{1}{0mm}
{\baselineskip}
{\baselineskip}
{\fontsize{14}{14}\centering\bfseries\MakeUppercase}%
}
\makeatother
\begin{document}
\section{a}
\begin{figure}[h] \label{fig:1} \centering
\subfigure[]{\label{fig:11}
\includegraphics[width=60mm]{1.png}}%
\subfigure[]{\label{fig:12}
\includegraphics[width=60mm]{2.png}}
\caption{11 and 12}.
\end{figure}
\section{b}
\ref{fig:11}
\end{document}
答案1
不要使用过时的subfigure
软件包,你应该使用subfig
或者subcaption
;这是使用的代码subfig
:
\documentclass{article}
\usepackage{amsmath}
\usepackage{subfig}
\usepackage[demo]{graphicx}
\usepackage{caption}
\renewcommand{\thesection}{\arabic{section}.}
\renewcommand{\thesubsection}{\thesection\arabic{subsection}.}
\renewcommand{\thefigure}{\arabic{section}.\arabic{figure}}
\makeatletter
\renewcommand{\section}{%
\@startsection
{section}{1}{0mm}
{\baselineskip}
{\baselineskip}
{\fontsize{14}{14}\centering\bfseries\MakeUppercase}%
}
%subsection
\renewcommand{\subsection}{%
\@startsection
{subsection}{1}{0mm}
{\baselineskip}
{\baselineskip}
{\fontsize{14}{14}\centering\bfseries\MakeUppercase}%
}
\makeatother
\begin{document}
\section{a}
\begin{figure}[h]
\centering
\subfloat[]{\label{fig:11}%
\includegraphics[width=60mm]{1.png}}\ %
\subfloat[]{\label{fig:12}%
\includegraphics[width=60mm]{2.png}}
\caption{11 and 12}
\label{fig:1}
\end{figure}
\ref{fig:11} or \ref{fig:1}\subref{fig:11}
\end{document}
附注:\thefigure
当新的部分开始时,重新定义不会重置计数器;如果您想重置计数器,可以使用
\@addtoreset{figure}{section}
内部\makeatletter
,,\makeatother
或
\numberwithin{figure}{section}
从amsmath
包裹中,或
\counterwithin{figure}{section}
来自chngcntr
包。还请注意,在浮动环境中,\label
必须始终出现后 \caption
(在您的代码中\label
是在之前\caption
)。
如果由于某种原因您需要坚持使用 subfigure 包,那么您可以重新定义\thesubfigure
、\p@subfigure
和\@thesubfigure
:
\documentclass{article}
\usepackage{amsmath}
\usepackage{subfigure}
\usepackage[demo]{graphicx}
\usepackage{caption}
\renewcommand{\thesection}{\arabic{section}.}
\renewcommand{\thesubsection}{\thesection\arabic{subsection}.}
\renewcommand{\thefigure}{\arabic{section}.\arabic{figure}}
\renewcommand{\thesubfigure}{\thefigure(\alph{subfigure})}
\makeatletter
\renewcommand{\p@subfigure}{}
\renewcommand{\@thesubfigure}{(\alph{subfigure})\hskip\subfiglabelskip}
\makeatother
\makeatletter
\renewcommand{\section}{%
\@startsection
{section}{1}{0mm}
{\baselineskip}
{\baselineskip}
{\fontsize{14}{14}\centering\bfseries\MakeUppercase}%
}
%subsection
\renewcommand{\subsection}{%
\@startsection
{subsection}{1}{0mm}
{\baselineskip}
{\baselineskip}
{\fontsize{14}{14}\centering\bfseries\MakeUppercase}%
}
\makeatother
\begin{document}
\section{a}
\begin{figure}[h]
\centering
\subfigure[]{\label{fig:11}%
\includegraphics[width=60mm]{1.png}}\ %
\subfigure[]{\label{fig:12}%
\includegraphics[width=60mm]{2.png}}
\caption{11 and 12}
\label{fig:1}
\end{figure}
\ref{fig:11}
\end{document}