# Add one or more arguments to \caption

I would like to add an argument to \caption, so that I can add a title to the table, figure or note. Why do I get an error if I modify the definition like I show you below?

\documentclass[nofonts]{tufte-handout}

\usepackage{booktabs}

\makeatletter

%%
% Format the captions in a style similar to the sidenotes

\long\def\@caption#1[#2]#3{%
\par%
{\protect\numberline{\csname the#1\endcsname}{\ignorespaces #2}}%
\begingroup%
\@parboxrestore%
\if@minipage%
\@setminipage%
\fi%
\@tufte@caption@font\@tufte@caption@justification%
\noindent\csname fnum@#1\endcsname: \ignorespaces#3\par%
%\@makecaption{\csname fnum@#1\endcsname}{\ignorespaces #3}\par
\endgroup}

\makeatother

\begin{document}

\begin{table}[h]
\begin{center}
\footnotesize%
\begin{tabular}{lcr}
\toprule
Heading & Style & Size \\
\midrule
Part & roman & 1 \\
Chapter & italic & 2 \\
Section & italic & 11\\
Subsection & italic & 111 \\
Paragraph & italic & 10/14 \\
\bottomrule
\end{tabular}
\end{center}
\caption{Fonts}{These are\dots}
\end{table}

\end{document}


Why can't I just modify the definition like this?

\long\def\@caption#1[#2]#3#4{%
\par%
{\protect\numberline{\csname the#1\endcsname}{\ignorespaces #2}}%
\begingroup%
\@parboxrestore%
\if@minipage%
\@setminipage%
\fi%
\@tufte@caption@font\@tufte@caption@justification%
\noindent\textsc{#3} \ignorespaces#4\par%
%\@makecaption{\csname fnum@#1\endcsname}{\ignorespaces #3}\par
\endgroup}


Error:

! Missing number, treated as zero.
\par
l.158 \end{table}

A number should have been here; I inserted 0'.
(If you can't figure out why I needed to see a number,
look up weird error' in the index to The TeXbook.)

! Missing = inserted for \ifnum.
\par
l.158 \end{table}

I was expecting to see <', =', or >'. Didn't.

! Missing number, treated as zero.
\par
l.158 \end{table}

A number should have been here; I inserted 0'.
(If you can't figure out why I needed to see a number,
look up weird error' in the index to The TeXbook.)

• What is the error? – user31729 Oct 9 '15 at 16:31
• @ChristianHupfer It has something to do with the table environment. Se my updated question. – Aurelius Oct 9 '15 at 17:15
• And what should the new argument do? – egreg Oct 9 '15 at 17:18
• @egreg I just wanted to create something like a "label" for the all the material that goes in the margin. Instead of Table 1: This table is about... I wanted to try something new like Title: description... where Title is the title or label of the material (e.g. table, picture, note etc.). Am I making myself clear? – Aurelius Oct 9 '15 at 17:51

The internal macro \@tufte@caption reads the final arguments of \caption. The following example uses the last argument #4 as the caption text and puts the type of caption (Fonts) in macro \my@caption@type. Then this can be used inside \@caption with its normal arguments (#1[#2]#3).

Also the type (Fonts) is put in the list of tables instead of the number. Since additional space is needed, \@tufte@lof@line is adjusted accordingly:

\documentclass[nofonts]{tufte-handout}

\usepackage{booktabs}

\makeatletter

\long\def\@caption#1[#2]#3{%
\par%
%  {\protect\numberline{\csname the#1\endcsname}{\ignorespaces #2}}%
{\protect\numberline{\textsc{\my@caption@type}}{\ignorespaces #2}}%
\begingroup
\@parboxrestore
\if@minipage
\@setminipage
\fi
\@tufte@caption@font\@tufte@caption@justification
\noindent\textsc{\my@caption@type} \ignorespaces#3\par
%\@makecaption{\csname fnum@#1\endcsname}{\ignorespaces #3}\par
\endgroup
}

\long\def\@tufte@caption[#1][#2]#3#4{%
\gdef\my@caption@type{#3}%
\ifthenelse{\isempty{#1}}%
{\gdef\@tufte@stored@shortcaption{#4}}%
{\gdef\@tufte@stored@shortcaption{#1}}%
\gsetlength{\@tufte@caption@vertical@offset}{-#2}%
\gdef\@tufte@stored@caption{#4}%
}
\makeatother

\begin{document}

\begingroup
\makeatletter
\renewcommand*{\@tufte@lof@line}[2]{%
% #1 is the figure/table number and its caption text
% #2 is the page number on which the figure/table appears
\leftskip 0.0em
\rightskip 0em
\parfillskip 0em plus 1fil
\parindent 0.0em
\@afterindenttrue
\interlinepenalty\@M
\leavevmode
% Increase space for the "number"
\settowidth{\@tempdima}{\textsc{Fonts}\enspace}% largest term
\null\nobreak\hskip -\leftskip
\par%
}%
\listoftables
\endgroup

\begin{table}[h]
\centering
\footnotesize
\begin{tabular}{lcr}
\toprule
Heading & Style & Size \\
\midrule
Part & roman & 1 \\
Chapter & italic & 2 \\
Section & italic & 11\\
Subsection & italic & 111 \\
Paragraph & italic & 10/14 \\
\bottomrule
\end{tabular}
\caption{Fonts}{These are\dots}
\end{table}

\end{document}


• What is the purpose of \expandafter here? If I remove it, I can't see any difference... – Aurelius Oct 10 '15 at 10:19
• @FormlessCloud I have removed it, it was a leftover from a previous version. – Heiko Oberdiek Oct 10 '15 at 14:53
• This return an error if you use it within the margintable environment... – Aurelius Oct 18 '15 at 20:00
• @FormlessCloud There are many packages that deal with captions, redefine internals, ..., that can conflict with other code redefining internals. – Heiko Oberdiek Oct 18 '15 at 20:05
• Okay don't worry, I just wanted to let you know. I'll take care of it :)` – Aurelius Oct 18 '15 at 20:07