Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'd like to redefine \caption* as

\renewcommand{\caption*}[1]{\vspace{\abovecaptionskip}\caption*{\textbf{Note:} #1}\vspace{-\abovecaptionskip}}

but keep getting an error when I try to compile. My work-around is to just define the new command \floatnote and use that instead of \caption*. It's a perfectly fine work-around, but I'm left with the question:

Q: Why doesn't the above \renewcommand code work?

\documentclass{article}
\usepackage{booktabs}
\usepackage[margin=10pt,font=small,labelfont=bf,labelsep=colon,tableposition=top,figureposition=bottom]{caption}
%\renewcommand{\caption*}[1]{\vspace{\abovecaptionskip}\caption*{\textbf{Note:} #1}\vspace{-\abovecaptionskip}}
\newcommand{\floatnote}[1]{\vspace{\abovecaptionskip}\caption*{\textbf{Note:} #1}\vspace{-\abovecaptionskip}}
\begin{document}
Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet.

\begin{table}[h]
  \centering
  \caption{Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet.}
  \begin{tabular}{ll}
    \toprule
    foo & bar \\
    \midrule
    baz & qux \\
    \bottomrule
  \end{tabular}
  %\caption*{Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet.}
  \floatnote{Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet.}
\end{table}

Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet.
\end{document}

tab1

share|improve this question

2 Answers 2

up vote 7 down vote accepted

First: you can't say \renewcommand{\caption*}[1]{...} no matter what you put in as the replacement text. A *-variant is not a command by itself: when you say \caption, LaTeX peeks at what's coming next and decides whether to perform the normal action (\caption) or the variant (\caption*).

Second: even if you could, you may not define a command in terms of itself (without taking special precautions, and this is not the case).

If you say \renewcommand{\foo}{xyz \foo} then TeX, upon finding \foo will dutifully replace it with

xyz \foo

and so it would replace \foo with xyz \foo and … TeX will stop when its memory is exhausted.

The strategy of defining \floatnote is surely better.

share|improve this answer

This answer echoes egreg's and gives some more detail.

When using the LaTeX definitions \newcommand, \renewcommand and \providecommand, only letters are allowed in the definition of the control sequence. Sometimes you may use @, but this is only allowed after changing the category code from other (or 12) to letter (or 11); hence the call to \makeatletter. For a list of TeX's category codes, see What are category codes? You are allowed other non-letter character constructions, but then you have to use a different (more low-level) control sequence definition/construction.

The way one would (re)define a command that has a *-variant would be via "verbatim peeking" - this uses the TeX condition \@ifstar (see Commands defined with * options) - or by using constructs that support it, like those provided by xparse or suffix. Regardless, whether conditioning or using support techniques, you (re)define the unstarred version, and merely supply a *-variant.

Here's how you would go about redefining a command to have a *-variant using xparse:

\usepackage{xparse}% http://ctan.org/pkg/xparse
\RedefineDocumentCommand{\somecommand}{s ...}{
  % macro contents where #1 refers to *-variant (true) or not (false)
  \IfBooleanTF{#1}% Condition on *
    {}% TRUE: \somecommand*
    {}% FALSE: \somecommand
}

Here's how the interface with suffix is used:

\usepackage{suffix}% http://ctan.org/pkg/suffix
\newcommand\somecommand{...}% unstarred version
\WithSuffix\newcommand\somecommand*{...}% *-variant
share|improve this answer
    
Wish I could check two answers. This was very helpful. But I'll just stick with the simpler \floatnote method, mentioned above, and not go down this road. –  lowndrul Feb 8 '12 at 18:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.