如何在 tikzpicture 中输入交叉引用编号

如何在 tikzpicture 中输入交叉引用编号

我正在尝试使用下图中的“ \label{thm1}”和“ ”环境自动生成定理参考编号。但它显示错误。如果我通过手动输入下面的定理编号替换“ ” ,它可以完美运行。如何在环境中使用该命令?\ref{thm1}text={Theorem \ref{thm1}}"text={Theorem 1.1}"\ref{...}decorations

\documentclass[]{amsart}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm,amsxtra}
\usepackage{cite}
\usepackage{enumerate}
\usepackage[mathscr]{eucal}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{tikz-cd}
\usepackage{tkz-graph}
\usepackage{tkz-berge}
\usetikzlibrary{positioning,arrows,shapes.geometric,trees}

\usepackage{mathtools}
\usetikzlibrary{positioning}
\usetikzlibrary{decorations.text}
\usepackage{graphicx}

\newtheorem{Th}{Theorem}[section]
\begin{document}

\section{Section 1}
\begin{Th}
\label{thm1}
This is a theorem. 
\end{Th}

\section{Section 2}

\begin{tikzpicture}[scale=2,node distance=3cm and 2.5cm]
  \node (k1) {$\underset{(1)} {Step1}$};
  \node (k2) [below=of k1] {$\underset{(2)} {Step2}$};
  \draw [->,postaction={decorate,decoration={raise=-2ex,text along path,text align=center,text={Theorem \ref{thm1}}}}](k1) to  (k2);
  \end{tikzpicture}

\end{document}

答案1

除非使用calc包,否则\ref不是可扩展的命令。但是,\getrefnumber来自refcount包是可扩展的,因此请\ref用替换\getrefnumber

为什么它必须可扩展?因为decoration库需要有关内容的信息,而不仅仅是框的宽度和高度。

我还建议用Step1\text{Step 1}替换。

\documentclass[]{amsart}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm,amsxtra}
\usepackage{cite}
\usepackage{enumerate}
\usepackage[mathscr]{eucal}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{tikz-cd}
\usepackage{tkz-graph}
\usepackage{tkz-berge}
\usetikzlibrary{positioning,arrows,shapes.geometric,trees}

\usepackage{mathtools}
\usetikzlibrary{positioning}
\usetikzlibrary{decorations.text}
\usepackage{graphicx}

\usepackage{refcount}
\newtheorem{Th}{Theorem}[section]
\begin{document}

\section{Section 1}
\begin{Th}
\label{thm1}
This is a theorem. 
\end{Th}

\section{Section 2}

\begin{tikzpicture}[scale=2,node distance=3cm and 2.5cm]
  \node (k1) {$\underset{(1)} {\text{Step 1}}$};
  \node (k2) [below=of k1] {$\underset{(2)} {\text{Step 2}}$};
  \draw [->,postaction={decorate,decoration={raise=-2ex,text align=center,text along path,text={Theorem \getrefnumber{thm1}}}}](k1) to  (k2);
  \end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容