![改变 \ref 引用子节的方式](https://linux22.com/image/307780/%E6%94%B9%E5%8F%98%20%5Cref%20%E5%BC%95%E7%94%A8%E5%AD%90%E8%8A%82%E7%9A%84%E6%96%B9%E5%BC%8F.png)
你好,我有一个关于分段的问题:
我想用罗马数字 I、II、III 来表示每个部分,用字母 A、B、C 来表示每个小节,用阿拉伯数字 1、2、3 来\ref{}
表示小节。但是,当引用第 III 部分 B 小节中的第 2 小节时,我想得到 III.B.2,但我只得到 B.2。我想要的 III.B. 部分也是一样。
这是我目前所拥有的。
\documentclass[12pt,letterpaper,leqno,doublespacing]{article}
\renewcommand{\thesection}{\Roman{section}}
\renewcommand{\thesubsection}{\Alph{subsection}}
\renewcommand{\thesubsubsection}{\arabic{subsubsection}}
\begin{document}
\section{sec 1}
\subsection{subsec 1}
\subsection{subsec 2}
\subsection{subsec 3}
\section{sec 2}
\subsection{subsec 1}
\subsection{subsec 2}
\section{sec 3}
\subsection{subsec 1}
\subsection{subsec 2}
\subsubsection{subsub 1}
\subsubsection{subsub 2}\label{reference}
This is section \ref{reference}
\end{document}
答案1
无需加载任何特殊包。只需重新定义 LaTeX 为每个计数器变量自动设置的标签前缀宏即可。
\renewcommand{\thesection}{\Roman{section}}
\renewcommand{\thesubsection}{\Alph{subsection}}
\renewcommand{\thesubsubsection}{\arabic{subsubsection}}
\makeatletter
\renewcommand{\p@subsection}{\thesection.}
\renewcommand{\p@subsubsection}{\thesection.\thesubsection.}
\makeatother
答案2
一个解决方案titlesec
。
将您的计数器定义为
\renewcommand{\thesection}{\Roman{section}}
\renewcommand{\thesubsection}{\thesection.\Alph{subsection}}
\renewcommand{\thesubsubsection}{\thesubsection.\arabic{subsubsection}}
然后按以下方式格式化章节标题:
\titleformat{\section}
{\normalfont\Large\bfseries}{\Roman{section}}{1em}{}
\titleformat{\subsection}
{\normalfont\large\bfseries}{\Alph{subsection}}{1em}{}
\titleformat{\subsubsection}
{\normalfont\normalsize\bfseries}{\arabic{subsubsection}}{1em}{}
梅威瑟:
\documentclass[12pt,letterpaper,leqno,doublespacing]{article}
\renewcommand{\thesection}{\Roman{section}}
\renewcommand{\thesubsection}{\thesection.\Alph{subsection}}
\renewcommand{\thesubsubsection}{\thesubsection.\arabic{subsubsection}}
\usepackage{titlesec}
\titleformat{\section}
{\normalfont\Large\bfseries}{\Roman{section}}{1em}{}
\titleformat{\subsection}
{\normalfont\large\bfseries}{\Alph{subsection}}{1em}{}
\titleformat{\subsubsection}
{\normalfont\normalsize\bfseries}{\arabic{subsubsection}}{1em}{}
\begin{document}
\section{sec 1}
\subsection{subsec 1}
\subsection{subsec 2}
\subsection{subsec 3}
\section{sec 2}
\subsection{subsec 1}
\subsection{subsec 2}
\section{sec 3}
\subsection{subsec 1}
\subsection{subsec 2}
\subsubsection{subsub 1}
\subsubsection{subsub 2}\label{reference}
This is section \ref{reference}
\end{document}
输出:
答案3
这是一个解决方案
\documentclass[12pt,letterpaper,leqno,doublespacing]{article}
\renewcommand{\thesection}{\Roman{section}}
\renewcommand{\thesubsection}{\thesection.\Alph{subsection}}
\renewcommand{\thesubsubsection}{\thesubsection.\arabic{subsubsection}}
\makeatletter
\def\@seccntformat#1{\@ifundefined{#1@cntformat}%
{\csname the#1\endcsname\quad}%
{\csname #1@cntformat\endcsname}}
\def\section@cntformat{\thesection\quad}
\def\subsection@cntformat{\Alph{subsection}\quad}
\def\subsubsection@cntformat{\arabic{subsubsection}\quad}
\makeatother
\begin{document}
\section{sec 1}
\subsection{subsec 1}
\subsection{subsec 2}
\subsection{subsec 3}
\section{sec 2}
\subsection{subsec 1}
\subsection{subsec 2}
\section{sec 3}
\subsection{subsec 1}
\subsection{subsec 2}
\label{refer}
\subsubsection{subsub 1}
\subsubsection{subsub 2}\label{reference}
This is subsubsection \ref{reference} part of \ref{refer}
\end{document}