[Tex/LaTex] Remove colon in the caption of a figure if the caption is empty

captionspunctuation

One of my figures should not have a caption, only the normal numbering. To get this, I use this code:

\begin{wrapfigure}{l}{4cm}
  \begin{center}
    \includegraphics[width=3cm]{graphic.pdf}
    \caption[Caption for the list of figures]{}
    \label{fig:figureX}
  \end{center}
\end{wrapfigure}

But now I get "Figure x.y:" as caption of my figure. How can I remove the ":", if the caption is empty? I found some solutions with renewcommand, but this changes the caption style in the whole document. I want to remove the colon only if the caption is empty. In any other case, it is good to have "Figure x.y: My Caption".

Best Answer

Just loading the caption package should solve this. It makes the colon a proper "separator", i.e. it only appears when there is something to separate.

\documentclass{article}
\usepackage{wrapfig}
\usepackage[demo]{graphicx}
\usepackage{caption}

\begin{document}
\begin{wrapfigure}{l}{4cm}
  \begin{center}
    \includegraphics[width=3cm]{graphic.pdf}
    \caption[Caption for the list of figures]{}
    \label{fig:figureX}
  \end{center}
\end{wrapfigure}
\begin{wrapfigure}{l}{4cm}
  \begin{center}
    \includegraphics[width=3cm]{graphic.pdf}
    \caption[Caption for the list of figures]{With caption}
    \label{fig:figureX}
  \end{center}
\end{wrapfigure}
\end{document}

figures

Related Question