ToC의 섹션 제목에서 첫 번째 단어 제거

ToC의 섹션 제목에서 첫 번째 단어 제거
\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}

\begin{document}

\tableofcontents

\chapter{MyChapter}
\section{Term: Foo}
\section{foobar}
\section{Term: Bar}
\end{document}

내 섹션 제목 중 일부는 특별한 단어로 시작됩니다. 내 예에서는 "Term: "이라는 텍스트입니다. 물론 이것은 전체 제목의 일부입니다. 하지만 ToC에는 표시되지 않기를 바랍니다.

현재 목차:

1 MyChapter               3
  1.1 Term: Foo ..........3
  1.2 foobar .............3
  1.3 Term: Bar ..........3

예상되는 목차:

1 MyChapter               3
  1.1 Foo ................3
  1.2 foobar .............3
  1.3 Bar ................3

물론 다른 방식으로 작동하는 솔루션도 좋을 것입니다. 나중에 섹션 제목에 "Term:" 접두사를 추가하는 솔루션이 있다면 이 방법도 작동할 수 있습니다. 그러나 이 경우에는 제목이 붙은 몇 가지 섹션만 확장되어야 한다는 점을 보장할 필요가 있습니다.

답변1

당신은 간단히 할 수 있습니다 :

\section*{Term: Foo}                  % suppresses output in TOC
\addcontentsline{toc}{section}{Foo}   % add custom line to TOC

편집: 위의 코드는 아마도 원하지 않는 번호 매기기도 억제합니다. 따라서 하나의 명령으로 모든 작업을 수행하는 또 다른 제안은 다음과 같습니다.

\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\newcommand{\customsec}[1]{\section[#1]{Term: #1}}

\begin{document}

\tableofcontents

\chapter{MyChapter}
\customsec{Foo}
\section{foobar}
\customsec{Bar}
\end{document}

목차 콘텐츠

답변2

명령 의 선택적 인수로 짧은 제목을 사용할 수 있습니다 \section. 이렇게 하면 번호 매기기가 유지됩니다. MWE:

\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}

\begin{document}

\tableofcontents

\chapter{MyChapter}
\section[Foo]{Term: Foo}
\section{foobar}
\section[Bar]{Term: Bar}
\end{document}

결과:

여기에 이미지 설명을 입력하세요

관련 정보