仅删除目录中章节编号之前的章节编号

仅删除目录中章节编号之前的章节编号

我看到了对一个问题的回答类似问题,但我想要更多的控制权:

我有罗马章节和阿拉伯部分。我希望罗马数字在目录中隐藏,并在仅限目录(此外,我稍后还会从章节标题中删除它们)。最重要的是我需要跨章节部分参考显示章节号

我尝试过,titletoc但没有成功(尽管从手动的):

\documentclass[12pt, a4paper]{report}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{titlesec,titletoc}

\renewcommand{\thechapter}{\Roman{chapter}}
\newcommand{\thesectiononly}{\arabic{section}}  % Do not override \thesection.

% Large bold section titles with section number only
\titleformat{\section}{\Large\bfseries}{\thesectiononly}{24pt}{}

% bold section names in the table of contents, with section number only.
\titlecontents*{section}[12pt]{\bfseries}{\thesectiononly. }{}{\thecontentspage}

\begin{document}

% Here, we should see 1. First section......
\tableofcontents

\chapter{First chapter}

\section{First section}\label{sec:first-section}

First content.

\section{Second section}

Other content.

\chapter{Second chapter}

\section{section in second chapter}

Last content, referring to section~\ref{sec:first-section}. % Displayed as "I.1"

\end{document}

编译通过,但生成的目录是:

图片

  • 我如何获得正确的章节编号?
  • 如何获取页码的默认前导点?

我知道tocloft,但还没有找到使用它来删除章节编号的方法。

答案1

您只需要重新定义\thesection\p@section

\documentclass[12pt, a4paper]{report}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{titlesec,titletoc}

\renewcommand{\thechapter}{\Roman{chapter}}
\renewcommand{\thesection}{\arabic{section}}
\makeatletter
\renewcommand{\p@section}{\thechapter.} 
\makeatother


\begin{document}

% Here, we should see 1. First section......
\tableofcontents

\chapter{First chapter}

\section{First section}\label{sec:first-section}

First content.

\section{Second section}

Other content.

\chapter{Second chapter}

\section{section in second chapter}

Last content, referring to section~\ref{sec:first-section}. % Displayed as "I.1"

\end{document}

相关内容