从 pdf 正文中删除章节和部分标题,但不从目录中删除?

从 pdf 正文中删除章节和部分标题,但不从目录中删除?

如何将标题(包含章节、节标题)添加到目录条目并删除正文中的任何标题?这样做的目的是我有很多章节、节、小节和段落,其中包含大量图表,这些标题占据了整整一页,并且页数还在增加。我的目标是使用最少的页数。请参阅下面的 MWE:

\documentclass{report}
\usepackage{listings}
\usepackage{fancyhdr}
\pagestyle{fancy}

\lhead{\nouppercase{\rightmark} (\nouppercase{\leftmark})}
\chead{}
\rhead{}

\newcommand\chap[1]{%
  \chapter*{#1}%
  \addcontentsline{toc}{chapter}{#1}}

\begin{document}
\tableofcontents

\part{Humanoid Introduction} 
\chapter{Obstacle Avoidance}
\section{detecting wall}
\chapter{Face Recognition}
\section{Shape Recognition}
\subsection{Face Recognisation}
\subsection{Hand Recognisation}

\end{document}

答案1

\documentclass{report}
\newcommand\fakechapter[1]{%
  \clearpage
  \refstepcounter{chapter}%
  \addcontentsline{toc}{chapter}{\protect\numberline{\thechapter}#1}%
  \chaptermark{#1}}

\begin{document}
\tableofcontents

\fakechapter{Obstacle Avoidance}
blbla

\fakechapter{Face Recognition}
blblb

\end{document}

答案2

这可能需要一些调整,但基本上可以满足您的要求。由于我只是重新定义了分段命令,注释掉这些\redefinelevel行将恢复为标准行为,没有其他变化(除了运行几次 LaTeX)。

\documentclass{report}
\usepackage{fancyhdr}

\usepackage{lipsum}

\pagestyle{fancy}

\fancyhf{}
\fancyhead[L]{\nouppercase{\rightmark} (\nouppercase{\leftmark})}
\fancyfoot[C]{\thepage}

\makeatletter
\newcommand{\redefinelevel}[2][]{%
  \@namedef{#2}{\par % ... in case "\section" and siblings are called while 
                     % still in horizontal mode.
    \@ifstar{\@nameuse{redef@s@#2}}{\@nameuse{redef@#2}}}%
  \@namedef{redef@#2}##1{%
    #1% (In any case, unneeded spaces in macro definition waste memory...)
    \refstepcounter{#2}%
    \@nameuse{#2mark}{##1}%
    \addcontentsline{toc}{#2}{\protect\numberline{\@nameuse{the#2}}##1}%
  }%
  \@namedef{redef@s@#2}##1{#1\@mkboth{##1}{##1}}% this one was missing too
}
\makeatother

\redefinelevel[\cleardoublepage]{chapter}
\redefinelevel{section}
\redefinelevel{subsection}
\redefinelevel{subsubsection}

\begin{document}

\tableofcontents

\part{Humanoid Introduction} 
\chapter{Obstacle Avoidance}
\section{detecting wall}

\lipsum[1-10]

\chapter{Face Recognition}

\section{Shape Recognition}

\lipsum[1-10]

\subsection{Face Recognisation}

\lipsum[1-10]

\subsection{Hand Recognisation}

\lipsum[1-10]

\chapter{Testing the correction}
Some text.
\section{Called in horizontal mode}
This should be a new paragraph.  (Note that, without \verb|\par|, and 
without the appropriate~\verb|%|'s, two more spurious spaces were added.)

\end{document}

在此处输入图片描述

相关内容