在目录中:如何隐藏 \subsection 中的 \section 编号?

在目录中:如何隐藏 \subsection 中的 \section 编号?

有人知道我该如何做才能使表格列表中不出现父标题的编号吗?我当前最小示例的输出

I
 I.1
 I.2
 I.3
 I.4
   I.4.1
   I.4.2
II

但我想要以下格式:

I
 1
 2
 3
 4
  1
  2
II

这是一个最小的例子。

\documentclass[12pt,german,titlepage,a4paper]{article}
\usepackage[latin1]{inputenc}
\setcounter{secnumdepth}{4} \setcounter{tocdepth}{3} \pagestyle{headings} \raggedbottom
\renewcommand{\thesection}{\Roman{section}} 

\begin{document}
    \begin{titlepage}
    \end{titlepage}
    
    \thispagestyle{empty}
    \setcounter{page}{1}
    \tableofcontents
    \clearpage
    \pagenumbering{arabic}
    \section{Test1}
    \clearpage
    \subsection{Test2}
    \clearpage
    \subsection{Test2}
    \clearpage
    \subsection{Test2}
    \clearpage
    \subsection{Test2}
    \clearpage
    \subsubsection{Test3}
    \clearpage
    \subsubsection{Test3}
    \clearpage
    \section{Test1}
    \clearpage
\end{document}

答案1

这是一个不需要加载任何特定 LaTeX 包的解决方案。它在章节标题和对子节和子小节标题的任何交叉引用中显示“完整”(复合)子节和子节编号,但在目录中仅显示简单的“数字”(或字母)。

在此处输入图片描述


在此处输入图片描述


\documentclass[12pt,a4paper]{article}

\pagestyle{headings} 

% Choose unique numbering styles:
\renewcommand{\thesection}{\Roman{section}} 
\renewcommand{\thesubsection}{\arabic{subsection}}
\renewcommand{\thesubsubsection}{\alph{subsubsection}}

% Use method proposed in "The LaTeX Companion", 2nd ed., to
% determine how the section-like counters are displayed in
% sectioning headers:
\makeatletter
\def\@seccntformat#1{\@ifundefined{#1@cntformat}%
   {\csname the#1\endcsname\space}%default
   {\csname #1@cntformat\endcsname}}%  enable individual control 
\newcommand\subsection@cntformat{%     subsection
   \thesection.\thesubsection\space} 
\newcommand\subsubsection@cntformat{%  subsubsection
   \thesection.\thesubsection.\thesubsubsection\space}
\makeatother

% Display section and subsection numbers in cross-references
% to subsections and subsubsections
\makeatletter
\renewcommand{\p@subsection}{\thesection.}
\renewcommand{\p@subsubsection}{\thesection.\thesubsection.}
\makeatother

\begin{document}

\pagenumbering{roman}
\thispagestyle{empty}
\setcounter{page}{1}
\tableofcontents

\clearpage
\pagenumbering{arabic}
\section{Test I} \label{sec:aaa}
\clearpage
\subsection{Test I1}
\clearpage
\subsection{Test I2} \label{sec:bbb}
\clearpage
\subsection{Test I3}
\clearpage
\subsection{Test I4}
\clearpage
\subsubsection{Test I4a}
\clearpage
\subsubsection{Test I4b} \label{sec:ccc}

\clearpage
\section{Test II}
Cross-references to sections \ref{sec:aaa}, \ref{sec:bbb}, 
and \ref{sec:ccc}.

\end{document}

相关内容