5

I want to get rid of prefixes in figure captions. I use MikTeX, XeLaTeX and tufte-latex style class. I've tried three variants:

\caption*{Foto}
\usepackage[labelformat=empty]{caption}
\captionsetup[figure]{labelformat=empty}

but no one helped. Am I doing something wrong? Here's MWE:

\documentclass[nofonts]{tufte-book}

\usepackage{polyglossia}
\setdefaultlanguage{russian}

\usepackage{fontspec}
\setmainfont{Palatino Linotype}

\usepackage{caption}

\begin{document}
\begin{figure}
    \includegraphics[scale=0.75]{square.png}
    \caption{Foto}
\end{figure}
\end{document}
2
  • 1
    caption does almost nothing with the tufte-book class, because it redefines captions in an incompatible way. Do you want to remove all of Fig. 1:?
    – egreg
    Commented Apr 1, 2013 at 19:32
  • @egreg, yes, I wanted to remove all prefixes. Thank you!
    – Alvar
    Commented Apr 1, 2013 at 19:55

2 Answers 2

8

If you want to remove only "Fig." (in Russian "Рис."), then

\makeatletter
\renewcommand{\fnum@figure}{\thefigure}
\makeatother

in the document preamble will print the caption as

1: Foto

If instead you want to get rid also of the number and the colon, a slightly more complicated patch is required: the whole \@caption command must be modified.

\usepackage{etoolbox}
\makeatletter
\patchcmd{\@caption}
  {\noindent\csname fnum@#1\endcsname: \ignorespaces}
  {}
  {}{}
\makeatother

With this code you'll get only

Foto

Here's a complete example:

\documentclass[nofonts]{tufte-book}

\usepackage{polyglossia}
\setdefaultlanguage{russian}

\usepackage{fontspec}
\setmainfont{Palatino}
\newfontfamily{\cyrillicfont}{Palatino}

%%% With this code no name and number will appear
\usepackage{etoolbox}
\makeatletter
\patchcmd{\@caption}
  {\noindent\csname fnum@#1\endcsname: \ignorespaces}
  {}
  {}{}
\makeatother

%%% Remove the above code and uncomment the following
%%% three lines if you still want the number
%\makeatletter
%\renewcommand{\fnum@figure}{\thefigure}
%\makeatother



\begin{document}

\begin{figure}
  \includegraphics[scale=0.75]{square.png}
  \caption{Foto}
\end{figure}

\end{document}

The package caption can't be used because tufte-book redefines the code for captions in an incompatible way.


In case you want no prefix and no number, but still want a list of figures (of course without the numbers), add also the following code before \makeatother:

\pretocmd{\@tufte@lof@line}
  {\begingroup\let\numberline\@gobble}
  {}{}
\apptocmd{\@tufte@lof@line}
  {\endgroup}
  {}{}

The captions in the list will be links to the actual figure.

1
  • This falls short in two respects: Removing the counter stepping (if you insert a mix of numbered/unnumbered figures) and printing a LoF. Of course, since the OP wants "all prefixes" removed, this is sufficient.
    – Werner
    Commented Apr 1, 2013 at 20:00
5

The following example goes one step further, also removing the details from the LoF, since \@caption includes this by default:

enter image description here

\documentclass{tufte-book}% http://ctan.org/pkg/tufte-latex
\makeatletter
\newenvironment{nocapfigure}
  {\let\H@refstepcounter\@gobble%
   \long\def\@caption##1[##2]##3{%
   \par%
   %\addcontentsline{\csname ext@##1\endcsname}{##1}%
   %  {\protect\numberline{\csname the##1\endcsname}{\ignorespaces ##2}}%
   \begingroup%
     \@parboxrestore%
     \if@minipage%
       \@setminipage%
     \fi%
     \@tufte@caption@font\@tufte@caption@justification%
     \noindent\ignorespaces##3\par%\noindent\csname fnum@#1\endcsname: \ignorespaces#3\par%
     %\@makecaption{\csname fnum@#1\endcsname}{\ignorespaces #3}\par
   \endgroup}\figure
    }{\endfigure}
\makeatother

\usepackage{graphicx}% http://ctan.org/pkg/graphicx
\begin{document}
\listoffigures
\begin{figure}
  \includegraphics[scale=0.75]{example-image-a}
  \caption{Foto}
\end{figure}
\begin{nocapfigure}
  \includegraphics[scale=0.75]{example-image-a}
  \caption{Foto}
\end{nocapfigure}
\begin{figure}
  \includegraphics[scale=0.75]{example-image-a}
  \caption{Foto}
\end{figure}
\end{document}

Removing the \addcontentsline part of \@caption removes the insertion of everything from the LoF. If you're interested in keeping the figure title, only part of \addcontentsline could be removed, as in:

\addcontentsline{\csname ext@##1\endcsname}{##1}%
  {\protect\numberline{}{\ignorespaces ##2}}%

Technically, this just drops the contents of \numberline, which provides the appropriate horizontal placement of the entry in the LoF.

The length of code via a patch (using etoolbox, say) would be comparable to a redefinition of \@caption altogether, as I did in my example.

You must log in to answer this question.

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