# Equivalent of titlesec with sectsty

I am using

 \usepackage{titlesec}
\usepackage{tipa}
\titleformat{\section}
{\normalfont\huge\bfseries}
{\thesection\hskip 10pt\textpipe\hskip 10pt}
{0pt}
{}


for formatting my sections. The only problem is that it has issues with hyperref and I cannot link the sections nicely.

See here Table of contents points to wrong page for sections, not for subsection for the original problem and a MWE.

I just want the same formatting (a pipe before the section name) with another package (sectsty or others). Is that possible?

Thanks!

You need no package for this:

\documentclass{article}

\usepackage{hyperref}

\makeatletter
\renewcommand{\@seccntformat}[1]{%
\csname the#1\endcsname % the number
\hspace{10pt}$|$\hspace{10pt}% space, bar, space
}
\makeatother

\begin{document}

\tableofcontents
\newpage

\section{Here's the section title}

\end{document}


This will add the vertical bar also in subsection titles, but it's possible to limit it just to sections.

\documentclass{article}

\usepackage{hyperref}

\makeatletter
\renewcommand{\@seccntformat}[1]{%
% the number
\csname the#1\endcsname
% the formatting for the current level
}
\makeatother
\newcommand{\formatsection}{%
\hspace{10pt}$|$\hspace{10pt}% space, bar, space
}

\begin{document}

\tableofcontents
\newpage

\section{Here's the section title}

\subsection{Here's a subsection}

\end{document}


If you don't define \format<level>, the usual \quad will be added between the number and the title.

• Can you please tell me on how to limit it to the sections? – elaRosca Jun 17 '14 at 14:14
• Is it possible for me to also make the section names bigger? – elaRosca Jun 17 '14 at 14:19
• @elaRosca I added the code for having the pipe only in sections. For making the font larger, use sectsty. But avoid it, the font size is already quite large. – egreg Jun 17 '14 at 14:22
• Thank you. The issue is that now it does not start a new page when a new section starts.I am using \newcommand{\sectionbreak}{\clearpage} for doing that. – elaRosca Jun 17 '14 at 14:28
• @elaRosca Defining \sectionbreak will do nothing; do \usepackage{etoolbox} and \preto{\section}{\clearpage} if you really want to start a new page with each section. But judging from the context, you seem to be wanting the report class and use \chapter instead of \section. – egreg Jun 17 '14 at 14:33