![参考和定理盒子的问题](https://linux22.com/image/429335/%E5%8F%82%E8%80%83%E5%92%8C%E5%AE%9A%E7%90%86%E7%9B%92%E5%AD%90%E7%9A%84%E9%97%AE%E9%A2%98.png)
大家好,我在使用 \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}