However, this still isn't an optimal solution because now the table of contents and list of figures will not display properly. I can correct the spacing on the list of figures easily enough but how can I display the text in each section and subsection? Is there a better way to change the figure number based on what section or subsection it is in?
My idea was to redefine the \section command so that it called \section and also renewed the figure number each time it was called. I have not been able to implement this though.
As a reiteration, I'm trying to create a figure number that shows what section it is in, e.g. the second figure in section 1.1.1 would be 1.1.1-2.
Code: Select all
\documentclass{article}
\usepackage[pdftex,demo]{graphicx} %to use images and figures
%Make section number before figure number.
\newcommand{\mysection}[2][]{\section[#1]{#2}\setcounter{figure}{0}\renewcommand{\thefigure}{\thesection-\arabic{figure}}}
\newcommand{\mysubsection}[2][]{\subsection[#1]{#2}\setcounter{figure}{0}\renewcommand{\thefigure}{\thesubsection-\arabic{figure}}}
\newcommand{\mysubsubsection}[2][]{\subsubsection[#1]{#2}\setcounter{figure}{0}\renewcommand{\thefigure}{\thesubsubsection-\arabic{figure}}}
\begin{document}
\tableofcontents
\listoffigures
\newpage
\mysection{Section 1}
\begin{figure}[h] %Should be Figure 1-1
\begin{center}
\includegraphics[width=120mm]{test.png}
\end{center}
\caption{(Should say Figure 1-1)}
\end{figure}
\newpage
\mysubsection{Subsection}
\begin{figure}[h] %Should be Figure 1.1-1
\begin{center}
\includegraphics[width=120mm]{test.png}
\end{center}
\caption{(Should say Figure 1.1-1)}
\end{figure}
\newpage
\mysubsubsection{Subsubsection}
\begin{figure}[h] %Should be Figure 1.1.1-1
\begin{center}
\includegraphics[width=120mm]{test.png}
\end{center}
\caption{(Should say Figure 1.1.1-1)}
\end{figure}
\newpage
\mysection{Section 2}
\begin{figure}[h] %Should be Figure 2-1
\begin{center}
\includegraphics[width=120mm]{test.png}
\end{center}
\caption{(Should say Figure 2-1)}
\end{figure}
\end{document}