参考和定理盒子的问题

参考和定理盒子的问题

在此处输入图片描述 大家好,我在使用 \label 和 \ref 时遇到了问题,就像在这个最小的例子中一样,请帮助我

    \documentclass[12pt,a4paper,openany]{book}
%-------------------------------------------------------
\usepackage{hyperref}

\hypersetup{% bookmarks=true,
    unicode=true,
    colorlinks=true,
    citecolor=green, %black,
    filecolor=black,
    linkcolor=blue, 
    urlcolor=cyan, 
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{titlesec}
\usepackage{titletoc}

%%%%%%%%%%%%%%%%%%%



\newtheorem{theorem}{مبرهنة}[section]

\usepackage{tcolorbox}

\tcbuselibrary{theorems}
\newtcbtheorem
  [number within= section]% init options
  {definition}% name
  {تعريف}
  % title
  {%
    colback=green!5,
    colframe=green!35!black,
    fonttitle=\bfseries,
  }% options
{def}% prefix



%-------------------------------------------------------
\usepackage{polyglossia}
\setmainlanguage[numerals=maghrib]{arabic}
\setotherlanguage{english}
\newfontfamily\arabicfont[Script=Arabic,Scale=1.1,AutoFakeSlant=-0.03]{Amiri}
\setsansfont[Script=Arabic,Scale=1.1]{Amiri}
%-------------------------------------------------------


\begin{document}
\section{1}
\begin{definition}{}{}\label{1}
نسمي
\end{definition}

من
\ref{1}
\section{2}
\begin{theorem}\label{2}
ليكن 
\end{theorem}

\ref{2}
\end{document}

答案1

定理和类似的环境中tcolorbox有两个参数,第一个是定理标题,第二个是标签后缀,它将被添加到标签前缀中,作为 tcbtheorem 声明中的第四个强制参数声明。

\newtcbtheorem[number within=section]{theorem}{Theorem}{}{theo}

theo是前缀,所以当你声明

\begin{theorem}{theorem name}{2}
...
\end{theorem}

标签theo-2已创建,您可以使用\ref{theo-2}它来引用此定理。与 的行为类似definition。您不需要外部\label命令。

\documentclass[12pt,a4paper,openany]{book}
%-------------------------------------------------------
\usepackage{hyperref}

\hypersetup{% bookmarks=true,
    unicode=true,
    colorlinks=true,
    citecolor=green, %black,
    filecolor=black,
    linkcolor=blue, 
    urlcolor=cyan, 
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{titlesec}
\usepackage{titletoc}

%%%%%%%%%%%%%%%%%%%



%\newtheorem{theorem}{مبرهنة}[section]

\usepackage[most]{tcolorbox}

\tcbuselibrary{theorems}

\newtcbtheorem[number within=section]{theorem}{Theorem}{}{theo}

\newtcbtheorem
  [number within= section]% init options
  {definition}% name
  {Name}
  % title
  {%
    colback=green!5,
    colframe=green!35!black,
    fonttitle=\bfseries,
  }% options
{def}% prefix



%-------------------------------------------------------
%\usepackage{polyglossia}
%\setmainlanguage[numerals=maghrib]{arabic}
%\setotherlanguage{english}
%\newfontfamily\arabicfont[Script=Arabic,Scale=1.1,AutoFakeSlant=-0.03]{Amiri}
%\setsansfont[Script=Arabic,Scale=1.1]{Amiri}
%-------------------------------------------------------


\begin{document}
\section{1}
\begin{definition}{Definition name}{1}
نسمي
\end{definition}

من
\ref{def:1}
\section{2}
\begin{theorem}{theorem name}{2}
ليكن 
\end{theorem}

\ref{theo:2}
\end{document}

在此处输入图片描述

相关内容