从 titlesec 打开此宏的章节编号

从 titlesec 打开此宏的章节编号

我发现了有关 titlesec 包用于格式化章节和小节标题的信息。

目前,根据我在网上找到的一个代码片段,以下代码片段运行良好,但章节编号已关闭。如何打开章节编号?

使用我当前的乳胶设置,我得到以下文档,其中的章节和小节未按如下所示编号。

在此处输入图片描述

    \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

正如 Johannes_B 所说他的评论 年龄在我发表这个答案之前:

\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}

相关内容