7

How do I remove the caption prefix (i.e Figure 1:, Table 1:) from figures, tables, etc. WITHOUT using the caption package? The reason I don't want to is because I'm using tufte-latex which already redefines the \caption command, so it doesn't work.

EDIT: More specifically, if I choose to use the normal \caption command, the figure is numbered and shows up in the List of Figures. If I use the alternative approach, the figure is not numbered and doesn't show up in the List of Figures. Same applies for tables.

Thanks in advance!

8
  • Do you still need the caption to show up in a list of figures or list of tables? Or is it merely a captioned image in a document that has no requirements to be referenced anywhere else? Mar 31, 2016 at 11:08
  • @StevenB.Segletes Actually, it's kinda specific. I want only the captions and figures that are left numbered to show up in the list. All other should just remain in the document.
    – naiveai
    Mar 31, 2016 at 11:25
  • In this case, don't use the figure or table environments. Just \begin{center}<\includegraphics{} or tabular, as needed>\par Here is my non-numbered caption\end{center} Mar 31, 2016 at 11:27
  • @StevenB.Segletes How would that work for marginfigure and margintable (defined in tufte-latex?) Besides, it's a very hack-ish solution and I would like to avoid it.
    – naiveai
    Mar 31, 2016 at 11:31
  • Please, make your request more precise, stating what figures or tables you don't want numbered. “Left numbered” is unclear.
    – egreg
    Mar 31, 2016 at 11:39

2 Answers 2

7
+150

Some surgery on tufte-common.def in order to accommodate for a \varcaption command which has the syntax

\varcaption[<offset>]{<caption text>}

(the optional argument is similar to the second optional argument for \caption).

\documentclass{tufte-book}
\usepackage{regexpatch}

\usepackage{lipsum} % just for the example

