0

I have problem with numbering subsection after figure label. I put appendix, caption and label, and put counter of figure to 0 so graph label says Picture 1. Then, when i want to start new chapter, section or subsection, it is numbered .0.1. instead of example, 2.2.1. How do i end figure labeling and let document continue section numbering normally? Here is the code:

\section{text}
\pgfplotsset{compat=1.12}
\begin{figure}[h] 
\centering
\appendix

\begin{tikzpicture}
\begin{axis}[xlabel=x,ylabel=y,grid=both,xmax=10,ymax=10,axis lines=middle,restrict y to domain=-7:10,enlargelimits]
\addplot[blue]  {pow(2,x)} node[above]{$y=2^x$};
\addplot[red]  {pow(10,x)} node[above]{$y=10^x$};
\end{axis}
\end{tikzpicture}

\setcounter{figure}{0}
\caption{text}
\label{fig:text}
\end{figure}

\subsection{text}
  • What is your over all goal doing this? Why is there an \appendix-Tag in the middle of your figure? – nhck Aug 2 '17 at 9:30
  • @nhck I have a section 2.2. In there i need to put a graph of an exponential function. This is my first picture in document so i need to label it: "Picture 1: Exponential graph". If i just use caption and label, it's label isn't "1." but "2.1" for some reason. If i put \appendix and set counter to 0, it shows correct number of caption but messes up section numbering. It may be a minor problem, i just started working in tex yesterday, so I only put appendix in because it worked that way, I cant really understand what it does. – Mactadilis Aug 2 '17 at 10:12
1

The numbering depends on your documentclass. I'm assuming book in this example. You can use the package chngcntr to adjust the figure numbering to include or exclude certain numbers. The example below excludes section and subsection number for the figure number.

The \appendixtag you use is just for resetting the counter to start the appendix numbering.

These two posts are also a good read for you: How to number figures continuously in documentclass{article} and Why does an environment's label have to appear after the caption?

\documentclass{book} 
\usepackage{lipsum} %Just for the sampletext


\usepackage[demo]{graphicx} %Package for the Figures

\usepackage{chngcntr} %Package to set the counter
\counterwithout{figure}{section}
\counterwithout{figure}{subsection}


\begin{document}
\chapter{This is Chapter}
\section{Section One}
\begin{figure}
    \centering
    \includegraphics[width=0.3\linewidth]{img}
    \caption{trest}
    \label{fig:dogemadone}
\end{figure}
\lipsum[1-3]
\section{Section Two}
\lipsum[1]
\begin{figure}
    \centering

    \includegraphics[width=0.3\linewidth]{img}
    \caption{trest2}
    \label{fig:dogemad}
\end{figure}
\subsection{Subsection of Section Two}
\lipsum[2-4]

\appendix %This changes the counter for the appendix
\chapter{Chapter}
\section{Section One}
\lipsum*
\end{document}
  • 1
    Thank you, it solved the problem. I deleted appendix and set counter within figure, added \usepackage{chngcntr} and added \counterwithout command. – Mactadilis Aug 2 '17 at 12:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.