目次からセクション番号を削除する

目次からセクション番号を削除する

目次からセクション番号を削除するにはどうすればよいですか? 私のドキュメントクラスは次のとおりですarticle:

\documentclass[a4paper]{article}
\begin {document}
\tableofcontents
\section{one}
test text number one
\section{two}
test text number two
\end{document}

ここに画像の説明を入力してください

答え1

パッケージを使用すると、簡単に実行できますtitlesec/titlestoc。パッケージには、目次の番号付きセクションと番号なしセクション (番号なしセクションを追加する場合) の異なる書式設定を可能にするコマンドがあります。

\documentclass[a4paper]{article}
\usepackage{titletoc}

\begin {document}
\titlecontents{section}[0em]
{\vskip 0.5ex}%
{\scshape}% numbered sections formatting
{\itshape}% unnumbered sections formatting
{}%

\tableofcontents

\section{A First Section}
Test text number one. 

\section{Another Section}
Test text number two. 

\section*{An Unnumbered Section}
Test text number three. 
\addcontentsline{toc}{section}{An Unnumbered Section}
\end{document} 

ここに画像の説明を入力してください

答え2

\makeatletterAstrinusのアドバイスに従って、との間に次の2行のコードを追加することができます\makeatotheregregの回答、目次のエントリを変更します。手順は次のとおりです。

\documentclass[12pt, a4paper]{article}

\makeatletter
\let\latexl@section\l@section
\def\l@section#1#2{\begingroup\let\numberline\@gobble\latexl@section{#1}{#2}\endgroup}
\makeatother

\begin{document}
\tableofcontents
\newpage
\section{One}
test text number one
\section{Two}
test text number two
\end{document}

\newpage後にはが存在することを確認する必要があることに注意してください\tableofcontents

ここに画像の説明を入力してください

関連情報