當我嘗試以下程式碼時,一切都按預期工作:
\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}
屈服