2

I've run into a problem where with using titlesec where my numberless sections are numbered. I took a look at a few other questions here, and the titlesec package help, where I saw the numberless option. However, with the suggestion that I noticed elsewhere here, i.e., to use \sectioning as the label it still produces a (wrong) number before the section name.

Can anyone give me a pointer here?

The present lines in my code read as:

\documentclass[12pt]{article}

\usepackage[a4paper,headheight=72pt,bottom=3cm]{geometry}
\usepackage[onehalfspacing]{setspace}

\usepackage[T1]{fontenc}
\usepackage{charter}
\usepackage[expert]{mathdesign}

\usepackage{amssymb,amsmath,array,floatflt,graphicx,marvosym,multirow,subcaption,siunitx,tabu,titlesec,tocbibind,tocloft}
\usepackage[font=small,hypcap]{caption}
\usepackage[authoryear,round,sort,nonamebreak]{natbib}
\usepackage[activate={true,nocompatibility},final,tracking=true,kerning=true,spacing=true,factor=1100,stretch=10,shrink=10]{microtype}
\usepackage{fancyhdr}

\pagestyle{fancy}

% keep this as last usepackage%
\usepackage[plainpages=false,pagebackref=true,colorlinks=true,linkcolor=blue,breaklinks]{hyperref}


\titleformat{\section}[hang]{\usefont{T1}{qhv}{b}{n}\selectfont}{}{0em}{\hspace{-0.4pt}\Large \thesection\hspace{0.6em}}

\titleformat{name=\section,numberless}[hang]{\usefont{T1}{qhv}{b}{n}\selectfont}{}{0em}{\hspace{-0.4pt}\Large \thesection\hspace{0.6em}}

And the endresult here is that all sections manage to change their font, size, and spacing, but that the ones that go by \section*{} are erroneously numbered.

I have my suspicion that I could do something by the optional titlesec commands, but I a not entirely confident in how they work.

Cheers

  • 1
    You have \thesection also in the numberless part. – egreg Nov 23 '13 at 11:43
3

Remove \thesection the definition for numberless:

\documentclass[12pt]{article}
\usepackage[T1]{fontenc}
\usepackage{titlesec}


\titleformat{\section}[hang]
  {\usefont{T1}{qhv}{b}{n}}
  {}
  {0em}
  {\hspace{-0.4pt}\Large \thesection\hspace{0.6em}}

\titleformat{name=\section,numberless}[hang]
  {\usefont{T1}{qhv}{b}{n}}
  {}
  {0em}
  {\hspace{-0.4pt}\Large}

\begin{document}

\section*{Unnumbered section}

Some text

\section{Numbered 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.