TransWikia.com

figures: return the figure number rather than the section number when there is no caption

TeX - LaTeX Asked on July 20, 2021

I want to be able to number my figures using the figure counter, not the section number, but am unable to do this without including a caption. Of course a potential (hideous) kludge would be to include a caption{} before the label but by default, this would result in FIGURE 1: when I really don’t want a caption at all. So, if it’s really impossible (extremely hard to believe) that you have to have a caption in order to have a figure number, then how can I tamper with caption so that it doesn’t return anything, even white space?

The code below illustrates the problem: ref{myLabel} will return In figure 1.1.1.
Here is the bunny:
enter image description here

documentclass{amsart}
usepackage{graphicx}
begin{document}
section{section}
subsection{subsection}
subsubsection{subsubsection}
begin{figure}
includegraphics{bunny.jpg}
label{myLabel}
end{figure}
In figure ref{myLabel},

end{document}

~

2 Answers

There is no counter increment associated with the figure environment, only with caption however you can use refstepcounter{figure} before the label if you want the counter to increment unseen.

Answered by David Carlisle on July 20, 2021

(this answer incorporates information provided by the OP in a comment below the main query)

If you use caption{} to create captions without caption text, the colon that's inserted by LaTeX after Figure 1, Figure 2, etc probably doesn't look quite right, since there's no text to which the caption header cum colon points to.

If you share this view, you may want to load the caption package. That way, the trailing colon after Figure x and Table y will be omitted automatically if the argument of caption is either empty or consists of whitespace only.

To verify this statement, simply compile the following sample code -- note the absence of a colon in the caption{} and caption{ } cases.

documentclass{article} 
usepackage{caption}

begin{document}

begin{table}[ht!] 
  caption{Hello} 
end{table}
begin{figure}[h!] 
  caption{} 
end{figure}
begin{table}[h!] 
  caption{   } 
end{table}
begin{figure}[h!] 
  caption{World} 
end{figure}

end{document}

Answered by Mico on July 20, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP