tcolorbox:\newtcbtheorem 带有 \zref 参考系统,适用于多卷书

tcolorbox:\newtcbtheorem 带有 \zref 参考系统,适用于多卷书

我想将精美的tcolorbox框架包与现代参考系统一起使用zref

我的\newtcbtheorem样子是:

\newtcbtheorem[auto counter,number within=chapter]{mathexam}{MyExample}{%
   % colback=purple!5,
   % colframe=blue!100!,
   fonttitle=\itshape,        % \bfseries,
   fontupper=\small,
   fontlower=\footnotesize,
   enforce breakable,         % breakable,
   compress page,
   enhanced,
   arc=1pt, left=0pt,right=0pt
}{mai}

但它会产生:

LaTeX Warning: Reference `mai:exam038' on page 12 undefined on input line 262.

尽管我翻译过好几次。是否可以同时使用这两个库?

我使用zref软件包的动机是创建多卷书,其中包含我来自不同科目的学校笔记。软件包zref-xref可以代替,xr-hyper如所示Heiko Oberdiek 的解决方案

我的完整 MNWE 是:

\documentclass{scrbook} 
  \usepackage[most]{tcolorbox}
  \newtcbtheorem[auto counter,number within=chapter]{mathexam}{Problem}{%
    % colback=purple!5,
    % colframe=blue!100!,
      fonttitle=\itshape,        % \bfseries,
      fontupper=\small,
      fontlower=\footnotesize,
      enforce breakable,         % breakable,
      compress page,
      enhanced,
      arc=1pt, left=0pt,right=0pt
  }{mai}

\usepackage{nameref}
\usepackage[user, counter]{zref}
%  \usepackage{zref-xr}
%  \zexternaldocument*{example}

\begin{document}
  \chapter{Algebra}\zlabel{chap:math1}
    This is a test for math.
    \begin{equation}
      E=mc^2 \zlabel{eq:1}
    \end{equation}
    This is a second test for math.
    \begin{equation}
      r = \sqrt{x^2 + y^2} \zlabel{eq:2}
    \end{equation}
    In the document A there is chapter \nameref{chap:math1} see the eqation \zref{eq:2}. 

  Solve the problem shown in example \zref{exam038}

  \section{Bunch of examples}
    Let's solve following problems
    \begin{mathexam}{Gauss method}{exam038}
      \(3x + 4y = 5\)
    \end{mathexam}
\end{document}

答案1

tcolorbox 不支持 zref。您可以提出功能请求,或重新定义 \label 以便也发出 \zlabel,或修补 tcolorbox 命令。nameref 可以替换 titleref 模块。

\documentclass{scrbook}
  \usepackage[most]{tcolorbox}
  \newtcbtheorem[auto counter,number within=chapter]{mathexam}{Problem}{%
    % colback=purple!5,
    % colframe=blue!100!,
      fonttitle=\itshape,        % \bfseries,
      fontupper=\small,
      fontlower=\footnotesize,
      enforce breakable,         % breakable,
      compress page,
      enhanced,
      arc=1pt, left=0pt,right=0pt,
  }{mai}

\usepackage{nameref}
\usepackage[user, counter,titleref]{zref}
%  \usepackage{zref-xr}
%  \zexternaldocument*{example}

\makeatletter
\pretocmd\tcb@set@label{\zlabel{#1}}{}{\fail}
% if nameref is loaded, else patch \tcb@gettitle
\pretocmd\NR@gettitle{\zref@titleref@setcurrent{#1}}{}{\fail}
%\pretocmd\tcb@gettitle{\zref@titleref@setcurrent{#1}}{}{\fail}
\makeatother
\begin{document}

  \chapter{Algebra}\zlabel{chap:math1}
    This is a test for math.
    \begin{equation}
      E=mc^2 \zlabel{eq:1}
    \end{equation}
    This is a second test for math.
    \begin{equation}
      r = \sqrt{x^2 + y^2} \zlabel{eq:2}
    \end{equation}
    In the document A there is chapter \ztitleref{chap:math1} see the equation \zref{eq:2}.

  Solve the problem shown in example \zref{mai:exam038}

  \section{Bunch of examples}
    Let's solve following problems
    \begin{mathexam}{Gauss method}{exam038}
      \(3x + 4y = 5\)
    \end{mathexam}
    
    \ztitleref{mai:exam038}
\end{document}

相关内容