答案在交叉引用未编号的子部分展示如何定义自定义\subsec
命令以允许交叉引用cleveref
。
但是我该如何修改以允许使用复数形式\cref
,并引用两个这样的小节。
样本来源:
\documentclass[12pt]{memoir}
\usepackage{hyperref}
\usepackage{cleveref}
\setsecnumdepth{subsection}
% subsections:
%
% Handle refs to subsections, which are unnumbered
\newcounter{subsec}
\makeatletter
\newcommand{\subsec}[1]{%
\subsection*{#1}%
\addcontentsline{toc}{subsection}{#1}%
\refstepcounter{subsec}%
\def\cref@currentlabel{[subsec][\arabic{subsec}][]#1}%
\def\@currentlabelname{#1}%
}
\makeatother
\crefname{subsection}{subsection}{subsections} % not used?
\Crefname{subsection}{Subsection}{Subsections} % not used?
\crefformat{subsec}{#2subsection~``#1''#3} % for unnumbered subsections
\Crefformat{subsec}{#2Subsection~``#1''#3} % ditto, caps
\begin{document}
In \cref{sec:one,sec:other} we outline. [OK, as expected]
\section{The section}\label{sec:one}
\section{The other section}\label{sec:other}
\begin{itemize}
\item In \cref{subsec:this} and \cref{subsec:another} we ponder. [OK]
\item In \cref{subsec:this,subsec:another} we analyze. [Does \textbf{NOT} work.]
\emph{Want output there to be:} subsections ``This one'' and ``Another one''
\end{itemize}
\subsec{This one}\label{subsec:this}
This is in a subsection.
\subsec{Another one}\label{subsec:another}
Here is another subsection.
\end{document}
答案1
那里标有的计数器是subsec
,因此\crefname
应该使用subsec
而不subsection
是以提供正确的交叉引用信息。
那时也是如此\Crefname
。
\crefname{subsection}{subsection}{subsections}
等已经完成了cleveref
。
\documentclass[12pt]{memoir}
\usepackage{hyperref}
\usepackage{cleveref}
\setsecnumdepth{subsection}
% subsections:
%
% Handle refs to subsections, which are unnumbered
\newcounter{subsec}
\makeatletter
\newcommand{\subsec}[1]{%
\subsection*{#1}%
\addcontentsline{toc}{subsection}{#1}%
\refstepcounter{subsec}%
\def\cref@currentlabel{[subsec][\arabic{subsec}][]#1}%
\def\@currentlabelname{#1}%
}
\makeatother
\crefname{subsec}{subsection}{subsections} % not used?
\Crefname{subsec}{Subsection}{Subsections} % not used?
\crefformat{subsec}{#2subsection~``#1''#3} % for unnumbered subsections
\Crefformat{subsec}{#2Subsection~``#1''#3} % ditto, caps
\crefmultiformat{subsec}{subsections~``#2#1#3''}{ and~``#2#1#3''}{,~``#2#1#3''}{ and~``#2#1#3''}% As Mico proposed ;-)
\begin{document}
In \cref{sec:one,sec:other} we outline. [OK, as expected]
\section{The section}\label{sec:one}
\section{The other section}\label{sec:other}
\begin{itemize}
\item In \cref{subsec:this} and \cref{subsec:another} we ponder. [OK]
\item In \cref{subsec:this,subsec:another} we analyze. [Does \textbf{NOT} work.]
\emph{Want output there to be:} subsections ``This one'' and ``Another one''
\end{itemize}
\subsec{This one}\label{subsec:this}
This is in a subsection.
\subsec{Another one}\label{subsec:another}
Here is another subsection.
\end{document}