3

I'm writing a paper in LaTeX, and I wanted to use titlesec for custom title styling, when I tried to apply my custom styling to my chapter title, it worked.

However, when I tried to apply custom styling to my section, the section-title disappeared like in the following picture:

This is the code in my header:

\documentclass[a4paper,12pt,oneside]{book}
%header information
\usepackage{blindtext, array, color}
\definecolor{gray75}{gray}{0.75}
\newcommand{\hsp}{\hspace{20pt}}
\usepackage[explicit]{titlesec}

\titleformat{\chapter}[block]{\Huge\bfseries}{\color{gray75}\thechapter}{20pt}{\begin{tabular}[t]{@{\color{gray75}\vrule width 2pt}>{\hsp}l}#1\end{tabular}}

\titleformat{\section}[block]
{\Large\bfseries}{\color{gray75}\thesection}{12pt}{}

\usepackage{graphicx}
\usepackage{amsmath}
\usepackage[style=ieee,backend=bibtex]{biblatex}
\usepackage[paper=a4paper,left=25mm,right=25mm,top=25mm,bottom=25mm]{geometry}
\usepackage{setspace}
\usepackage{fancyhdr} 
\renewcommand{\headrulewidth}{0pt}
\fancyhf{}
\cfoot{\thepage}
\pagestyle{fancy} 
\setstretch{1.3}
\DeclareGraphicsExtensions{.pdf,.png,.jpg}
\newcommand{\abbrlabel}[1]{\makebox[3cm][l]{\textbf{#1}}}
\newenvironment{abbreviations}{\begin{list}{}{\renewcommand{\makelabel}{\abbrlabel}}}{\end{list}}
\addbibresource{references.bib}

\begin{document}

I don't understand what is happening!

  • 1
    Welcome to TeX.SX! Since you use the explicit option, the last argument in \titleformat{\section} should be {#1}, rather than {} – egreg Apr 2 '17 at 9:45
  • Thank you! It worked, I totally looked over that, thanks for the quick answer, what a great community! – Diederik Apr 2 '17 at 9:55
  • We do our best for helping! Welcome again! – egreg Apr 2 '17 at 9:55
2

Since you're using explicit, the code for the section should be

\titleformat{\section}[block]
{\Large\bfseries}{\color{gray75}\thesection}{12pt}{#1}

However, I usually prefer not using the option: it's easier if you define a suitable one argument macro and keep the code in a different place, reducing clutter.

\documentclass[a4paper,12pt,oneside]{book}

\usepackage{color}
\usepackage{array}
\usepackage{titlesec}

\definecolor{gray75}{gray}{0.75}

\titleformat{\chapter}[block]
  {\Huge\bfseries}
  {\color{gray75}\thechapter}
  {20pt}
  {\formatchapter}

\titleformat{\section}[block]
  {\Large\bfseries}
  {\color{gray75}\thesection}{12pt}
  {}

\newcommand{\formatchapter}[1]{%
  \begin{tabular}[t]{@{\color{gray75}\vrule width 2pt}>{\hspace{20pt}}l}
  #1
  \end{tabular}%
}

\begin{document}

\chapter{State of the art}

\section{First section}

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.