2

List of Tables can be obtained by using listoftables commands. I wonder how to skip listoftables output if the document doesn't contain any table. Thanks

\documentclass[11pt]{article}

\begin{document}

\tableofcontents
\listoftables

\clearpage

\section{Dummy section 1}


\begin{table}[ht]
\caption{Dummy table 1}
\begin{center}
\begin{tabular}{|c|c|}

\end{tabular}
\end{center}
\label{tab:dum1}
\end{table}


\end{document}
lockstep
  • 250,273
MYaseen208
  • 8,587

1 Answers1

5

A possible way is to use the table counter

\ifnum\value{table} > 0 \listoftables \fi wouldn't work alone since the number of tables isn't known at that stage of processing. With the totcounter package one could register the total number of tables (which is written to the .aux file (so it's known in the second run finally). However, since the table counter might be in the reset list of chapter or section counter (depends on other settings), the (total) table counter might have a value of zero. Therefore I used (my ;-)) assoccnt package which counts the number of tables differently.

\documentclass[11pt]{article}
\usepackage{assoccnt}
\usepackage{totcount}

\newtotcounter{tottables}
\DeclareAssociatedCounters{table}{tottables}
\begin{document}

\tableofcontents
\ifnum\totvalue{tottables} > 0 
\listoftables
\fi

\IfFileExists{\jobname.lot}{%
 \listoftables
}{%
 % Does not exist
}

\clearpage

\section{Dummy section 1}


\begin{table}[ht]
%\caption{Dummy table 1}
\centering
\begin{tabular}{|c|c|}

\end{tabular}

\label{tab:dum1}
\end{table}


\end{document}