Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a set of different types to include figure-like items in a document. These include a float (created by \SetupFloatingEnvironment), a non-float and full-page environments/commands.

While the non-float environment easily can share the counter and list of the basic float type through the \captionsetup, I had to go to some length with the full-page type: This doesn't have a real \caption but rather a text that is formatted like the caption. I then manually update the counter, write a) that 'caption' in the page header and b) manually create a toc entry.

Basically that works quite well, but when I'm in a context where the floating environments are numbered with the chapter number included I don't know how to mimick that in my manual caption.

So the question is: How can I determine the actual numbering options for floats (that the end user of my package may have changed individually)? And how can I reproduce that formatting for a custom caption and 'contentsline'?

share|improve this question
1  
If your float has a counter myfloat, then \themyfloat prints the float counter in whichever way it was defined. If it includes the chapter, it would typically be something like \arabic{chapter}.\arabic{myfloat}. Are you using \themyfloat to set the counter in your full-page environments or are you using \arabic{myfloat}? –  Werner Mar 13 '13 at 17:02
    
@Werner: Thank you very much. That was all that was missing :-) I didn't know about this \the... instance and tried with \arabic. –  uli_1973 Mar 13 '13 at 17:28
    
@uli_1973: I've added an answer that seems very generic, but most likely addresses your question. It's also better to use \thechapter.\arabic{myfloat} instead, as I've noted. –  Werner Mar 13 '13 at 17:35
    
Thanks for that answer, but it doesn't really solve my question. Your earlier comment was suited better. I have a float myfloatand a non-floating command mycommand that shares the myfloat counter. What I now do is to manually increment myfloat from within mycommand (with \refstepcounter{myfloat} and then use themyfloat to display the counter. Should I update your answer? Or just upvote it and write my own answer? What would be the desired behaviour for this situation? –  uli_1973 Mar 19 '13 at 9:35
    
Although the situation might seem different, the display (using \the<counter>) is identical. In that respect, you can edit my answer. –  Werner Mar 19 '13 at 16:02

1 Answer 1

In LaTeX, each counter defined by \newcounter{<counter>} is provided with an accompanying macro \the<counter> that defaults to \arabic{<counter>}. This allows users to step (or update) counters as expected, but have them linked to other counters when printing (for example, figure counters that include the chapter as well).

Instead of setting the counter using \arabic{<counter>} within your code, use \the<counter> instead, and redefine it in the following way, say:

\renewcommand{\the<counter>}{\the<othercounter>.\arabic{<counter>}}

This allows <counter> to inherit any formatting of the <othercounter>'s printing mechanism.

An alternative approach is to directly use \the<othercounter> to use its display properties, whatever they are.

Given a command \myfigure that wants to hook into the figure counter one could write:

\newcommand{\myfigure}{%
    \refstepcounter{figure}%
    \addcontentsline{lof}{figure}{\protect\numberline{\thefigure}{\ignorespaces #1\relax }}%
}

That way the contentsline uses the numbering of figure regardless of its formatting.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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