3つ以上の章をリストするにはcleverefパッケージを使用します

3つ以上の章をリストするにはcleverefパッケージを使用します

私は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

ここでの問題は、デフォルトで参照を圧縮しているが、章の参照についてはその圧縮を行わないということです。解決策は、(この場合) 最後の 2 つの参照の間に追加のコンマを挿入することです。これにより、その参照リストの圧縮がオフになります。より詳しい説明については、ドキュメントの §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}

コードの出力

関連情報