![如何在 tikzpicture 中输入交叉引用编号](https://linux22.com/image/356973/%E5%A6%82%E4%BD%95%E5%9C%A8%20tikzpicture%20%E4%B8%AD%E8%BE%93%E5%85%A5%E4%BA%A4%E5%8F%89%E5%BC%95%E7%94%A8%E7%BC%96%E5%8F%B7.png)
我正在尝试使用下图中的“ \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}