1

On this example, the list of tables is being shown, but there are no tables on it to show, then, it should not appear unless there are tables to list.

\documentclass[12pt]{memoir}

\begin{document}

\listoftables*

Contents.

\end{document}

enter image description here

How to hide the \listoftables* automatically if/when there are no tables in my document?

1

you can redefine mem@listoftables, e.g. using pdffilesize to test for emptiness of \jobname.lot, see answer to "Checking whether a file is empty?". Commment out the table to see also the list of tables disappear.

\documentclass[12pt]{memoir}

\def\firstoftwo#1#2{#1}
\def\secondoftwo#1#2{#2}
\def\iffileexist#1{%
  \expandafter\ifx\expandafter&\pdffilesize{#1}&%
    \expandafter\secondoftwo
  \else
    \expandafter\firstoftwo
  \fi
}
\def\iffileempty#1{%
  \ifnum0\pdffilesize{#1}>0
    \expandafter\secondoftwo
  \else
    \expandafter\firstoftwo
  \fi
}

\makeatletter
  \@namedef{mem@listoftables}#1{%
    \ensureonecol
    \par
    \begingroup
    \iffileempty{\jobname.lot}{\relax}{%
      \@nameuse{@lotmaketitle}
      \if#1
        \ifmem@em@starred@listof\else
          \phantomsection
          \addcontentsline{toc}{chapter}{List of Tables}
        \fi
      \fi
      \parskip\cftparskip
      \@nameuse{cftlotbeforelisthook}%
    \@input{\jobname.lot}%
   }
    \if@filesw
      \AtEndDocument{%
        \expandafter\ifx\csname tf@lot\endcsname\relax
          \expandafter\newwrite\csname tf@lot\endcsname
          \immediate\openout \csname tf@lot\endcsname \jobname.lot\relax
        \fi
      }%
    \fi
      \@nobreakfalse
      \@nameuse{cftlotafterlisthook}%
    \endgroup
    \restorefromonecol}
\makeatother

\begin{document}

\listoftables*

Contents.

\begin{table}
\caption{test tabel caption}
test table
\end{table}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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