9

I'm using two different floats, and I'd like to use the same counter for both. The standard LaTeX format for a new float is:

 \newfloat{type}{placement}{ext}[outer counter]

I tried using this by substituting various counters for the "outer counter" but they all give a double digit result, like 0.1 or 0.2, etc. I'm wondering how I can use one SINGLE DIGIT COUNTER for the floats. In other words, I want to start my floats' captions as "Figure 1", "Figure 2", etc.

Could someone please provide a code example to do this?

As an aside, I'm using both the float and caption packages.

2 Answers 2

11

You can make a new float type foo and then use

\makeatletter
\let\c@foo\c@figure
\makeatother

to make foo share a counter with figure.

0
3

The "float" package gives you the ability to number floats in two ways. One sequentially through your document i.e., (Example 1, Example 2 etc) or to reset the counter every time based on another counter such as a chapter or section. Here is an example below that can do both.

\documentclass{book}
\usepackage{float}
\begin{document}
\newfloat{Example}{htbp}{loe}
\newfloat{Code}{htbp}{loc}[chapter]
\chapter{One}

\begin{Example}
   This is a test
\caption{This is the first example}
\end{Example}

\begin{Example}
   This is a test
\caption{This is the second example}
\end{Example}

\chapter{Two}
\begin{Example}
   This is a test
\caption{This is the third example}
\end{Example}


\begin{Code}
  \begin{verbatim}
      \one \two \three
   \end{verbatim}
   \caption{Code Example}
\end{Code}

\begin{Code}
  \begin{verbatim}
      \begin ... \end
   \end{verbatim}
   \caption{Code Example}
\end{Code}
\end{document}

I did not understand the part of your question where you say you need the floats to share the counter value. LaTeX creates a counter as by appending a c@ to the counter name, so for the two examples above to share a counter you can write \let\c@Example\c@Code or vice-versa as you wish.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .