Graphics, Figures & TablesFigure counter not incrementing with \input

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
bidski
Posts: 5
Joined: Fri Sep 24, 2021 1:30 am

Figure counter not incrementing with \input

Post by bidski »

I have the following

Code: Select all

\begin{figure}
    \input{figure1.tex}
\end{figure}
\begin{figure}
    \input{figure2.tex}
\end{figure}
Inside of both figure1.tex and figure2.tex i have

Code: Select all

\begin{tikzpicture}
    %%% .... tikz code ....
    \node [options] at (position) {
    \parbox{\linewidth}{
        \captionsetup{font={large}}
        \caption{\label{fig:fig1}Figure caption}
    }};
\end{tikzpicture}
(the label is distinct for each of the input files).

In the generated document both images have the same number though (e.g. both images are shown as "Figure 4.5")

If I modify the original code to

Code: Select all

\begin{figure}
    \input{figure1.tex}
    \stepcounter{figure}
\end{figure}
\begin{figure}
    \input{figure2.tex}
    \stepcounter{figure}
\end{figure}
Then any following images (after these two) will have the correct figure numbers, but the two inputted figures still have the same duplicated numbers.

Does \input do something strange with counters? How can I fix this so that both of the inputted images have distinct numbers?

See this question for more context on the tikzpictures

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Stefan Kottwitz
Site Admin
Posts: 10340
Joined: Mon Mar 10, 2008 9:44 pm

Figure counter not incrementing with \input

Post by Stefan Kottwitz »

I would use \caption outside the tikzpicture environment, since it doesn't belong to the TikZ content. That (nesting in a parbox within a node within a TikZ picture code) could be the reason, not the \input.

You could move \caption below \end{tikzpicture} at least to verify that this may be the reason.

Stefan
LaTeX.org admin
bidski
Posts: 5
Joined: Fri Sep 24, 2021 1:30 am

Figure counter not incrementing with \input

Post by bidski »

Stefan Kottwitz wrote: You could move \caption below \end{tikzpicture} at least to verify that this may be the reason.
This was actually the issue. Is there any way other way to get this to work? Is it possible to do something like \footnotemark and \footnotetext with a caption?
Post Reply