1

I found about the titlesec package to format titles of sections and subsections.

Currently based on a snippet I found on the web the following snippet works nicely, but the section numbering is turned off. How do turn on section numbering?

With my current latex settings, I get the following document with the sections and subsections not numbered as below.

enter image description here

    \documentclass[11pt]{article}
    \usepackage[utf8]{inputenc}
    \usepackage[T1]{fontenc}
    \usepackage{graphicx}
    \usepackage{grffile}
    \usepackage{longtable}
    \usepackage{wrapfig}
    \usepackage{rotating}
    \usepackage[normalem]{ulem}
    \usepackage{amsmath}
    \usepackage{textcomp}
    \usepackage{amssymb}
    \usepackage{capt-of}
    \usepackage{hyperref}
    \usepackage{minted}
    \usepackage[margin=0.8in]{geometry}
    \usepackage{parskip}
    \usepackage{graphicx}
    \usepackage{mdframed}
    \newcommand\mycommfont[1]{\footnotesize\ttfamily\textcolor{blue}{#1}}
    \SetCommentSty{mycommfont}
    \usepackage{tikzsymbols}
    \usepackage{needspace}
    \hypersetup{colorlinks=true,linkcolor=blue}
    \usepackage{multicol}
    \setlength{\columnsep}{1cm}
    \usepackage{titling}
    \usepackage{xcolor}
    \usepackage{titlesec}
    \titleformat{\section}[block]{\color{black}\normalfont\sffamily\Large\bfseries\filcenter}{}{0.3em}{}
    \titleformat{\subsection}[block]{\color{black}\normalfont\sffamily\large\bfseries\filcenter}{}{0.3em}{}
    \setlength{\headsep}{0pt}
    \setlength{\topskip}{0pt}
    \setlength{\topmargin}{0pt}
    \setlength{\topsep}{0pt}
    \setlength{\partopsep}{0pt}
    \setlength{\droptitle}{-5em}     % Eliminate the default vertical space
    \author{John Doe}
    \date{}
    \title{Dummy Title}
    \hypersetup{
     pdfauthor={John Doe},
     pdftitle={Dummy Title},
     pdfkeywords={},
     pdfsubject={},
     pdfcreator={Emacs 25.3.1 (Org mode 9.1.7)}, 
     pdflang={English}}
    \begin{document}

    \maketitle
    \tableofcontents

    \begin{multicols}{2}
    \section{Introduction}
    \label{sec:orgbe11d3e}

    \subsection{Lorem}
    \label{sec:orgcfab93a}

    Et nam fugit torquatos reprehendunt, id malis scripta eum. Duo ea nisl dicat. Ea ancillae mentitum sadipscing per, ad harum dolore has. An pri quod case clita. Exerci posidonium per no, ut ius lobortis laboramus reprehendunt.

sed ea. Sint ludus eu mea, in postulant honestatis interpretaris per. In vix natum mentitum disputationi, natum sapientem ne duo.
    \section{Ipsum}
    \label{sec:orgc59abd3}
    Et nam fugit torquatos reprehendunt, id malis scripta eum. Duo ea nisl dicat. Ea ancillae mentitum sadipscing per, ad harum dolore has. An pri quod case clita. 

\end{multicols}
\end{document}
  • 1
    Without testing (you did not provide testable code): \filcenter#1 – Johannes_B Apr 22 '18 at 5:59
  • @Johannes_B Please see edit. I have edited the question to make it more clear. – smilingbuddha Apr 22 '18 at 10:50
  • \filcenter\thesection Sorry, it was before my first cofee this morning. – Johannes_B Apr 22 '18 at 11:05
2

As Johannes_B already said in his comment ages before I posted this answer:

\documentclass[11pt]{article}

\usepackage{xcolor}
\usepackage{titlesec}
\titleformat{\section}[block]{\color{black}\normalfont\sffamily\Large\bfseries\filcenter\thesection\space}{}{0.3em}{}
\titleformat{\subsection}[block]{\color{black}\normalfont\sffamily\large\bfseries\filcenter\thesubsection\space}{}{0.3em}{}

\begin{document}

\section{Introduction}

\subsection{Lorem}

Et nam fugit torquatos reprehendunt, id malis scripta eum. Duo ea nisl dicat. Ea ancillae mentitum sadipscing per, ad harum dolore has. An pri quod case clita. Exerci posidonium per no, ut ius lobortis laboramus reprehendunt.

sed ea. Sint ludus eu mea, in postulant honestatis interpretaris per. In vix natum mentitum disputationi, natum sapientem ne duo.

\section{Ipsum}
Et nam fugit torquatos reprehendunt, id malis scripta eum. Duo ea nisl dicat. Ea ancillae mentitum sadipscing per, ad harum dolore has. An pri quod case clita. 

\end{document}
  • Never too lazy to upvote :-) – Johannes_B Apr 22 '18 at 11:44

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.