I'm a newer user of the detailed formatting capabilities in Latex…
I'm having a really hard time figuring out titlesec documentation to do the necessary formatting that I require. Unfortunately, the online examples are not helping me much…
- I'm working in an article class.
- I need uppercase section labels, with the section number including the subsection (e.g. 1.0 INTRODUCTION . . . . . . pg#)
- Subsections and subsubsections should also be included, indented respectively, with nothing beyond the default behavior
- Appendices are not to be uppercase and should be labeled "APPENDIX A – Appendix title . . . pg#)
- Finally, the Table of Contents header should be bold, centered, and uppercase.
Here's the code I have now:
\documentclass[12pt]{article}
\usepackage{blindtext}
\usepackage{titlesec}
\usepackage{titletoc}
\titleformat{\section} % command
[hang] % shape
{\normalsize\bfseries} % format
{\thesubsection} % label
{1em} % Spacing between label and title
{\MakeUppercase} % before code
\titlespacing{\section}% Set the spacing around the title
{0pt} % Left
{0pt} % Above
{0pt} % Below
\titlecontents{section}[2em]{\vspace{12pt}}{\normalfont\normalsize \contentslabel{2em}}{\hspace*{-2em} \MakeUppercase}{}{}
\titleformat{\subsection} % command
[hang] % shape
{\bfseries\normalsize} % format
{\thesubsection} % label
{1em} % Spacing between label and title
{} % before code
\titlespacing{\subsection}% Set the spacing around the title
{0pt} % Left
{0pt} % Above
{0pt} % Below
\titleformat{\subsubsection} % command
[runin] % shape
{\bfseries\normalsize} % format
{\thesubsubsection} % label
{1em} % Spacing between label and title
{} % before code
[.] % after code
\begin{document}
\tableofcontents
% Put this after TOC to keep single spacing in TOC:
\setlength{\parskip}{2ex} %--skip lines between paragraphs
\setlength{\parindent}{0pt} %--don't indent paragraphs
\vspace{4em} % Would normally be \newpage
\blinddocument
\end{document}
Sorry… I've spent five hours with minimal progress. I think I'm still learning a lot of the basics that is convoluting this for me…
Thanks,
Mike
Best Answer
Here's one way to do it:
The result:
Explanation
Center the ToC title.
I used the
etoolbox
package to patch\tableofcontents
:Formatting for section entries.
I defined two commands
\RegToCEntries
and\AppToCEntries
:The first one gives the desired formatting for regular sections and the seccond one, for sections in appendix; I added Appendix using
\contentspush
. The first command is used\AtBeginDocument
:and the second one is applied automatically after invoking
\appendix
:Suggestion
Your code sets
which suppresses spacing around section titles; I'd suggest you to use positive values in the last two arguments so section titles will have better vertical spacing with respect to the surrounding text.