0

I must use the package \usepackage{titlesec}.

I have no problem with chapters and sections. However, when using \subsection{..}, the enumeration disappears.

Problem: My problem is that I want to have numbered subsections, but TexStudio show up unnumbered subsections in my document

Question: How to continue to have the subsection enumeration??

Following the code and the image of the pdf.


\documentclass[a4paper,12pt,twoside]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage[explicit,clearempty,nobottomtitles*]{titlesec} % pretty titles %\usepackage{titlesec} % pretty titles \usepackage{graphicx} % \resizebox \usepackage{xcolor} % \color, \textcolor \usepackage{colortbl} % \cellcolor \providecommand\phantomsection{} % just in case we're not using hyperref

% chapter style \definecolor{chapcolor}{rgb}{0.33,0.73,0} \newlength\Chapmargin \Chapmargin=10pt % extra margin at left of chapter title \newlength\Chaplineext \Chaplineext=1.5in % extension of "hanging" bottom line

% section style \newsavebox\Secbox % used to temporarily store the section label \titleformat{\section}% [hang]{}{}{0pt}% {% \sbox\Secbox{% temporarily save section label in order to measure it later %~ \color{white}\bfseries\rmfamily\LARGE\textsuperscript\S,\thesection% section number, in white over color, bold, roman, LARGE \color{white}\bfseries\rmfamily\LARGE\thesection% section number, in white over color, bold, roman, LARGE }% \def\arraystretch{2}% better vertical margins (for this table only) \arrayrulewidth=1pt% thicker lines (for this table only) \begin{tabular}{cl@{}}% no margin at the end \arrayrulecolor{chapcolor}% colored lines (for this table only) \hline% \hfill\cellcolor{chapcolor}\usebox\Secbox% &% \textcolor{chapcolor}{% needs to be outside of the parbox (and use \textcolor) or else it messes up line formatting \parbox[t]{\dimexpr \textwidth-\wd\Secbox-3\tabcolsep\relax}{% \raggedright% no stretching/hyphenation \LARGE\rmfamily\bfseries\MakeUppercase{#1}% chapter title (roman, bold, uppercase) }}% \% \end{tabular}% }

\begin{document}

\chapter{First Chapter}

\section{first Section}

\subsection{First Sub Section}

\subsubsection{First SubSub Section}

\subsection{Second Sub Section}

\end{document}

What I obtain:

enter image description here

and what I would like to obtain:

enter image description here

Please note that the last figure was obtained by deleting \usepackage{titlesec}

Leos313
  • 639
  • 1
    Your problem is that you want to have numbered subsections, but they show up unnumbered in your document? – Vincent Sep 16 '20 at 15:07
  • yes! even with the code in this answer here (https://tex.stackexchange.com/questions/442101/how-to-fill-section-on-titlesec) my laptop continue to give me pdf with NO numbering. Can be something like the new version of titlesec? – Leos313 Sep 16 '20 at 15:09
  • If I compile your example, the output document has numbered subsections. Is your installation up-to-date? – Vincent Sep 16 '20 at 15:14
  • today I have just re-installed texstudio and texlive-full. And I have this problem that I can resolve. My version should be the last one, right? yours can be older – Leos313 Sep 16 '20 at 15:17
  • 1
    I would guess you have a very old installation and this old 2016 bug https://tex.stackexchange.com/questions/299969/titlesec-loss-of-section-numbering-with-the-new-update-2016-03-15 – David Carlisle Sep 16 '20 at 15:18
  • your log should show Package: titlesec 2019/10/16 v2.13 Sectioning titles – David Carlisle Sep 16 '20 at 15:21
  • how to update it? – Leos313 Sep 16 '20 at 15:22
  • Done, problem solved. I have just posted the solution found thaks to your comments – Leos313 Sep 16 '20 at 15:32

1 Answers1

1

Thanks to the comments, it was clear that I face an OLD bug of titlesec. The problem is solved with the new version. For more information see the question and the answer here.

FOR SOLVING THE BUG:

Download the right (no buggy) .sty and substitute the old one.

For Ubuntu 18.04 with texlive:

sudo wget http://mirrors.ctan.org/macros/latex/contrib/titlesec/titlesec.sty -O /usr/share/texlive/texmf-dist/tex/latex/titlesec/titlesec.sty

For other Linux distros:

First, run locate /titlesec.sty then adapt the previous code.

Leos313
  • 639
  • 1
    directly writing the files to the managed directories is very fragile and could get over-written at any update. Which texllive are you running is there really not a newer version available via the standard apt update mechanisms? – David Carlisle Sep 16 '20 at 16:35
  • texliveonfly 1.2 and texstudio 2.12.14 – Leos313 Sep 16 '20 at 18:46
  • 1
    Old and short lived (just a few days, because I fixed quickly). The odd thing is some Linux distributions included the buggy version for months. – Javier Bezos Sep 17 '20 at 16:36