\makeatletter
\newcommand{\varcaption}[2][0pt]{%
  \gsetlength{\@tufte@caption@vertical@offset}{-#1}%
  \gdef\@tufte@stored@varcaption{#2}%
}
\xpatchcmd{\end@tufte@float}
  {\par\vspace}
  {\ifthenelse{\NOT\equal{\@tufte@stored@varcaption}{}}{\@tufte@varcaption{\@tufte@stored@varcaption}}{}\par\vspace}
  {}{}
\xapptocmd{\end@tufte@float}{\gdef\@tufte@stored@varcaption{}}{}{}
\gdef\@tufte@stored@varcaption{} % initialize
\newcommand\@tufte@varcaption[1]{%
  \begingroup
  \@parboxrestore 
  \if@minipage\@setminipage\fi
  \@tufte@caption@font
  \@tufte@caption@justification
  \noindent #1\par
  \endgroup
}
\makeatother

\begin{document}

\listoffigures

\chapter{Title}

\lipsum[2]

\begin{figure}
Something
\caption{A numbered caption}
\end{figure}

\lipsum[3]

\begin{figure}
Something
\varcaption{An unnumbered caption}
\end{figure}

\lipsum[4]

\end{document}

You'll see that the second caption is not listed in the List of Figures.

enter image description here

A version without regexpatch; copy in your document preamble everything from \makeatletter to \makeatother (included).

\documentclass{tufte-book}

\usepackage{lipsum} % just for the example

\makeatletter
\newcommand{\varcaption}[2][0pt]{%
  \gsetlength{\@tufte@caption@vertical@offset}{-#1}%
  \gdef\@tufte@stored@varcaption{#2}%
}
\gdef\@tufte@stored@varcaption{} % initialize
\newcommand\@tufte@varcaption[1]{%
  \begingroup
  \@parboxrestore 
  \if@minipage\@setminipage\fi
  \@tufte@caption@font
  \@tufte@caption@justification
  \noindent #1\par
  \endgroup
}
\def\end@tufte@float{%
      \par\hbox{}\vspace{-\baselineskip}\ifthenelse{\prevdepth>0}{\vspace{-\prevdepth}}{}% align baselines of boxes
      \end{minipage}%
    \end{lrbox}%
    % build the caption box
    \begin{lrbox}{\@tufte@caption@box}%
      \begin{minipage}[\floatalignment]{\marginparwidth}\hbox{}%
        \ifthenelse{\NOT\equal{\@tufte@stored@caption}{}}{\@tufte@orig@caption[\@tufte@stored@shortcaption]{\@tufte@stored@caption}}{}%
        \ifthenelse{\NOT\equal{\@tufte@stored@label}{}}{\@tufte@orig@label{\@tufte@stored@label}}{}%
        \ifthenelse{\NOT\equal{\@tufte@stored@varcaption}{}}{\@tufte@varcaption{\@tufte@stored@varcaption}}{}
        \par\vspace{-\prevdepth}%% TODO: DOUBLE-CHECK FOR SAFETY
      \end{minipage}%
    \end{lrbox}%
    % now typeset the stored boxes
    \begin{fullwidth}%
      \begin{minipage}[\floatalignment]{\linewidth}%
        \ifthenelse{\boolean{@tufte@float@star}}%
          {\@tufte@float@fullwidth[\@tufte@caption@vertical@offset]{\@tufte@figure@box}{\@tufte@caption@box}}%
          {\@tufte@float@textwidth[\@tufte@caption@vertical@offset]{\@tufte@figure@box}{\@tufte@caption@box}}%
      \end{minipage}%
    \end{fullwidth}%
    \@tufte@orig@endfloat% end original LaTeX float environment
    % output debug info
    \ifthenelse{\boolean{@tufte@debug}}{%
      \typeout{^^J^^J----------- Tufte-LaTeX float information ----------}%
      \ifthenelse{\equal{\@tufte@stored@label}{}}%
        {\typeout{Warning: Float unlabeled!}}%
        {\typeout{Float label: [\@tufte@stored@label]}}%
      \typeout{Page number: [\thepage]}%
      \def\MessageBreak{^^J}%
      \typeout{\@tufte@float@debug@info}%
      \ifthenelse{\boolean{@tufte@symmetric}}%
        {\typeout{Symmetric: [true]}}%
        {\typeout{Symmetric: [false]}}%
      \typeout{----------------------------------------------------^^J^^J}%
    }{}%
    % reset commands and temp boxes and captions
    \gdef\@tufte@float@debug@info{}%
    \let\caption\@tufte@orig@caption%
    \let\label\@tufte@orig@label%
    \begin{lrbox}{\@tufte@figure@box}\hbox{}\end{lrbox}%
    \begin{lrbox}{\@tufte@caption@box}\hbox{}\end{lrbox}%
    \gdef\@tufte@stored@shortcaption{}%
    \gdef\@tufte@stored@caption{}%
    \gdef\@tufte@stored@label{}%
    \gsetlength{\@tufte@caption@vertical@offset}{0pt}% reset caption offset
    \gdef\@tufte@stored@varcaption{}
  }
\makeatother

\begin{document}

\listoffigures

\chapter{Title}

\lipsum[2]

\begin{figure}
Something
\caption{A numbered caption}
\end{figure}

\lipsum[3]

\begin{figure}
Something
\varcaption{An unnumbered caption}
\end{figure}

\lipsum[4]

\end{document}

Support for marginfigure and margintable

With the following code that must be added to the previous one before the final \makeatother, you can use \varcaption also in marginfigure and margintable.

\renewenvironment{@tufte@margin@float}[2][-1.2ex]%
  {\FloatBarrier% process all floats before this point so the figure/table numbers stay in order.
  \begin{lrbox}{\@tufte@margin@floatbox}%
  \begin{minipage}{\marginparwidth}%
    \renewcommand\varcaption[2][]{\par\@tufte@varcaption{##2}}%
    \@tufte@caption@font%
    \def\@captype{#2}%
    \hbox{}\vspace*{#1}%
    \@tufte@caption@justification%
    \@tufte@margin@par%
    \noindent%
  }
  {\end{minipage}%
  \end{lrbox}%
  \marginpar{\usebox{\@tufte@margin@floatbox}}%
  }
10
  • So what exactly do I need to do? What do I need to copy into my preamble? I copied from \makeatletter to \makeatother and included regexpatch. I get an Undefined control sequence error.
    – naiveai
    Mar 31, 2016 at 13:23
  • @eshansingh1 What Undefined control sequence?
    – egreg
    Mar 31, 2016 at 13:32
  • Wait no, no longer getting that but there is no caption.
    – naiveai
    Mar 31, 2016 at 13:38
  • Ah, wait - this is meant to work with figure, not marginfigure. Thanks for this though, I can model this to figure something out.
    – naiveai
    Mar 31, 2016 at 13:43
  • Also, how did you do all of this so fast? I have absolutely zero knowledge about LaTeX programming. I guess you have to know it pretty well to get to 464k rep.
    – naiveai
    Mar 31, 2016 at 13:45
2

In a comment, I told the OP how to add a figure in the text, without numbering. Here, based on a follow-up comment by the OP, I show how to get the unnumbered figure into the margin, similar to marginfigure of the tufte-book class.

\documentclass{tufte-book}
\usepackage{lipsum,graphicx}
\begin{document}
\listoffigures

\noindent\hrulefill

\lipsum[1]
\marginpar{
\includegraphics[width=.5in]{example-image-A}\par
\footnotesize This is my caption
}
\lipsum[2]
\begin{marginfigure}
\includegraphics[width=.5in]{example-image-A}\par
\caption{margin figure}
\end{marginfigure}
\lipsum[3]
\end{document}

enter image description here

1
  • This works, but I'll wait for more answers. In case none come up, I'll accept this.
    – naiveai
    Mar 31, 2016 at 12:13

You must log in to answer this question.

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