隐藏目录和表格、图表和算法列表中的章节详细信息

隐藏目录和表格、图表和算法列表中的章节详细信息

我有以下简单的文档:

\documentclass[10pt,a4paper]{report}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\setcounter{secnumdepth}{4}
\setcounter{tocdepth}{4}
\usepackage{algorithm,algcompatible}
\begin{document}
    \tableofcontents
    \listoffigures
    \listoftables
    \listofalgorithms

\chapter{Chapter First}
This is my chapter first.

\chapter{Chapter Two}   
This is my chapter two.

\section{sec 1}

\begin{table}
    \centering
    \caption{my table}
    \label{tab1}
    \begin{tabular}{|c|c|}
        \hline 1 & 2 \\ 
        \hline 3 & 4 \\ 
        \hline 
    \end{tabular} 
\end{table}

\subsection{subsec 1}

\begin{algorithm}
    \caption{(\textit{The EGl-FOM})}
    \label{myalg}
    \begin{algorithmic}[1]
        \STATE Choose 
        \STATE Use the 
        \STATE Compute $\alpha_m$
        \STATE Compute $\lVert R_m\rVert_F=h_{m, m+1}|e_m^T\alpha_m|$.
    \end{algorithmic}
\end{algorithm}

\subsubsection{subsubsec 1}

\end{document}

我将隐藏章节、节、小节和小小节的标题关于第二章来自目录。此外,我想隐藏表格、图形和算法标题关于第二章来自表格、图表和算法列表。有没有正确的方法来做这些事情?

答案1

您可以设置触发器第二章停止向 ToC/LoF/LoT/LoA 写入内容,然后恢复此写入第二章(第三章之前)。

这两个宏\hidefromtoc\writetotoc是停止/恢复对表的写入的触发器:

\documentclass{report}
\setcounter{secnumdepth}{4}
\setcounter{tocdepth}{4}
\usepackage{algorithm,algcompatible}

\let\oldaddcontentsline\addcontentsline
\newcommand{\hidefromtoc}{\renewcommand{\addcontentsline}[3]{}}
\newcommand{\writetotoc}{\let\addcontentsline\oldaddcontentsline}

\begin{document}

\tableofcontents
\listoffigures
\listoftables
\listofalgorithms

\chapter{First chapter}
\section{First section}
\subsection{First subsection}
\begin{figure}
  \caption{A figure}
\end{figure}
\begin{table}
  \caption{A table}
\end{table}
\begin{algorithm}
  \caption{An algorithm}
\end{algorithm}

\hidefromtoc% <------------ Stop writing content to ToC/LoF/LoT/LoA

\chapter{Second chapter}
\section{Second section}
\subsection{Second subsection}
\begin{figure}
  \caption{A figure}
\end{figure}
\begin{table}
  \caption{A table}
\end{table}
\begin{algorithm}
  \caption{An algorithm}
\end{algorithm}

\writetotoc% <------------ Restore writing content to ToC/LoF/LoT/LoA

\chapter{Third chapter}
\section{Third section}
\subsection{Third subsection}
\begin{figure}
  \caption{A figure}
\end{figure}
\begin{table}
  \caption{A table}
\end{table}
\begin{algorithm}
  \caption{An algorithm}
\end{algorithm}

\end{document}

答案2

KOMA-Script 类提供了两个特殊功能,可用于仅抑制 ToC 条目:

  • 目录条目为空的标题将不会打印在目录中
  • 标题的目录条目可以与标题或页眉分开设置
\documentclass[headings=optiontotocandhead]{scrartcl}

\usepackage{lipsum}
\begin{document}

\tableofcontents
\section{First Section}
\lipsum[1]
\subsection{Subsection with ToC entry}
\lipsum[2]
\subsection[tocentry={}]{Subsection without ToC entry}
\lipsum[3]
\subsection{Another Subsection with ToC entry}

\end{document}

