在 Latex 中隐藏 Toc 的条目

发布于 2024-08-31 23:56:11 字数 262 浏览 2 评论 0原文

我想知道如何隐藏目录中的某个部分,但又不会丢失文档正文中的部分编号。例如,在这个 tex 文件中,我丢失了 hide 的编号,并且所有序列都被损坏:

\documentclass{article}

\begin{document}
\tableofcontents
\section{uno}
\section{dos}
\section*{hide}
\section{tres}
\end{document}

I would like to know how I can hide a section from the table of contents but without loosing the section number in the body of the document. For example, in this tex file I loose the number for hide, and all the sequences are damaged:

\documentclass{article}

\begin{document}
\tableofcontents
\section{uno}
\section{dos}
\section*{hide}
\section{tres}
\end{document}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

同尘 2024-09-07 23:56:11

我认为您正在寻找

\section*{hide}
\addtocounter{section}{1}

或将其变成命令:

\newcommand{\toclesssection}[1]{\section*{#1}\addtocounter{section}{1}}

编辑:

好的,我想我明白现在想要什么(而且它比我给出的答案更有意义)。下面是一个命令,您可以使用它来禁止向目录中添加节、小节等。这个想法是暂时禁用 \addcontentsline

\newcommand{\nocontentsline}[3]{}
\newcommand{\tocless}[2]{\bgroup\let\addcontentsline=\nocontentsline#1{#2}\egroup}
...
\tocless\section{hide}
\tocless\subsection{subhide}

I think you are looking for

\section*{hide}
\addtocounter{section}{1}

or make it into a command:

\newcommand{\toclesssection}[1]{\section*{#1}\addtocounter{section}{1}}

EDIT:

Okay, I think I understand what is wanted now (and it makes more sense then the answer I gave). Here is a command that you can use to suppress adding a section, subsection, etc. to the TOC. The idea is to temporarily disable \addcontentsline.

\newcommand{\nocontentsline}[3]{}
\newcommand{\tocless}[2]{\bgroup\let\addcontentsline=\nocontentsline#1{#2}\egroup}
...
\tocless\section{hide}
\tocless\subsection{subhide}
不寐倦长更 2024-09-07 23:56:11

只是想说谢谢伊万斯的伟大提示!
(我只是在谷歌上搜索与我的自定义 (Sub)Appendix{} 命令类似的内容:

\newcommand{\nocontentsline}[3]{}
\newcommand{\tocless}[2]{\bgroup\let\addcontentsline=\nocontentsline#1{#2}\egroup}

\newcommand{\Appendix}[1]{
  \refstepcounter{section}
  \section*{Appendix \thesection:\hspace*{1.5ex} #1}
  \addcontentsline{toc}{section}{Appendix \thesection}
}
\newcommand{\SubAppendix}[1]{\tocless\subsection{#1}}

也许这对其他人也有用......)

Just wanted to say thanks for Ivans great hint!
(I was just googling for something similar for my customized (Sub)Appendix{} commands:

\newcommand{\nocontentsline}[3]{}
\newcommand{\tocless}[2]{\bgroup\let\addcontentsline=\nocontentsline#1{#2}\egroup}

\newcommand{\Appendix}[1]{
  \refstepcounter{section}
  \section*{Appendix \thesection:\hspace*{1.5ex} #1}
  \addcontentsline{toc}{section}{Appendix \thesection}
}
\newcommand{\SubAppendix}[1]{\tocless\subsection{#1}}

Maybe this is useful for someone else, too...)

む无字情书 2024-09-07 23:56:11

刚刚从类似的问题来到这里。上面的答案没有'不太有效,因为它给出了一些格式问题,但是 类似的解决方案 似乎成功了

have just come here from a similar question. The answer above didn't quite work as it gave some formatting issues, but a similar solution seemed to do the trick

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文