![如何在标题和 \numberwithin{figure}{section} 中使用破折号代替点](https://linux22.com/image/439961/%E5%A6%82%E4%BD%95%E5%9C%A8%E6%A0%87%E9%A2%98%E5%92%8C%20%5Cnumberwithin%7Bfigure%7D%7Bsection%7D%20%E4%B8%AD%E4%BD%BF%E7%94%A8%E7%A0%B4%E6%8A%98%E5%8F%B7%E4%BB%A3%E6%9B%BF%E7%82%B9.png)
我的图在部分内进行了编号。我想在图片标题中使用破折号而不是点(例如,图 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}