目次の章番号を非表示にするにはどうすればいいですか?

目次の章番号を非表示にするにはどうすればいいですか?

番号付けの深さを設定できることは知っています\setcounter{secnumdepth}{1}が、章ではなくセクションとサブセクションのみに番号を付ける必要があります。これをワンライナーで実行できますか? 同様の問題に対する回答をいくつか見たことがありますが、このような単純なタスクにしては複雑すぎるようです。

答え1

私たちの仲間のユーザーである jfbu による非常に豪華で洗練されたパッケージが、etocこれを実現する手段を提供します。

これを使用することで、\etocsetlevel{level name}{level value}構造レベルをシフトすることが可能です(例:)からより低いレベル(例えばサブパラグラフ) に設定し、tocdepthカウンターを上記の値に制限します。

\etocsetlevel{chapter}{6}そして\setcounter{tocdepth}{4}仕事をするでしょう。

これは、ドキュメントのメイン部分ではなく、目次内の表現にのみ影響します。

ToC 内のスペースの調整が必要になる場合があります。これは、パッケージ\cft....のさまざまなコマンドを使用して実現できますtocloft(ここでは使用されていません)

secnumdepthとカウンターの違いに注意してくださいtocdepth:

  • tocdepthpart目次に表示されるレベル(-1~6)を決定しますsubparagraph(標準のLaTeXクラスの場合)
  • secnumdepthメイン文書内のどのレベルにセクション番号を割り当てるかを決定します。

\documentclass{book}
\usepackage{etoc}       
\setcounter{secnumdepth}{4}% Show down to subsubsection
\begin{document}    

\setcounter{tocdepth}{4} %for main TOC, only show chapter/section
\etocsetlevel{part}{6} % push away the chapters
\etocsetlevel{chapter}{6}  % push away the chapters, beyond toc depth (4 )
\tableofcontents
\chapter{this is chapter heading}    
  \section{this is section heading}
  \subsection{this is subsection heading}
  \subsubsection{this is subsubsection heading}
  \subsubsection{this is another subsubsection heading}
  \chapter{another chapter}
  \section{this is yet another section} 
\end{document}

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

編集

章番号のみを削除する必要がある場合 (ただし、セクション 1.1 などは削除しない)、\@chapterコマンドをパッチする方法が 1 つあります。

\documentclass{book}
\usepackage{tocloft}
\setcounter{secnumdepth}{4}% Show down to subsubsection

\setlength{\cftchapindent}{-20pt}% Just some value...

\usepackage{xpatch}

\makeatletter
\xpatchcmd{\@chapter}{\addcontentsline{toc}{chapter}{\protect\numberline{\thechapter}#1}}{%
                      \addcontentsline{toc}{chapter}{\protect\numberline{}#1}}{\typeout{Success}}{\typeout{Failed!}}
\makeatother

\begin{document}    

\tableofcontents

%\renewcommand{\thechapter}{\arabic{chapter}}
\chapter{First chapter}
  \section{First section}
  \subsection{First subsection}
  \subsubsection{Even more in the basement}
  \chapter{Another chapter}
  \section{this is yet another section} 
\end{document} 

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

答え2

おそらく、KOMA-Script クラスを使用できるでしょう:

\documentclass[emulatestandardclasses]{scrbook}
\renewcommand\addchaptertocentry[2]{\addtocentrydefault{chapter}{}{#2}}

\usepackage{blindtext}% dummy text
\begin{document}
\tableofcontents
\Blinddocument
\Blinddocument
\end{document}

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

答え3

解決策titletoc:

    \documentclass[11pt, a4paper]{book}

    \usepackage[utf8]{inputenc}
    \usepackage[T1]{fontenc}
    \usepackage{fourier}
    \usepackage{microtype}

    \usepackage{titletoc}%

      \titlecontents{chapter}[0em]{\lsstyle\smallskip\bfseries}%\vspace{1cm}%
      {}%
      {\itshape\bfseries}%numberless%
      {\hfill\contentspage}[\medskip]%
    %
     \titlecontents{section}[4.25em]{\smallskip}%
      {\contentslabel[\thecontentslabel]{2em}}%numbered
      {\hspace*{-1em}}%numberless
      {\hfill\contentspage}[\smallskip]%
    %
     \titlecontents{subsection}[7em]{}%
      {\contentslabel[\thecontentslabel]{2.75em}}%numbered
      {\hspace*{-1em}}%numberless
      {\hfill\contentspage}[\smallskip]

    \begin{document}
    \tableofcontents

    \chapter*{INTRODUCTION}
    \addcontentsline{toc}{chapter}{INTRODUCTION}

    \chapter{A NICE FIRST CHAPTER}

    \section{An Introductory Section}
    \newpage
    \section{Another Section}
    \subsection{A Boring Subsection }

    \end{document}

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

関連情報