我的图在部分内进行了编号。我想在图片标题中使用破折号而不是点(例如,图 1-1-3、图 2-7-1),并且不更改部分标题的样式(即保留 、 、 这样的样式1.1
)1.2
。2.3
以下方法失败。如果能帮助我解决此问题,我将不胜感激。
\documentclass{book}
\usepackage{amsmath}
\usepackage{tikz}
\usepackage{caption}
\renewcommand\thefigure{\thesection-\arabic{figure}}
\numberwithin{figure}{section}
\begin{document}
\chapter{}
\section{}
\section{}
The following caption should be Figure 1-2-1.
\begin{center}
\begin{tikzpicture}
\end{tikzpicture}
\captionof{figure}{}
\end{center}
\section{}
The following caption should be Figure 1-3-1.
\begin{center}
\begin{tikzpicture}
\end{tikzpicture}
\captionof{figure}{}
\end{center}
The following caption should be Figure 1-3-2.
\begin{center}
\begin{tikzpicture}
\end{tikzpicture}
\captionof{figure}{}
\end{center}
The following caption should be Figure 1-3-3.
\begin{center}
\begin{tikzpicture}
\end{tikzpicture}
\captionof{figure}{}
\end{center}
\end{document}
答案1
首先你需要\numberwithin{figure}{section}
因为这也会重新定义\thefigure
。之后你可以重新定义\thefigure
(再次)以满足你的需要。明确使用在这两个元素之间\thechapter-\arabic{section}
插入。-
\documentclass{book}
\usepackage{amsmath,caption}
\numberwithin{figure}{section}
\renewcommand\thefigure{\thechapter-\arabic{section}-\arabic{figure}}
\begin{document}
\chapter{A chapter}
\section{A section}
\section{Another section}
The following caption should be Figure 1-2-1.
\begin{center}
\captionof{figure}{A figure caption}
\end{center}
\section{Yet another section}
The following caption should be Figure 1-3-1.
\begin{center}
\captionof{figure}{Another figure caption}
\end{center}
The following caption should be Figure 1-3-2.
\begin{center}
\captionof{figure}{Yet another figure caption}
\end{center}
The following caption should be Figure 1-3-3.
\begin{center}
\captionof{figure}{A final figure}
\end{center}
\end{document}