我想向 添加一个参数\caption
,以便我可以为表格、图形或注释添加标题。为什么如果我像下面显示的那样修改定义,会出现错误?
\documentclass[nofonts]{tufte-handout}
\usepackage{booktabs}
\makeatletter
%%
% Format the captions in a style similar to the sidenotes
\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\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}
为什么我不能像这样修改定义?
\long\def\@caption#1[#2]#3#4{%
\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\textsc{#3} \ignorespaces#4\par%
%\@makecaption{\csname fnum@#1\endcsname}{\ignorespaces #3}\par
\endgroup}
错误:
! Missing number, treated as zero.
<to be read again>
\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.
<to be read again>
\par
l.158 \end{table}
I was expecting to see `<', `=', or `>'. Didn't.
! Missing number, treated as zero.
<to be read again>
\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.)
答案1
内部宏\@tufte@caption
读取 的最终参数\caption
。以下示例使用最后一个参数#4
作为标题文本,并将标题类型 ( Fonts
) 放入宏 中\my@caption@type
。然后可以在内部使用\@caption
其正常参数 ( #1[#2]#3
)。
Fonts
此外,表格列表中放置的是类型 ( ),而不是数字。由于需要额外的空间,因此\@tufte@lof@line
进行了相应调整:
\documentclass[nofonts]{tufte-handout}
\usepackage{booktabs}
\makeatletter
\long\def\@caption#1[#2]#3{%
\par%
\addcontentsline{\csname ext@#1\endcsname}{#1}%
% {\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
\advance\leftskip\@tempdima
\null\nobreak\hskip -\leftskip
{#1}\nobreak\qquad\nobreak#2%
\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}