For customization of any tableofcontents
-like command (ToC
, LoT
, or LoF
) I like the titletoc
package, as it offers the same friendly user interface of the titlesec
package.
The important part in the code below is
\titlecontents{table}
[0pt] % left margin
{\addvspace{.5cm}\itshape}% % above code (e.g vertical space)
{\contentsmargin{0pt} \bfseries % numbered entry format
TABLE~\thecontentslabel:\enspace%
\large}
{\contentsmargin{0pt}\large} % unnumbered entry format
{\titlerule*[.5pc]{.}\contentspage} % filler-page format (e.g dots)
[\addvspace{.5pc}] % below code (e.g vertical space)
I have used more spacing commands than you requested, but you can tweak them to suit your tastes. In particular, you can change \enspace
to any \hspace{}
command that you like.
% arara: pdflatex
% !arara: indent: {overwrite: true}
\documentclass{report}
\usepackage{titletoc}
\usepackage{hyperref}
\titlecontents{table}
[0pt] % left margin
{\addvspace{.5cm}\itshape}% % above code (e.g vertical space)
{\contentsmargin{0pt} \bfseries % numbered entry format
TABLE~\thecontentslabel:\enspace%
\large}
{\contentsmargin{0pt}\large} % unnumbered entry format
{\titlerule*[.5pc]{.}\contentspage} % filler-page format (e.g dots)
[\addvspace{.5pc}] % below code (e.g vertical space)
\begin{document}
\listoftables
\chapter{Test one}
\section{Test one one}
\begin{table}
\caption{Test table one}
\end{table}
\begin{table}
\caption{Test table one}
\end{table}
\begin{table}
\caption{Test table one}
\end{table}
\begin{table}
\caption{Test table one}
\end{table}
\begin{figure}
\caption{Test figure one}
\end{figure}
\chapter{Test two}
\section{Test two two}
\begin{table}
\caption{Test table two}
\end{table}
\begin{figure}
\caption{Test figure two}
\end{figure}
\end{document}
Here is another approach. What it does is to check at the end of the document the values of the figure
and table
counters, and add to the .aux
file a boolean flag setting depending on whether these values are zero or positive.
Then you have on next run \iffigures
and \iftables
which allow you to act conditionally.
In the code below, perhaps the \global
are not really needed, I didn't check.
See also a variant at bottom which does not use the figure
/table
counters because they might well be reset to zero due to document sectioning (as pointed out by egreg
in a comment).
\documentclass[10pt,twocolumn]{article}
\usepackage{lipsum}
\usepackage[margin=0.75in]{geometry}
\usepackage{float}
\floatstyle{boxed}
\restylefloat{figure}
\restylefloat{table}
\newif\iffigures
\newif\iftables
\makeatletter
\AtEndDocument {%
\if@filesw
\ifnum\value{figure}=\z@ % no figures
\immediate\write\@mainaux {\global\string\figuresfalse}%
\else
\immediate\write\@mainaux {\global\string\figurestrue}%
\fi
\ifnum\value{table}=\z@ % no tables
\immediate\write\@mainaux {\global\string\tablesfalse}%
\else
\immediate\write\@mainaux {\global\string\tablestrue}%
\fi
\fi
}
\makeatother
% for the purpose of testing
% this will make a MWE without tables
\long\def\IGNORE #1\ENDIGNORE{}
% uncomment to make a MWE with tables
% \let\IGNORE\empty
% \let\ENDIGNORE\empty
\begin{document}
\tableofcontents
%
\iffigures
\addcontentsline{toc}{section}{List of Figures}
\listoffigures
\fi
%
\iftables
\addcontentsline{toc}{section}{List of Table}
\listoftables
\fi
\section{First section}
\lipsum[\inputlineno]
\begin{figure}[H]\centering
\LaTeX\LaTeX
\caption{my figure}
\end{figure}
\lipsum[\inputlineno]
\begin{figure}[H]\centering
\LaTeX\TeX
\caption{another figure}
\end{figure}
\section{Second section}
\lipsum[\inputlineno]
\IGNORE
\begin{table}[H]\centering
\TeX\LaTeX
\caption{my table}
\end{table}
\ENDIGNORE
\lipsum[\inputlineno]
\IGNORE
\begin{table}[H]\centering
\TeX\TeX
\caption{another table}
\end{table}
\ENDIGNORE
\lipsum[\inputlineno]
\end{document}
Here is for a document with figures but no tables:
And if tables are present:
Three compilations needed.
Variant. I don't know to what extent patching \figure
and \table
as here is OK, depends perhaps on float related packages. At the worst I guess doing the patches immediately after \begin{document}
should be enough (at the end of preamble might not be enough if some package does stuff during At Begin Document).
\documentclass[10pt,twocolumn]{article}
\usepackage{lipsum}
\usepackage[margin=0.75in]{geometry}
\usepackage{float}
\floatstyle{boxed}
\restylefloat{figure}
\restylefloat{table}
\newif\iffigures
\newif\iftables
\makeatletter
\let\OLDfigure\figure
\def\figure {\figures@in@document\OLDfigure }
\let\OLDtable\table
\def\table {\tables@in@document\OLDtable }
\def\figures@in@document {%
\immediate\write\@mainaux {\global\string\figurestrue}%
\global\let\figures@in@document\empty
}
\def\tables@in@document {%
\immediate\write\@mainaux {\global\string\tablestrue}%
\global\let\tables@in@document\empty
}
\makeatother
% for the purpose of testing
% this will make a MWE without tables
\long\def\IGNORE #1\ENDIGNORE{}
% uncomment to make a MWE with tables
%\let\IGNORE\empty
%\let\ENDIGNORE\empty
\begin{document}
\tableofcontents
%
\iffigures
\addcontentsline{toc}{section}{List of Figures}
\listoffigures
\fi
%
\iftables
\addcontentsline{toc}{section}{List of Table}
\listoftables
\fi
\section{First section}
\lipsum[\inputlineno]
\begin{figure}[H]\centering
\LaTeX\LaTeX
\caption{my figure}
\end{figure}
\lipsum[\inputlineno]
\begin{figure}[H]\centering
\LaTeX\TeX
\caption{another figure}
\end{figure}
\section{Second section}
\lipsum[\inputlineno]
\IGNORE
\begin{table}[H]\centering
\TeX\LaTeX
\caption{my table}
\end{table}
\ENDIGNORE
\lipsum[\inputlineno]
\IGNORE
\begin{table}[H]\centering
\TeX\TeX
\caption{another table}
\end{table}
\ENDIGNORE
\lipsum[\inputlineno]
\end{document}
Best Answer
abntex2
is a class that loadsmemoir
as base class, which in turn provides starred versions of\tableofcontents
,\listoffigures
and\listoftables
, so using those macros removes the listing of the\listof...
in theToC
.The manual of
abntex2
explicitly mentions\listoffigures*
etc. on page 31 (however, in Portuguese)