当我尝试以下代码时,一切都按预期进行:
\documentclass{article}
%\renewcommand{\thesubsubsection}{\alph{subsubsection})}
\begin{document}
\section{A Section}
\subsection{A Subsection}
\subsubsection{A Subsubsection}
\label{testlabel}
Hello world.
\par
In \ref{testlabel} I wrote: Hello world.
\end{document}
这将打印 1.1.1。
但是,如果我在注释中启用该命令,我只会得到 a),而不是预期的 1.1.a)
实际上,我希望该部分显示为 a) ...并且引用显示为 1.1.a(不带括号)。
有任何想法吗?
答案1
对于任何 LaTeX 计数器,宏都是引用中使用的前缀。通常,它用于嵌套枚举中,以获得列表标签仅显示一个级别而引用显示扩展形式的效果。\[email protected]
默认宏假定最终计数器的打印形式在两个地方是相同的,因此如果您想丢失)
它,您需要使用前缀宏来删除它,就像这里一样,或者像在 egreg 的答案中那样不要将它添加到计数器格式中,而是考虑)
部分标题格式的一部分。
\documentclass{article}
\renewcommand{\thesubsubsection}{\alph{subsubsection})}
\makeatletter
\renewcommand{\p@subsubsection}{\thesubsection.\protect\eatbracket}
\makeatother
\def\eatbracket#1#2{#1\ifx)#2\else#2\fi}
\begin{document}
\section{A Section}
\subsection{A Subsection}
\subsubsection{A Subsubsection}
\label{testlabel}
Hello world.
\par
In \ref{testlabel} I wrote: Hello world.
\end{document}
答案2
最好将括号添加到它应该在的位置,而不是事后将其删除。这可以通过简单地重新定义来实现\@seccntformat
:
\documentclass{article}
\makeatletter
\renewcommand{\@seccntformat}[1]{%
\csname the#1\endcsname
\csname suffix@#1\endcsname % this does nothing unless \suffix@... is defined
\quad
}
% the subsubsection number is just a letter
\renewcommand{\thesubsubsection}{\alph{subsubsection}}
% but references will also have “section.subsection.” in front of the letter
\renewcommand{\p@subsubsection}{\thesubsection.}
% define \suffix@subsubsection
\newcommand{\suffix@subsubsection}{)}
\makeatother
\begin{document}
\section{A Section}
\subsection{A Subsection}
\subsubsection{A Subsubsection}\label{testlabel}
Hello world.
In \ref{testlabel} I wrote: Hello world.
\end{document}
这也是可扩展的。假设您想要在a)
和标题之间有一个正常的单词间距,同时保留\quad
以用于更高级别。那么您可以修改代码如下
\makeatletter
\renewcommand{\@seccntformat}[1]{%
\csname the#1\endcsname
\@ifundefined{suffix@#1}%
{\quad}%
{\csname suffix@#1\endcsname}%
}
% the subsubsection number is just a letter
\renewcommand{\thesubsubsection}{\alph{subsubsection}}
% but references will also have “section.subsection.” in front of the letter
\renewcommand{\p@subsubsection}{\thesubsection.}
% define \suffix@subsubsection
\newcommand{\suffix@subsubsection}{) }% parenthesis and space
\makeatother
第二个解决方案也修复了目录(同样,在括号和标题之间留一个正常的空格似乎是最好的)。
\documentclass{article}
\makeatletter
\renewcommand{\@seccntformat}[1]{%
\csname the#1\endcsname
\@ifundefined{suffix@#1}
{\quad}%
{\csname suffix@#1\endcsname}%
}
% the subsubsection number is just a letter
\renewcommand{\thesubsubsection}{\alph{subsubsection}}
% but references will also have “section.subsection.” in front of the letter
\renewcommand{\p@subsubsection}{\thesubsection.}
% define \suffix@subsubsection
\newcommand{\suffix@subsubsection}{) }% parenthesis and space
\renewcommand{\l@subsubsection}[2]{%
\@dottedtocline{3}{3.8em}{3.2em}{\let\numberline\subsubsection@numberline#1}{#2}%
}
\def\subsubsection@numberline#1{#1) }
\makeatother
\begin{document}
\tableofcontents
\section{A Section}
\subsection{A Subsection}
\subsubsection{A Subsubsection}
\label{testlabel}
Hello world.
\par
In \ref{testlabel} I wrote: Hello world.
\section{Whatever}
\end{document}
答案3
您还需要提供\thesubsubsection
的内容\thesubsection
\documentclass{article}
\renewcommand{\thesubsubsection}{\thesubsection.\alph{subsubsection})}
\begin{document}
\section{A Section}
\subsection{A Subsection}
\subsubsection{A Subsubsection}
\label{testlabel}
Hello world.
\par
In \ref{testlabel} I wrote: Hello world.
\end{document}
屈服