1

I am trying to add my List of Figures to my (ShareLaTeX) document, but it wont appear in my Table of Content. Here are my code:

\documentclass{article}
\usepackage[utf8]{inputenc}

\begin{document}

\maketitle
\thispagestyle{empty} 
\newpage

\section*{Abstract}
\addtocontents{toc}{~\hfill\textbf{Side}\par}
\addcontentsline{toc}{section}{\protect\numberline{}Forord}

\section*{Introduction}
\addcontentsline{toc}{section}{\protect\numberline{}Sammendrag}

\newpage
\tableofcontents 

\listoffigures   
\addcontentsline{toc}{section}{\protect\numberline{}Figures}

\listoftables      
\addcontentsline{toc}{section}{\protect\numberline{}Tables}
\newpage

\pagenumbering{arabic} ´

%Several sections here

\newpage
\appendix
\section{Appendix A}
\subsection{Appendix name}

\end{document}

So, my goal is to get something like this:

enter image description here

I already have the Figures and Tables, but I will also want to have the List of Equations and Appendices. Any help?

2

Regardless of how you create your contents tables, the following provides a means for insertion of ad-hoc content related to \sections within your document.

enter image description here

\documentclass{article}

\usepackage{xparse}
\newcommand{\setsectiontocentry}[1]{\def\sectiontocentry{#1}}
\let\oldsection\section
\makeatletter
\RenewDocumentCommand{\section}{ s o m }{%
  \IfBooleanTF{#1}
    {% \section*
      \oldsection*{#3}%
      \IfValueTF{#2}
        {\addcontentsline{toc}{section}{\protect\numberline{}#2}}% \section*[.]{..}
        {\@ifundefined{sectiontocentry}
           {\addcontentsline{toc}{section}{\protect\numberline{} #3}}%
           {\addcontentsline{toc}{section}{\protect\numberline{} \sectiontocentry}}%
         \let\sectiontocentry\relax
        }
        %{\addcontentsline\addcontentsline{toc}{section}{\protect\numberline{}%
           %\ifcsname sectiontocentry\endcsname
             %\sectiontocentry
           %\else
              %#3%
           %\fi 
         %}%
         %\let\sectiontocentry\relax
        %}% \section*{..}
    }
    {% \section
      \IfValueTF{#2}
        {\oldsection[#2]{#3}}% \section[.]{..}
        {\oldsection{#3}}% \section{..}
    }%
}
\makeatother

\begin{document}

\addtocontents{toc}{~\hfill\textbf{Side}\par}
\section*{Abstract}

\section*{Introduction}

\clearpage

\setsectiontocentry{ToC}
\tableofcontents

\setsectiontocentry{Figures}
\listoffigures

\listoftables

\clearpage
\pagenumbering{arabic}

\section{First section}
\section{Second section}
\section*[THIRD SECTION]{Third section}
\section{Last section}

\clearpage
\appendix
\section{First appendix}
\section{Second appendix}

\end{document}

Fundamentally, \section* commands don't make it into the ToC, nor does it allow for using an optional argument under \section*. The above preamble setup redefines the way \section functions to allow for the starred version \section* to have an optional argument and also insert that content into the ToC.

This works if you have access to \section, which you do in general. However, when you call \tableofcontents (and the like), a \section call is made on your behalf. For that, I've defined \setsectiontocentry{<section toc>} that will grab and place the appropriate <section toc> entry. Hopefully this is visualized in the above example.

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.