0

I want to list only certain tables in my book on the List of Tables using \listoftables command, especially ones that are captioned. I have labelled tables that are captioned and not the ones that are not captioned. How can I tackle this problem? Say, I have 15 tables that I want to list among 100 tables.

I used empty \caption{} for uncaptioned tables just for displaying table numbers.

3
  • Don't use the table environment for the ones you don't want listed?
    – Alan Munn
    Commented Jun 3, 2021 at 17:45
  • I have a problem following your problem. A \caption in a table gets put into the LoT, a table without a \caption does not get into the LoT. Commented Jun 3, 2021 at 17:47
  • Oh wait, that is true. I actually used empty \caption{} for uncaptioned tables just for the purpose of displaying table numbering.
    – SolidMark
    Commented Jun 3, 2021 at 17:51

1 Answer 1

1

OK, let's assume you want an alternate captioning command that only prints a table number, but no caption and doesn't go into the list of tables.

Let's look at how \caption is defined, part is in the LaTeX kernel:

\def\caption{%
   \ifx\@captype\@undefined
     \@latex@error{\noexpand\caption outside float}\@ehd
     \expandafter\@gobble
   \else
     \refstepcounter\@captype
     \expandafter\@firstofone
   \fi
   {\@dblarg{\@caption\@captype}}%
}
\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
    \normalsize
    \@makecaption{\csname fnum@#1\endcsname}{\ignorespaces #3}\par
  \endgroup}

and part lives in the document class (the base classes are all pretty similar in their implementation):

\long\def\@makecaption#1#2{%
  \vskip\abovecaptionskip
  \sbox\@tempboxa{#1: #2}%
  \ifdim \wd\@tempboxa >\hsize
    #1: #2\par
  \else
    \global \@minipagefalse
    \hb@xt@\hsize{\hfil\box\@tempboxa\hfil}%
  \fi
  \vskip\belowcaptionskip}

This is going to be fairly easy to simplify for your needs. We don't need to worry about dealing with optional arguments or any arguments at all. Instead, we'll create a \nocaption command which just prints the table number and nothing else. As an added bonus, our formatting can be a little better than what's on offer with \caption{}.

First step is we'll keep the check to make sure we're inside a float when we call \caption:

\def\nocaption{%
   \if\@captype\@undefined
       \@latex@error{\noexpand\nocaption outside float}\@ehd
   \else
      \refstepcounter\@captype

There's no need to worry about the stuff surrounding parsing arguments, but we will have everything wrapped in an \if\fi so that we can recover ok from an error.

We don't need anything else from \caption or \@caption here. All we need to do is center the table number with the appropriate spacing

      \vskip\abovecaptionskip
      \hb#@xt@\hsize{\hfil\normalsize \@nameuse{\@captype} 
          \@nameuse{the\@captype}\hfil}
      \vskip\belowcaptionskip

\@nameuse is an internal macro in LaTeX that lets us access a command by name (it's identical to \csname\endcsname. The kernel is inconsistent about choosing \@nameuse over \csname\endcsname for reasons that I suspect no one knows but is most likely just different ages of the code).

Finally we can close out our \if\fi and our definition:

    \fi
  }

Now you can replace all your \caption{}s with \nocaption and get your desired output.

You must log in to answer this question.

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