使用“titlesec”包时继续枚举

使用“titlesec”包时继续枚举

我必须使用这个包裹\usepackage{titlesec}

我对章节和部分没有问题。但是,当使用时\subsection{..},枚举消失了。

问题:我的问题是我想要有编号的小节,但 TexStudio 在我的文档中显示未编号的小节

问题:如何继续进行子部分枚举?

遵循代码和 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}

我得到的是:

在此处输入图片描述

我想要得到的是:

在此处输入图片描述

请注意,最后一个数字是通过删除\usepackage{titlesec}

答案1

感谢评论,我清楚地知道我遇到了一个旧的错误titlesec。新版本解决了这个问题。有关更多信息,请参阅问题和答案这里

解决错误

下载正确的版本(没有错误).sty并替换旧的版本。

对于带有 texlive 的 Ubuntu 18.04:

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

对于其他 Linux 发行版:

首先,运行locate /titlesec.sty然后调整以前的代码。

相关内容