3

This question shows how to remove the needless : from a figure with no caption, while leaving the "Figure X" label intact. The solution is to include the caption package.

Unfortunately, the tufte-book class doesn't seem to like this solution, as shown in the MWE below, which produces the warning:

Package caption Warning: \caption will not be redefined since it's already
(caption)                redefined by a document class or package which is
(caption)                unknown to the caption package.
See the caption package documentation for explanation.

This question shows a circumvention that avoids using the caption package, but modifying the MWE to use it instead yields exactly the same output as before.

I don't actually need any captions at all in this document, just figure labels, so anything that gets rid of the darn : and centers the "Figure X" bit would be ideal. Suggestions?

MWE:

\documentclass{tufte-book}
\usepackage{wrapfig}
\usepackage[demo]{graphicx}
%\usepackage{caption}
\usepackage{etoolbox}
\makeatletter
\patchcmd{\@makecaption}{#1: #2}{#1}{}{}
\makeatother



\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}

Output: enter image description here

1 Answer 1

5

You are patching the wrong command. In the tufte-book class, it is \@caption and the relevant part is originally:

\@tufte@caption@font\@tufte@caption@justification%
\noindent\csname fnum@#1\endcsname: \ignorespaces#3\par%

see the file tufte-common.def.

Sample output

\documentclass{tufte-book}
\usepackage{wrapfig}
\usepackage[demo]{graphicx}
\usepackage{etoolbox}

\makeatletter
\patchcmd{\@caption}{\csname fnum@#1\endcsname: \ignorespaces#3}{\csname fnum@#1\endcsname}{}{}
\makeatother

\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}

This is easily adapted to test whether the caption is empty or not, and to center the caption:

\makeatletter
\patchcmd{\@caption}{\csname fnum@#1\endcsname:
\ignorespaces#3}{\Centering
\csname fnum@#1\endcsname\ifblank{#3}{}{: \ignorespaces#3}}{}{}
\makeatother 

Centered sample

2
  • That's what I was looking for. To center the figure label as well is as easy as \patchcmd{\@caption}{\csname fnum@#1\endcsname: \ignorespaces#3}{\begin{center} \csname fnum@#1\endcsname\end{center}}{}{} Dec 5, 2013 at 20:27
  • 1
    Very good - consistency with the other justification commands of this class would actually suggest you use \Centering instead, see my updated answer. Dec 6, 2013 at 7:34

You must log in to answer this question.

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