# Section Styles: Spacing, Font and Paragraph-Indentation

I am using sectsty to configure my section styles. I have read that perhaps titlesec is more powerful. A solution to my question below using titlesec is completely satisfactory.

Currently I am setting the fonts for section and subsection as follows.

\sectionfont{%                      % Change font of \section command
\noindent
\usefont{OT1}{phv}{b}{n}%       % bch-b-n: CharterBT-Bold font
\sectionrule{0pt}{0pt}{-5pt}{2pt}}

\subsectionfont{\noindent\usefont{OT1}{phv}{b}{n}}


I am then adjusting the spacing as follows.

\renewcommand\section{\@startsection{section}{1}{\z@}%
{\bigskipamount}%
{\bigskipamount}%
{\normalfont\large\bfseries\SS@sectfont}}
\renewcommand\subsection{\@startsection{subsection}{2}{\z@}%
{\bigskipamount}%
{\medskipamount}%
{\normalfont\normalsize\bfseries\SS@subsectfont}}


The template for this adjustment comes from this SE question: How to adjust the title spacing using sectsty package. A somewhat equivalent template for titlesec can be found from this SE question: Reducing spacing after headings.

Now my issue is the following. When I do this \renewcommand\section..., the first paragraph is indented. I don't want this. With titlesec, one can add an option noindentafter to the package call or use \titlespacing* to remove this indentation. See this SE question: Cancelling first-line indents after section titles. I cannot find similar things for sectsty, nor has experimentation succeeded.

Why am I using sectsty then? Well, I like the font and sectionrule options. I have not been able to get the same font using titlesec and the \titleformat option---which is somewhat confusing to me. The command \sectionrule appears to be specific to sectsty.

Thus I would like one of the following solutions.

1. Obtain the same font and section rule using titlesec.
2. Remove the indentation using sectsty.

Option (1) would be preferable, but Option (2) is acceptable.

Two MWEs. The first is set up for sectsty and the second for titlesec.

\documentclass[]{article}

\usepackage{sectsty}
\sectionfont{%                      % Change font of \section command
\noindent
\usefont{OT1}{phv}{b}{n}%       % bch-b-n: CharterBT-Bold font
\sectionrule{0pt}{0pt}{-5pt}{2pt}}
\subsectionfont{\noindent\usefont{OT1}{phv}{b}{n}}

\begin{document}

\section{Section Title}
This is not indented

\makeatletter
\renewcommand\section{\@startsection{section} {1}{\z@}%
{\bigskipamount}%
{\bigskipamount}%
{\normalfont\large\bfseries\SS@sectfont}}
\makeatother
\section{Next Section}
This is indented now \texttt{:frowning:}

\end{document}

\documentclass[]{article}

\usepackage{titlesec}
\titleformat{\section}
{\sffamily \normalsize \bfseries \usefont{OT1}{phv}{b}{n}}{\thesection}{1em}{}

\begin{document}

\section{Section Title}
This is not indented

\titlespacing{\section}
{0pt}
{\bigskipamount}
{\medskipamount}
\section{Next Section}
This is indented now \texttt{:frowning:}

\titlespacing*{\section}
{0pt}
{\bigskipamount}
{\medskipamount}
\section{Final Section}
But viola, it is no longer indented by adding \texttt{*}

\end{document}

• Could you please post a small complete code, not just snippets? Jan 6, 2021 at 19:32
• Sure :-) -- personally I didn't feel it was beneficial in this case, but if you're offering to help then I'll certainly provide what you ask for! :-) Jan 7, 2021 at 12:05

Here a way to do what you want with titlesec. I took the liberty to put \titlespacing in the preamble, to replace the Helvetica font with its clone TeX Gyre Heros, which has more glyphs and to reduce the spacing between section number and title to a half quad, which looks better, from my point of view.

\documentclass[]{article}

\usepackage[noindentafter]{titlesec}
\titleformat{\section}
{\usefont{T1}{qhv}{b}{n} \normalsize\boldmath}{\thesection}{0.5em}{}[{\titlerule[2pt]}]
\titlespacing{\section}
{0pt}
{\bigskipamount}
{\medskipamount}

\begin{document}

\section{Section Title}
This is not indented

\section{Next Section}%
This is \emph{not} indented now\texttt{:frowning:}

\section{Final Section}
But Viola, it is no longer indented by adding \texttt{*}

\end{document}


• Thank you. I was also able to get something similar to what you have done adjusting my MWEs, but not answer my query in full. I found that \usefont{OT1}{phv}{b}{n} was different in the sectsty version compared with titlesoc.[*] More importantly, though, the sectionrule is missing. It is this which I was unable to get in titletoc... [*I notice now that I didn't include this font in the MWE. Naturally one can simply copy+paste it from one to the other though. The issue is the missing rule, which I was unable to include] Jan 7, 2021 at 17:59
• Btw, I only included the \titlespacing stuff not in the preamble to demonstrate the different behaviour obtained by adding the * :) Jan 7, 2021 at 18:02
• @SamOT: I've added a rule command from titlesec – it has to be enclosed in a pair of braces, as its thickness is an optional argument, and it is placed in the last, optional argument of \titleformat Please see if it corresponds to what you want. Jan 7, 2021 at 19:37
• Thanks, it looks good! \sectionrule{0pt}{0pt}{-5pt}{2pt} has spacing arguments---search for "sectionrule" in tug.ctan.org/macros/latex/contrib/sectsty/sectsty.pdf. How should I add this in? It should be quite easy, no...? Maybe some box that can be moved? :/ Jan 7, 2021 at 22:10
• I thought you wanted a pair of rules, one above the title, the other below. To move the rule below a bit, you can add (in the final optional argument) a \vskip -some length before \titlerule. Jan 8, 2021 at 22:23