여러 레이블을 동시에 이름 참조하는 방법은 무엇입니까?

여러 레이블을 동시에 이름 참조하는 방법은 무엇입니까?

이 예에서는 이를 사용 \cref{first,second}하고 cleveref올바르게 레이블을 지정합니다. 여기에 이미지 설명을 입력하세요

\documentclass[10pt,a5paper]{memoir}
\usepackage[brazil]{babel}
\usepackage{hyperref}
\usepackage{cleveref}

\begin{document}

\namecref{first,second}

\chapter{First}
\label{first}

\chapter{Second}
\label{second}

\end{document}

하지만 , 를 사용하면 대신에 \nameref{first,second}, 만 제공됩니다 .??First and Second

\nameref여러 라벨을 어떻게 사용할 수 있나요 \cref?

답변1

다음 코드를 사용할 수 있습니다. 이는 user현재 표시 이름입니다. user동일한 접두사를 사용하여 존재할 수 있는 다른 관련 없는 코드와 충돌하지 않도록 하려면 코드의 접두사를 고유할 가능성이 더 높은 것으로 바꿔야 합니다 .

% The code below automatically adapts to the selected language.
\documentclass[english]{article}
\usepackage{babel}
\usepackage{xparse}
\usepackage{hyperref}
\usepackage{cleveref}

\ExplSyntaxOn

% #1: variant (cref, Cref, crefs or Crefs)
% #2: reference name (label)
\cs_new_protected:Npn \user_name_cref:nn #1#2
  { \use:c { name #1 } {#2} }

\cs_generate_variant:Nn \user_name_cref:nn { xV }

% #1: boolean expression (true: disable hyperlink)
% #2: reference name (label)
\cs_new_protected:Npn \user_name_ref:nn #1#2
  { \bool_if:nTF {#1} { \nameref* } { \nameref } {#2} }

\cs_generate_variant:Nn \user_name_ref:nn { nV }

\seq_new:N \l__user_name_refs_tmpa_seq
\seq_new:N \l__user_name_refs_tmpb_seq
\int_new:N \l__user_name_refs_nbrefs_int
\tl_new:N \l__user_name_refs_firstref_tl

% #1: boolean expression (true: start with capitalized letter, as in \Cref)
% #2: boolean expression (true: disable hyperlinks)
% #3: comma list of refs
\cs_new_protected:Npn \user_name_refs:nnn #1#2#3
  {
    \seq_set_from_clist:Nn \l__user_name_refs_tmpa_seq {#3}
    \int_set:Nn \l__user_name_refs_nbrefs_int
                { \seq_count:N \l__user_name_refs_tmpa_seq }
    \seq_get_left:NN \l__user_name_refs_tmpa_seq \l__user_name_refs_firstref_tl

    % (section, Section, sections or Sections) or (theorem, Theorem, ...) or...
    \user_name_cref:xV
      { \bool_if:nTF {#1} { C } { c }
        ref
       \int_compare:nNnTF { \l__user_name_refs_nbrefs_int } > { 1 } { s } { } }
     \l__user_name_refs_firstref_tl
    \nobreakspace

    % Now print the references.
    \seq_clear:N \l__user_name_refs_tmpb_seq
    \seq_map_inline:Nn \l__user_name_refs_tmpa_seq
      {
        \seq_put_right:Nn \l__user_name_refs_tmpb_seq
                          { \user_name_ref:nn {#2} {##1} }
      }
    \seq_use:Nnnn \l__user_name_refs_tmpb_seq { \crefpairconjunction }
                  { \crefmiddleconjunction } { \creflastconjunction }
  }

\cs_generate_variant:Nn \user_name_refs:nnn { nx }

\cs_new_protected:Npn \__user_name_refs:Nnn #1#2#3
  {
    \user_name_refs:nxn {#1}
      { \IfBooleanTF {#2} { \c_true_bool } { \c_false_bool } }
      {#3}
  }

% “Start in lower case” variant. With star: disable hyperlinks.
% #2: comma list of refs
\NewDocumentCommand \nameRefs { s m }
  {
    \__user_name_refs:Nnn \c_false_bool {#1} {#2}
  }

% “Start in upper case” variant. With star: disable hyperlinks.
% #2: comma list of refs
\NewDocumentCommand \NameRefs { s m }
  {
    \__user_name_refs:Nnn \c_true_bool {#1} {#2}
  }

\ExplSyntaxOff

\begin{document}

References:
\begin{itemize}
\item With one reference and hyperlink: \nameRefs{first} (we'll disable
  hyperlinks from now on, because their default appearance is hideous and they
  don't behave very well across line breaks);
\item With one reference: \nameRefs*{first};
\item With two references: \nameRefs*{first, second};
\item With three references: \nameRefs*{first, second, third};
\item With four references: \nameRefs*{first, second, third, fourth};
\item Capitalized variant: \NameRefs*{first, second, third, fourth};
\item etc.
\end{itemize}

% This is a cref command; beware that spaces are not ignored after the commas!
For comparison, the \verb|\cref| command: \cref{first,second,third,fourth}.

\section{First section}
\label{first}

\section{Second section}
\label{second}

\section{Third section}
\label{third}

\section{Fourth section}
\label{fourth}

\end{document}

스크린샷

관련 정보