3

How can I include list of figures, list of tables etc. in the table of content? Additionally I would like to have Roman numerals for the page with the table of contents, list of figures, list of tables AND (!!!) section A. Beginning with section B, I would like to have Arabic numerals as page numbers in the header. How should I modify the code that I have provided? Thanks a lot in advance!

\documentclass[12pt,oneside,a4paper]{article}
    \usepackage{amsmath, amssymb, graphicx, pgfplots, tikz, booktabs, tabularx, float, pgfplotstable, fancyhdr}
    \allowdisplaybreaks
    \usepackage[font=small,labelfont=bf,labelsep=colon]{caption}
    \special{papersize=210mm,297mm}
    \usepackage[left=40mm, top=30mm, right=20mm, bottom=20mm, headsep=12.5mm, headheight=3mm]{geometry}
    \pagestyle{fancy}
    \renewcommand{\headrulewidth}{0.0pt}
    \lhead{}
    \chead{}
    \rhead{\makebox[0pt][r]{Title of topic}
           \hspace*{1.66667em}
           \thepage}
    \lfoot{}
    \cfoot{}
    \rfoot{}
    \usepackage{setspace}\onehalfspacing
    \setstretch{1.3}
    \renewcommand\contentsname{Table of Contents}
    \begin{document}
    \newpage
    \tableofcontents
    \newpage
    \listoffigures
    \newpage 
    \listoftables 
    \clearpage 
\section*{Section A}
\section{Section B}

\end{document}
  • 2
    For your first question you can add \addcontentsline{toc}{section}{Section A} and similar before each non-numbered section. For LOF, LOT, etc. you can even load the package tocbibind which automates that. – karlkoeller Aug 30 '13 at 9:20
  • 2
    For your second question, adding \pagenumbering{Roman} before the TOC and then \pagenumbering{arabic} before the sections start is enough? – karlkoeller Aug 30 '13 at 9:25
2

Here's some code. Note that I removed all packages that are unnecessary for the example.

\documentclass[12pt,oneside,a4paper]{article}

\usepackage[
 left=40mm,
 top=30mm,
 right=20mm,
 bottom=20mm,
 headsep=12.5mm,
 headheight=14.5pt, %%% 3mm is too small
 heightrounded
]{geometry}

\usepackage{fancyhdr,xpatch}

\pagestyle{fancy}
\renewcommand{\headrulewidth}{0.0pt}
\fancyhf{}
\fancyhead[R]{Title of topic --- \thepage}

\makeatletter
\let\ORI@section\section
\renewcommand{\section}{\@ifstar\s@section\ORI@section}
\newcommand{\s@section}[1]{%
  \ORI@section*{#1}
  \csname phantomsection\endcsname % for hyperref
  \addcontentsline{toc}{section}{#1}
}
\xpatchcmd{\tableofcontents}{\section}{\ORI@section}{}{} % toc not in toc
\makeatother

\begin{document}
\pagenumbering{roman}

\tableofcontents
\clearpage

\listoffigures
\clearpage

\listoftables 
\clearpage

\section*{Section A}

\clearpage
\pagenumbering{arabic}

\section{Section B}

\end{document}

The code redefines \section so that \section* will automatically add it to the table of contents. There's only one catch: \tableofcontents uses \section*, so it has been patched in order to use the original version of the command.

Some points to note about your original code:

  1. \special is not needed, because geometry takes care of it
  2. the headheight you specified is too small
  3. \makebox[0pt][r]{Title of topic} does nothing more than the simple Title of topic, because fancyhdr uses right alignment anyway there; I also added a dash to separate the title from the page number.
  4. \onehalfspacing is countermanded by \setstretch{1.3}; if you can, avoid increasing the leading.

enter image description here


If you want to reduce the spacing between section titles, add the following line

\xpatchcmd{\l@section}{1.0em}{0.5ex}{}{}

immediately before \makeatother in the given code. Adjust 0.5ex to what suits you. For the image, I added two subsections in order to give the flavor.

enter image description here

  • Thank you very much, it works perfectly, is it somehow possible to reduce the space between List of Figures and List of Tables and set the same length which is automatically set between the points, ket's say, 1.2.1 and 1.2.2 etc. within the section 1 – ajafarov Aug 30 '13 at 14:32
  • @ajafarov I added the requested trick – egreg Aug 30 '13 at 15:31
  • Hello, one more question, if I want to add one more page before the table of contents and I dont want to see any page number on it, how should I modify your code? Thanks! – ajafarov Sep 2 '13 at 9:50
  • @ajafarov The page number is not typeset if you use \thispagestyle{empty} – egreg Sep 2 '13 at 10:09
  • I appreciate it, it works perfectly! Is it also possible to change the margins for the left, right, top and bottom, so that the cover page which is now now without page number has individual margins? The document will include then two different types of margins. Is it possible? – ajafarov Sep 2 '13 at 10:43

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.