9

I understand how to put a caption on a figure, I'd do something like,

\begin{figure}[h]

...put figure here...

\label{figure1}\caption{this is a figure}

\end{figure}

and the caption reads,

Figure 1: this is a figure

which is all very well and good. However, I would dearly like my figure to only have the label,

Figure 1

without the caption. How would I do this?

(Basically, I have a figure that I want to reference, so I need it to have some label. It is perfectly fine without any caption, and adding one would detract from what is going on.)

Marco Daniel
  • 95,681
user1729
  • 817
  • 7
  • 18

2 Answers2

9

First of all: First the caption than the label.

It depends on your loaded documentclass and packages. For example you can simple write:

\caption[this is a figure]{}

And the output is:

Figure 1:

The extra colon can be removed by changing the internal definition of the command \@makecaption. With no extra packages or a special class like memoir or KOMA you can use:

\documentclass[letterpaper, 10pt]{article}
\makeatletter
\def\mycaptsep{:\space}
\long\def\@makecaption#1#2{%
  \vskip\abovecaptionskip
  \ifx\ignorespaces#2\relax%
     \let\mycaptsep\relax%
  \fi%
  \sbox\@tempboxa{#1\mycaptsep #2}%
  \ifdim \wd\@tempboxa >\hsize
    #1\mycaptsep #2\par
  \else
    \global \@minipagefalse
    \hb@xt@\hsize{\hfil\box\@tempboxa\hfil}%
  \fi
  \vskip\belowcaptionskip}
\makeatother
\begin{document}
\begin{figure}[h]

...put figure here...
\caption{}
\label{figure1}
\end{figure}
\end{document}

If you are using the package caption it's more elegant. The package detects empty arguments of \caption:

\documentclass[letterpaper, 10pt]{article}
\usepackage{caption}
\begin{document}
\begin{figure}[h]

...put figure here...
\caption{}
\label{figure1}
\end{figure}
\end{document}

If you are using a KOMA class you must change the separator. This can be done global:

\documentclass[letterpaper, 10pt]{scrartcl}
\renewcommand*{\captionformat}{}
\begin{document}
\begin{figure}[h]

...put figure here...
\caption{}
\label{figure1}
\end{figure}
\end{document}
Marco Daniel
  • 95,681
  • Could you perhaps give a brief explanation of what the code in your first example is doing? – user1729 Apr 17 '12 at 12:50
  • 1
    @user1729: I created a new command \mycaptsep to define a separator if the caption isn't empty. Then I redefined the internal command \@makecaption defined in the document class in this way that it uses the new command \mycaptsep. – Marco Daniel Apr 17 '12 at 12:54
  • Have you tested your redefined \@makecaption with some more examples, one with a non-empty caption?

    IMHO the \ifx\ignorespaces#2\relax will always be true, because the standard \caption command in the LaTeX kernel expands this internal macro \@makecaption with a second argument starting with a \ignorespaces token (followed by the user caption text argument). And if used with a non-empty caption you will get some additional text somewhere you don't want it.

    – Bernd Raichle Jan 14 '23 at 14:25
7

Try this.

\documentclass{article}
\usepackage[figurename=Figure]{caption}
\begin{document}
\begin{figure}
\centering
\rule{4cm}{4cm}  
\caption{A nice figure}
\label{whatever}
\end{figure}
\end{document}

The caption package is loaded to get rid of any unwanted punctuation that could appear after the figure number.

Ian Thompson
  • 43,767