
我是一名 LaTeX 的重度用戶,但對 Tex 程式設計是如何完成的知之甚少。我正在寫一個較長的文檔,並希望有這樣的圖號:chaper.section.figure_number 例如圖 4.3.10。經過一番研究後,我發現這個解決方案效果很好:
\makeatletter
\@addtoreset{equation}{section}
\@addtoreset{figure}{section}
\@addtoreset{table}{section}
\def\thefigure{\thesection.\@arabic\c@figure}
\def\thetable{\thesection.\@arabic\c@table}
\def\theequation{\thesection.\@arabic\c@equation}
\makeatother
,雖然我不知道為什麼。不幸的是,當我使用標籤的子圖時,我得到了這樣的引用:chaper.figure_nuber 例如 4.30(a)。但我想要的是:chapter.section.figure_number.(a,,b,c..) 例如4.2.10(a)。我想我必須定義一個像上面這樣的附加命令,但是從 subfig 文件中我無法說出哪個命令以及如何...
我將不勝感激任何幫助
答案1
以下設定應該適合您想要的工作。請注意,我使用較新的subcaption
軟體包而不是較舊的軟體包subfig
,並且我使用了\numberwithin
該軟體包提供的命令amsmath
。
\documentclass{book}
\usepackage{amsmath, % for \numberwithin and \eqref commands
subcaption} % for subfigure environment
\usepackage[demo]{graphicx} % remove 'demo' option for real document
\numberwithin{equation}{section}
\numberwithin{figure}{section}
\numberwithin{table}{section}
\begin{document}
\chapter{First Chapter}
\section{New ideas}
\begin{figure}[h]
\begin{subfigure}{0.45\textwidth}
\includegraphics[width=\columnwidth]{somegraph.pdf}
\caption{First subfig} \label{fig:1a}
\end{subfigure}
\hspace{\fill} % maximize horizontal separation of subfigs
\begin{subfigure}{0.45\textwidth}
\includegraphics[width=\columnwidth]{anothergraph.pdf}
\caption{First subfig} \label{fig:1b}
\end{subfigure}
\caption{The first figure}
\end{figure}
A display-style equation:
\begin{equation}\label{eq:1}
a^2+b^2=c^2
\end{equation}
And here are cross-references to subfigures \ref{fig:1a} and \ref{fig:1b}
as well as to equation~\eqref{eq:1}.
\end{document}