3

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!

1 Answer 1

6

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}

enter image description here

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
  \@ifundefined{format#1}{\quad}{\csname format#1\endcsname}
}
\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.

enter image description here

5
  • Can you please tell me on how to limit it to the sections?
    – elaRosca
    Commented Jun 17, 2014 at 14:14
  • Is it possible for me to also make the section names bigger?
    – elaRosca
    Commented Jun 17, 2014 at 14:19
  • 1
    @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
    Commented Jun 17, 2014 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
    Commented Jun 17, 2014 at 14:28
  • 2
    @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
    Commented Jun 17, 2014 at 14:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .