解决方案基于乌尔丽克·菲舍尔评论 :

解决方案基于乌尔丽克·菲舍尔评论 :

我正在使用报告文档类进行 latex 项目。我想更改目录编号的方式。我只想显示相应的数字,如下所示:

在此处输入图片描述

但是,我还想保留文本中的标题,就像它们通常那样,并且能够进行如下交叉引用:

在此处输入图片描述

到目前为止,我已成功使用该titlesec包使目录和标题按我想要的方式显示。但交叉引用不起作用。

分数维:


\documentclass[12pt]{report}

\usepackage{hyperref}


\renewcommand{\thechapter}{\Roman{chapter}}
\renewcommand{\thesection}{\Alph{section}}
\renewcommand{\thesubsection}{\arabic{subsection}}
\renewcommand{\thesubsubsection}{\arabic{subsubsection}}
\renewcommand{\theparagraph}{\arabic{paragraph}}
\setcounter{secnumdepth}{4}

\usepackage{titlesec}
\titleformat{\chapter}
  {\LARGE\bfseries}{\Roman{chapter}.}{10pt}{}
\titleformat{\section}
  {\normalfont\Large\bfseries}{\Roman{chapter}.\Alph{section}.}{10pt}{}
\titleformat{\subsection}
  {\normalfont\large\bfseries}{\Roman{chapter}.\Alph{section}.\arabic{subsection}.}{10pt}{}
\titleformat{\subsubsection}
  {\normalfont\bfseries}{\Roman{chapter}.\Alph{section}.\arabic{subsection}.\arabic{subsubsection}}{10pt}{}
\titleformat{\paragraph}
  {\normalsize\bfseries}{\Roman{chapter}.\Alph{section}.\arabic{subsection}.\arabic{subsubsection}.\arabic{paragraph}}{10pt}{}


\begin{document}

\tableofcontents
\chapter{Introduction}
\section{The First Section}
\subsection{The First Subsection}
\subsubsection{The First Subsubsection} \label{sec:first_subsection}
\section{The Second Section}
\subsection{The Second Subsection}
\subsubsection{The Second Subsubsection}
See section \ref{sec:first_subsection} \nameref{sec:first_subsection}

\end{document}

答案1

我会尽量避免代码重复,因为代码重复很容易出错(事实上,你似乎忘记了段落数字后面的句号)。

请注意,hyperref应该最后加载,肯定在之后titlesec

\documentclass[12pt]{report}

\usepackage{titlesec}
\usepackage{hyperref}

\renewcommand{\thechapter}{\Roman{chapter}}
\renewcommand{\thesection}{\Alph{section}}
\renewcommand{\thesubsection}{\arabic{subsection}}
\renewcommand{\thesubsubsection}{\arabic{subsubsection}}
\renewcommand{\theparagraph}{\arabic{paragraph}}

\newcommand{\thefullsection}{\thechapter.\thesection}
\newcommand{\thefullsubsection}{\thefullsection.\thesubsection}
\newcommand{\thefullsubsubsection}{\thefullsubsection.\thesubsubsection}
\newcommand{\thefullparagraph}{\thefullsubsubsection.\theparagraph}

\labelformat{section}{\thefullsection}
\labelformat{subsection}{\thefullsubsection}
\labelformat{subsubsection}{\thefullsubsubsection}
\labelformat{paragraph}{\thefullparagraph}

\titleformat{\chapter}
  {\LARGE\bfseries}{\Roman{chapter}.}{10pt}{}
\titleformat{\section}
  {\normalfont\Large\bfseries}{\thefullsection.}{10pt}{}
\titleformat{\subsection}
  {\normalfont\large\bfseries}{\thefullsubsection.}{10pt}{}
\titleformat{\subsubsection}
  {\normalfont\bfseries}{\thefullsubsubsection.}{10pt}{}
\titleformat{\paragraph}
  {\normalsize\bfseries}{\thefullparagraph.}{10pt}{}

\setcounter{secnumdepth}{4}


\begin{document}
\tableofcontents
\chapter{Introduction}
\section{The First Section}
\subsection{The First Subsection} 
\subsubsection{The First Subsubsection} \label{sec:first_subsection}
\section{The Second Section}
\subsection{The Second Subsection}
\subsubsection{The Second Subsubsection}
\paragraph{A paragraph}
See section \ref{sec:first_subsection} \nameref{sec:first_subsection}

\end{document}

在此处输入图片描述

答案2

解决方案基于乌尔丽克·菲舍尔评论 :

只需使用\labelformat命令重新定义引用的方式

\documentclass[12pt]{report}

\usepackage{hyperref}


\renewcommand{\thechapter}{\Roman{chapter}}
\renewcommand{\thesection}{\Alph{section}}
\renewcommand{\thesubsection}{\arabic{subsection}}
\renewcommand{\thesubsubsection}{\arabic{subsubsection}}
\renewcommand{\theparagraph}{\arabic{paragraph}}
\setcounter{secnumdepth}{4}
\labelformat{subsubsection}{\Roman{chapter}.\Alph{section}.\arabic{subsection}.\arabic{subsubsection}}
\usepackage{titlesec}
\titleformat{\chapter}
  {\LARGE\bfseries}{\Roman{chapter}.}{10pt}{}
\titleformat{\section}
  {\normalfont\Large\bfseries}{\Roman{chapter}.\Alph{section}.}{10pt}{}
\titleformat{\subsection}
  {\normalfont\large\bfseries}{\Roman{chapter}.\Alph{section}.\arabic{subsection}.}{10pt}{}
\titleformat{\subsubsection}
  {\normalfont\bfseries}{\Roman{chapter}.\Alph{section}.\arabic{subsection}.\arabic{subsubsection}}{10pt}{}
\titleformat{\paragraph}
  {\normalsize\bfseries}{\Roman{chapter}.\Alph{section}.\arabic{subsection}.\arabic{subsubsection}.\arabic{paragraph}}{10pt}{}

% Added line
\labelformat{subsubsection}{\Roman{chapter}.\Alph{section}.\arabic{subsection}.\arabic{subsubsection}}

\begin{document}
\tableofcontents
\chapter{Introduction}
\section{The First Section}
\subsection{The First Subsection} 
\subsubsection{The First Subsubsection} \label{sec:first_subsection}
\section{The Second Section}
\subsection{The Second Subsection}
\subsubsection{The Second Subsubsection}
See section \ref{sec:first_subsection} \nameref{sec:first_subsection}

\end{document}

使用相同的方法可以扩展到章节、节、小节、段落等。

相关内容