我对如何操作小节使其也由字母给出的问题找到了一个绝妙的解决方案:
但不幸的是,我的目录出了问题
\documentclass{article}
\usepackage{hyperref}
%\usepackage{letltxmacro}
\NewCommandCopy{\originalsubsection}{\subsection} %\LetLtxMacro{\originalsubsection}{\subsection} \RenewDocumentCommand{\subsection}{sd()O{#3}m}{% \IfBooleanTF{#1}
{\originalsubsection*{#4}}%
{%
\IfNoValueTF{#2}
{% no letter
\renewcommand{\thesubsection}{\thesection.\arabic{subsection}}%
}
{% letter
\addtocounter{subsection}{-1}%
\renewcommand{\thesubsection}{\thesection.#2}%
}
\originalsubsection[#3]{#4}%
}% }
\renewcommand{\theHsubsection}{\thesubsection}
\begin{document}
\tableofcontents
\section{First section}
\subsection(P){First subsection}
\subsubsection{First subsubsection}
\subsubsection{Second subsubsection}
\subsection(V){Second subsection}\label{v}
\subsubsection{First subsubsection}\label{1-v}
\section{First section}
\subsection{First subsection}
\ref{v} and \ref{1-v}
\end{document}
目录如下:
NoValue
在小节中用字母显示的位置。
有办法解决这个问题吗?谢谢!
答案1
新定义的第三个参数\subsection
不应该使用O{#3}
,而应该使用o
,然后测试 是否#3
存在(使用\IfValueTF{#3}{<true>}{<false>}
)。此处<true>
分支(如果#3
提供了 )将按原样使用它,否则(如果#3
)未提供 )它应该使用#4
。
\documentclass{article}
\usepackage{hyperref}
\NewCommandCopy{\originalsubsection}{\subsection} %\LetLtxMacro{\originalsubsection}{\subsection}
\RenewDocumentCommand{\subsection}{s d() o m}{%
\IfBooleanTF{#1}
{\originalsubsection*{#4}}%
{%
\IfValueTF{#2}
{% letter
\addtocounter{subsection}{-1}%
\renewcommand{\thesubsection}{\thesection.#2}%
}
{% no letter
\renewcommand{\thesubsection}{\thesection.\arabic{subsection}}%
}%
\originalsubsection[\IfValueTF{#3}{#3}{#4}]{#4}%
}%
}
\renewcommand{\theHsubsection}{\thesubsection}
\begin{document}
\tableofcontents
\section{First section}
\subsection(P){First subsection}
\subsubsection{First subsubsection}
\subsubsection{Second subsubsection}
\subsection(V){Second subsection}\label{v}
\subsubsection{First subsubsection}\label{1-v}
\section{First section}
\subsection{First subsection}
\ref{v} and \ref{1-v}
\end{document}