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:
\special
is not needed, because geometry
takes care of it
- the
headheight
you specified is too small
\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.
\onehalfspacing
is countermanded by \setstretch{1.3}
; if you can, avoid increasing the leading.
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.
Use the optional arguments to \caption
and/or \section
. EDITED to follow egreg's emphatic recommendation.
\documentclass[11pt]{article}
\usepackage{lipsum}
\begin{document}
\tableofcontents
\listoftables
\noindent\hrulefill
\section[\MakeUppercase{this is the first of two sections}]{this is the first of two sections}
\lipsum[4]
\section[\MakeUppercase{blah for blah}]{blah for blah}
\lipsum[3]
\begin{table}[ht]
\centering
\caption[\MakeUppercase{this is the table for this section}]{this is the table for this section}
\begin{tabular}{|c|c|}
\hline
This is & my table\\
\hline
\end{tabular}
\end{table}
\end{document}
Based on a follow-up query by the OP, here is a way to get just the LOT (but not the LOF) to automatically capitalize the table captions:
\documentclass[11pt]{article}
\usepackage{lipsum}
\let\svcaption\caption
\let\svtable\table
\def\table{\tablecaps\svtable}
\def\tablecaps{%
\renewcommand\caption[2][]{\svcaption[\MakeUppercase{##2}]{##2}}
}
\begin{document}
\tableofcontents
\listoffigures
\listoftables
\noindent\hrulefill
\section{blah for blah}
\begin{figure}[ht]
\centering
\framebox{My Figure}
\caption{this is the figure caption}
\end{figure}
\begin{table}[ht]
\centering
\caption{this is the table for this section}
\begin{tabular}{|c|c|}
\hline
This is & my table\\
\hline
\end{tabular}
\end{table}
\end{document}
Best Answer
By default there is a difference in what is passed as a contents-related entry and what is set within the document. Since you have little control over this when setting
\listoffigures
and\listoftables
, the example below intervenes by passing the LoF/LoT entries using\MakeUppercase
:You can activate this type of ToC-related formatting using
\CAPinToC
(or revert back to the original definition using\noCAPinToC
).