在此处输入图片描述

包裹caption为浮点数提供类似的功能:

\documentclass[headings=optiontotocandhead]{scrartcl}
\usepackage{caption}
\usepackage{mwe}
\begin{document}

\tableofcontents
\listoffigures

\section{First Section}
\lipsum[1]
\subsection{Subsection with ToC entry}
\lipsum[2]
\begin{figure}
  \centering
  \includegraphics{example-image-a}
  \caption{Figure with ToC entry}
\end{figure}
\subsection[tocentry={}]{Subsection without ToC entry}
\lipsum[3]
\begin{figure}
  \centering
  \includegraphics{example-image-b}
  \caption[]{Figure without ToC entry}
\end{figure}
\subsection{Another Subsection with ToC entry}
\lipsum[4]
\begin{figure}
  \centering
  \includegraphics{example-image-c}
  \caption{Another figure with ToC entry}
\end{figure}

\end{document}

在此处输入图片描述

我使用了scrartclKOMA-Script 的文章类作为示例,因为它能够在一页上显示目录和图表列表。但此功能也适用于scrreprtscrbook

顺便说一句:这些类别提供了emulatestandardclasses模拟标准类别的选项。

答案3

一种相当临时的方法,使用\HideFromToC\UnhideFromToC宏,改变本地目录深度以及内部所做的事情的行为\caption

\documentclass[10pt,a4paper]{report}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{xpatch}
\usepackage{algorithm,algcompatible}


\newcounter{oldtocdepth}
\newif\ifshowintoc


\makeatletter


