
我正在使用cleveref
包來引用我的文件中的章節\documentclass{book}
。
下面是 MWE。
\documentclass{book}
\usepackage[capitalize]{cleveref}
\begin{document}
\chapter{First chapter}\label{ch:first}
\chapter{Second chapter}\label{ch:second}
\chapter{Third chapter}\label{ch:third}
\chapter{Fourth chapter}\label{ch:fourth}
We saw in \cref{ch:first,ch:second,ch:third} that ...
\end{document}
對於第 4 章,MWE 得出:
有沒有相對簡單的方法來\cref
代替給出以下內容?
我們在第 1、2、3 章看到…
看著cleveref package manual
,似乎\Crefmultiformat
或\Crefrangemultiformat
可能是合適的。但如果可能的話,我希望這僅適用於本地或僅適用於章節。例如,我可能確實想要類似「第 2.1 至 2.3 節」的內容部分,只是不為了章節。
答案1
這裡的問題是,您預設壓縮參考文獻,但對於章節參考文獻,您不想進行壓縮。解決方案是在(在本例中)最後兩個引用之間插入一個額外的逗號;這將關閉該參考清單的壓縮。有關更完整的說明,請參閱文件的第 5 節。如果您希望在參考文獻中使用牛津逗號,那麼您需要取消註釋\crefmultiformat
下面程式碼中的程式碼。
\documentclass{book}
\usepackage[capitalize]{cleveref}
%\crefmultiformat{chapter}{Chapters~#2#1#3}{ and~#2#1#3}{, #2#1#3}{, and~#2#1#3}
\begin{document}
\chapter{First chapter}\label{ch:first}
\chapter{Second chapter}\label{ch:second}
\chapter{Third chapter}\label{ch:third}
\chapter{Fourth chapter}\label{ch:fourth}
We saw in \cref{ch:first,ch:second,,ch:third} that ...
\end{document}