Remove section number but display the number in table of contents in LaTeX

丶灬走出姿态 提交于 2019-12-14 02:22:32

问题


I am new to LateX. I know how to remove the section number by using \section*{heading} instead of \section{heading}. But when I display the section heading in the Table of Contents , it does not print the section number. I want the section number to be displayed before "Introduction to Project" and "Introduction to company" in the Table of Contents shown below.


回答1:


The titlesec package is very useful to modify your chapter and section titles. An important command is \titleformat, which is described on page 4 of the manual. The command looks like this:

\titleformat{⟨command⟩}[⟨shape⟩]{⟨format⟩}{⟨label⟩}{⟨sep⟩}{⟨before-code⟩}[⟨after-code⟩]

here, we want to change the \section command, i.e. <command> is \section. The <shape> setting is optional - we'll just leave the default value. In <format>, we define how the title shall be formatted. The default for \section is \normalfont\Large\bfseries, so we'll set it to that. If you want to change the appearance, you can do that here. Now, the interesting part: the <label> is the section number - we don't want to print it, so we'll lave that field empty. The <sep> is the separation between label and title, which should be zero if we don't have a label. Finally, with <before-code> and <after-code> we can add any code which should be run before or after printing the title. We don't need that either. So, our command is:

\titleformat{\section}{\normalfont\Large\bfseries}{}{0pt}{}

Here, a demonstration of that:

\documentclass{article}

\usepackage{titlesec}
\titleformat{\section}{\normalfont\Large\bfseries}{}{0pt}{}

\begin{document}

\tableofcontents

\section{Introduction to Company}
This is the company.

\section{Introduction to Project}
My project is very nice.

\end{document}



来源:https://stackoverflow.com/questions/39833087/remove-section-number-but-display-the-number-in-table-of-contents-in-latex

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!