
명령의 출력을 원합니다.
\cref{prob:third-problem,prob:fourth-problem}
첫 번째 장 내용의 첫 번째 줄( ??
아래 표시된 페이지에 출력(두 개의 s 포함)이 표시된 장)은 해당 장의 다른 명령과 마찬가지로 "Exercises 2.3 and 2.4"(따옴표 없이)가 됩니다. 형태 \cref{first,second}
.
\cref{first,fourth,fifth}
(그리고 두 개 이상의 문제 참조 목록이 있는 경우에도 마찬가지입니다 .)
로 이 작업을 어떻게 수행할 수 있나요 cleveref
?
\documentclass{memoir}
% theorems
\usepackage{amsthm}
\usepackage{thmtools}
\declaretheoremstyle[
headformat=\NAME\NOTE,
headfont= \sffamily\bfseries,
headpunct={\vspace{\topsep}\newline},
numbered=no,
spaceabove=3\topsep,
postheadspace=0pt
]{probs}
\declaretheorem[
name=EXERCISES,
style=probs,
]{problemscontent}
\newenvironment{problems}
{\problemscontent}
{\endproblemscontent}
% lists
\usepackage{enumitem}
% For exercises
\newcounter{problemnumber} % number exercises within each chapter
\newlist{problemsenum}{enumerate}{3}
\setlist[problemsenum,1]{%...
label=\bfseries\sffamily\arabic*.,
ref={\arabic*}, % strips formatting!
before=\leavevmode \vspace{-\dimexpr\baselineskip+\topsep\relax},
after=\stepcounter{problemsenumi}\setcounter{problemnumber}{\value{problemsenumi}},
start=\value{problemnumber}
}
\makeatletter
\renewcommand{\p@problemsenumi}{\maybe@thechapter{\thechapter}}
\protected\def\maybe@thechapter#1{%
\ifnum#1=\value{chapter}%
\else
#1.%
\fi
}
\makeatother
\newlist{problempartsenum}{enumerate}{2}
\setlist[problempartsenum,1]{%
label=\bfseries\sffamily(\alph*),
ref={(\alph*)},%, % strips formatting!
before=\vspace{\dimexpr+6pt-\medskipamount\relax},
}
% links
\usepackage[pdftex]{hyperref}
\hypersetup{%
breaklinks=true,%
colorlinks, citecolor=red,%
}
%% Allow ref to section n, not section m.n
%% From 'third installment' of answer by Christian Hupfer
%% https://tex.stackexchange.com/a/383608
\usepackage{xparse,xassoccnt}
\usepackage[user,hyperref]{zref}
\RegisterPostLabelHook{\zlabel}
% Replace \arabic{section} with \Roman{section} etc. as needed:
\makeatletter
\zref@newprop{section}{\arabic{section}}
\zref@addprop{main}{section}
\newcommand{\secref}[1]{%
\zref@ifrefundefined{#1}{%
\ref{#1}}{%
\hyperlink{\zref@extract{#1}{anchor}}%
{\zref@extract{#1}{section}}}}
\makeatother
%% End of code from Christian Hupfer's answer
\usepackage{aliascnt}
\usepackage[noabbrev,nameinlink]{cleveref}
\crefformat{problemsenumi}{#2Exercise~#1#3}
\Crefformat{problemsenumi}{#2Exercise~#1#3}
\crefformat{problemscontent}{#2\textnormal{#3}}
\Crefformat{problemscontent}{#2\textnormal{#3}}
\newcommand\crefprob[2]{\cref{#1}~\ref{#2}}
\newcommand\crefrangeprob[2]{Exercises~\textup{\ref{#1}}--\textup{\ref{#2}}}
\newcommand\crefrangeprobpart[2]{\textup{\ref{#1}}--\textup{\ref{#2}}}
\newcommand\crefprobandrangeprobpart[3]{\cref{#1}~\textup{\ref{#2}}--\textup{\ref{#3}}}
\begin{document}
\chapter{First}\label{chap:1}
\setcounter{problemnumber}{1}
See \cref{prob:first-problem} in a different chapter. And \cref{prob:third-problem,prob:fourth-problem}.
See also \cref{prob:chap1-number2}~\ref{prob-part:one-part-b}, that is,
\crefprob{prob:chap1-number2}{prob-part:one-part-b}.
And consider \crefrangeprob{prob:chap1-number1}{prob:chap1-number2} in this chapter.
What about parts \crefrangeprobpart{prob-part:one-part-a}{prob-part:one-part-b}
of \cref{prob:chap1-number2} in this chapter?
That is, \crefprobandrangeprobpart{prob:chap1-number2}{prob-part:one-part-a}{prob-part:one-part-b}.
Or \crefprobandrangeprobpart{prob:first-problem}{prob-part:first-problem-part-a}{prob-part:first-problem-part-b}
in another chapter.
\begin{problems}
\begin{problemsenum}
\item\label{prob:chap1-number1}
A question.
\item\label{prob:chap1-number2}
\begin{problempartsenum}
\item\label{prob-part:one-part-a}
Why is $a = b$?
\item\label{prob-part:one-part-b}
Why is $d = c$?
\item\label{prob-part:one-part-c}
Is $x=y$?
\end{problempartsenum}
\end{problemsenum}
\end{problems}
%%%
\chapter{Second}\label{chap:2}
\setcounter{problemnumber}{1}
Refer to \cref{prob:first-problem} in this chapter---specifically, to
\crefprob{prob:first-problem}{prob-part:first-problem-part-b}.
And see \crefrangeprob{prob:third-problem}{prob:fifth-problem}.
\section{First section}
\begin{problems}\label{probs:seconeprobs}
\begin{problemsenum}
\item \label{prob:first-problem}
First problem.
\begin{problempartsenum}
\item\label{prob-part:first-problem-part-a}
Why is $a = b$?
\item\label{prob-part:first-problem-part-b}
Why is $d = c$?
\item\label{prob-part:first-problem-part-c}
Is $x=y$?
\end{problempartsenum}
\item
Second problem.
\end{problemsenum}
\end{problems}
\section{Second section}
\begin{problems}\label{probs:sectwoprobs}
\begin{problemsenum}
\item \label{prob:third-problem}
First problem.
\item \label{prob:fourth-problem}
Second problem.
\begin{problempartsenum}
\item\label{prob-part-fourth-problem-part-a}
Is it?
\item\label{prob-part-fourth-problem-part-b}
Why not?
\end{problempartsenum}
\item \label{prob:fifth-problem}
Fifth problem.
\end{problemsenum}
\end{problems}
\end{document}
노트:
- 환경 자체는 번호가 매겨진 정리와 같은 환경이 되지 않으면서 거기에 열거된 항목에 대한 참조를
problems
허용하도록 특별한 방법으로 정의되었습니다 .cleveref
해당 명령과cleveref
구성은 다른 게시물의 다양한 답변에서 수집됩니다. 해당 게시물에는 다음이 포함됩니다.소수점 이하 섹션번호 일부만 참조그리고 Cleveref를 사용하여 정리와 유사한 이름과 목록 항목 번호를 얻는 방법은 무엇입니까?. - 내 실제 훨씬 더 복잡한 문서에서는 문서 클래스를 사용합니다
memoir
. 그러나 이 MWE의 경우book
추가 패키지가 명시적으로 로드된 경우 클래스도 사용할 수 있습니다.
답변1
이 문제는 다음을 포함하여 해결할 수 있습니다.
\crefname{problemsenumi}{Exercise}{Exercises}
서문에서.
(내가 선호하는 누락된 옥스퍼드(연속) 쉼표는 답변으로 삽입될 수 있습니다.여러 인용에 Oxford 쉼표를 사용하도록 Cleveref를 만들 수 있습니까?, 즉 \newcommand{\creflastconjunction}{, and\nobreakspace}
.