3

I have the following MWE:

\documentclass{article}
\usepackage{lipsum}
\usepackage{titlesec}
\setcounter{secnumdepth}{5}
\begin{document}
\section{Section}
\lipsum[1]
\subsection{Subsection}
\lipsum[2]
\subsubsection{Subsubection}
\lipsum[3]
\paragraph{Paragraph}
\lipsum[4]
\subparagraph{Subparagraph}
\lipsum[5]
\end{document}

However, there is a lot of horizontal space before and after each Section/paragraph headings. the subparagraph also has an unnecessary indentation.

1 Answers1

3

Included both horizontal spaces (after heading number) and spacing before and after titles without using sectsty. Change the formatting commands in \titleformat as required and the horizontal spacing between the number and heading.

\documentclass{article}
\usepackage{lipsum}
\usepackage{titlesec}
\usepackage[T1]{fontenc}    % EDIT - allows multiple font styles %

% Change horizontal space in titles here % [block]{Formatting command}{Put `the' in front of paragraph etc}{Space after number}{} \titleformat{\section}[block]{\large\scshape\bfseries}{\thesection.}{0.2em}{} \titleformat{\subsection}[block]{\large\scshape}{\thesubsection}{0.3em}{}

% EDIT - to show the multiple font styles being applied due to package fontenc \titleformat{\subparagraph}[block]{\scshape\bfseries}{\thesubparagraph}{0.3em}{}

% Change vertical space \beforetitle and \aftertitle here, as above use \subparagraph etc. % 0pt is how far from the left margin the entry is placed

\newcommand\aftertitle{2ex} \newcommand\beforetitle{0.7ex}

\titlespacing{\section}{0pt}{\aftertitle}{\beforetitle} \titlespacing{\subsection}{0pt}{\aftertitle}{\beforetitle} \titlespacing{\subsubsection}{0pt}{\aftertitle}{\beforetitle} \titlespacing{\paragraph}{0pt}{\aftertitle}{\beforetitle} \titlespacing*{\subparagraph}{0pt}{\aftertitle}{\beforetitle}

\setcounter{secnumdepth}{5} \begin{document} \section{Section} \lipsum[1] \subsection{Subsection} \lipsum[2] \subsubsection{Subsubection} \lipsum[3] \paragraph{Paragraph} \lipsum[4] \subparagraph{Subparagraph} \lipsum[5] \end{document}

How it looks (EDIT - updated to include fontenc package for subparagraph formatting):

enter image description here

  • Thanks! Do you know how to change the subparagraph to small caps in boldface so that they look different? – user3236841 Aug 09 '21 at 01:58
  • Sorry about the delay, I'm probably in a different time zone. To have multiple fonts, you need to add \usepackage[T1]{fontenc} to your preamble and then use \titleformat{\subparagraph}[block]{\large\scshape\bfseries}{\thesubparagraph}{0.3em}{} where 0.3em is the horizontal space of your choosing. The fontenc package prevents the final font style from overriding the previous ones. –  Aug 09 '21 at 11:43
  • I've edited my answer so the MWE should do as you require, hope it helps. –  Aug 09 '21 at 11:52
  • 1
    thanks! i see, fontenc is needed. I wish I could rate this answer up one more time! – user3236841 Aug 09 '21 at 12:37