\xpatchcmd{\@caption}{%
 \addcontentsline{\csname ext@#1\endcsname}{#1}%
 {\protect\numberline{\csname the#1\endcsname}{\ignorespaces #2}}%
}{%
  \ifshowintoc
  \addcontentsline{\csname ext@#1\endcsname}{#1}%
  {\protect\numberline{\csname the#1\endcsname}{\ignorespaces #2}}%
  \fi
}{}{}



% Now adapt float's caption a little bit. 
\renewcommand\caption{%
  \ifshowintoc
  \ifx\@captype\@undefined
  \@latex@error{\noexpand\caption outside float}\@ehd
  \expandafter\@gobble
  \else
  \refstepcounter\@captype
  \let\@tempf\@caption
  \expandafter\ifx\csname @float@c@\@captype\endcsname\relax\else
  \expandafter\expandafter\let
  \expandafter\@tempf\csname @float@c@\@captype\endcsname\fi\fi
  \else
  \refstepcounter\@captype
  \let\@tempf\@caption
  \fi
  \@dblarg{\@tempf\@captype}%
}

\newcommand{\HideFromToC}[1][-1]{%
  \setcounter{oldtocdepth}{\number\value{tocdepth}}% Store the oldtocdepth
  \addtocontents{toc}{\protect\setcounter{tocdepth}{#1}}
  \showintocfalse
}

\newcommand{\UnhideFromToC}{%
  \addtocontents{toc}{\protect\setcounter{tocdepth}{\number\value{oldtocdepth}}}
  \showintoctrue
}

\makeatother

\begin{document}


\tableofcontents
\listoffigures
\listoftables
\listofalgorithms

\chapter{Chapter First}
This is my chapter first.



\HideFromToC


\chapter{Chapter Two}   
This is my chapter two.

\section{sec 1}

\begin{figure}
  \caption{A dummy figure}
\end{figure}

\begin{table}
    \centering
    \caption{my table}
    \label{tab1}
    \begin{tabular}{|c|c|}
        \hline 1 & 2 \\ 
        \hline 3 & 4 \\ 
        \hline 
    \end{tabular} 
\end{table}

\subsection{subsec 1}

\begin{algorithm}
    \caption{(\textit{The EGl-FOM})}
    \label{myalg}
    \begin{algorithmic}[1]
        \STATE Choose 
        \STATE Use the 
        \STATE Compute $\alpha_m$
        \STATE Compute $\lVert R_m\rVert_F=h_{m, m+1}|e_m^T\alpha_m|$.
    \end{algorithmic}
\end{algorithm}

\subsubsection{subsubsec 1}


\UnhideFromToC

\chapter{Foo that appears in ToC}

\section{Foo section}
\subsection{Foo subsection}
\subsubsection{Foo subsubsection}


\begin{algorithm}
    \caption{Another algo caption}
    \label{myalgo}
    \begin{algorithmic}[1]
        \STATE Choose 
        \STATE Use the 
        \STATE Compute $\alpha_m$
        \STATE Compute $\lVert R_m\rVert_F=h_{m, m+1}|e_m^T\alpha_m|$.
    \end{algorithmic}
\end{algorithm}


\end{document}

答案4

\addtocontents{toc}{\setcounter{tocdepth}{nn}}在想要隐藏的部分级别之前写入开关,\addtocontents{toc}{\setcounter{tocdepth}{pp}}然后立即执行此操作即可。

以下是文章类中隐藏一些子部分的示例:\documentclass[12pt]{article}%http://ctan.org/pkg/amsproc

    \usepackage[utf8]{inputenc}
    \usepackage[T1]{fontenc}
\usepackage{geometry}
    \usepackage{garamondx}
\usepackage{parskip}
\usepackage{verse}
\setlength{\leftmargini} {8em}
\renewcommand{\thesubsection}{\Alph{subsection}}
\raggedbottom
    \begin{document}

%\setcounter{tocdepth}{0}
\tableofcontents
    \section{Animals}

    \subsection{The Absolutely Abstemious Ass,}
\begin{verse}%
 who resided in a Barrell, and only lived on\\
Soda Water and Pickled Cucumbers. \\[3ex]
\includegraphics[scale=0.70]{nr_a}
\end{verse}

 \setcounter{subsection}{3}
    \subsection{The Dolomphious Duck,}
\begin{verse}
 who caught Spotted Frogs for her dinner \\
 with a Runcible Spoon. \\[2ex]
 \includegraphics[scale=0.75]{nr_d}
\end{verse}

 \setcounter{subsection}{7}
 \subsection{The Hasty Higgeldipiggledy Hen,}
\begin{verse}
 who went to market in a Blue Bonnet and Shawl, \\
 and bought a Fish for her Supper \\[3ex]
 \includegraphics[scale=0.75]{nr_h}
\end{verse}

 \setcounter{subsection}{15}
\subsection{The Perpendicular Purple Polly,}
 \begin{verse}
 who read the Newspaper and ate Parsnip Pie \\
 with his Spectacles. \\[3ex]
 \includegraphics[scale=0.75]{nr_p}
\end{verse}

\addtocontents{toc}{\setcounter{tocdepth}{1}}
\stepcounter{subsection}
\subsection{The Rural Runcible Raven,}
\begin{verse}
 who wore a White Wig and flew away\\
 with the Carpet Broom. \\[3ex]
 \includegraphics[scale=0.65]{nr_r}
\end{verse}
\addtocontents{toc}{\setcounter{tocdepth}{2}}

\setcounter{tocdepth}{2}
 \setcounter{subsection}{21}
\subsection{The Visibly Vicious Vulture,}
\begin{verse}
 who wrote some Verses to a Veal-cutlet in a\\
 Volume bound in Vellum. \\[2ex]
 \includegraphics[scale=0.6]{nr_v}
\end{verse}

 \setcounter{subsection}{24}
\subsection{ The Yonghy-Bonghy-Bo,}
\begin{verse}
 whose head was ever so much bigger than his\\
 Body, and whose Hat was rather small. \\[2ex]
 \includegraphics[scale=0.65]{nr_y}
\end{verse}

\end{document} 

在此处输入图片描述 在此处输入图片描述

相关内容