命令 \textHeight 已定义。\end{frame}

命令 \textHeight 已定义。\end{frame}

我不知道为什么会出现此错误。如果我使用独立 documentclass 运行相同的代码,则运行不会出现问题。

\documentclass[10pt]{beamer}
\mode<presentation>{ }

\usefonttheme{professionalfonts}
\usefonttheme{serif}
\usepackage{tikz, fontspec}

\makeatletter
\newcommand\getheightofnode[2]{
    \pgfextracty{#1}{\pgfpointanchor{#2}{north}}
    \pgfextracty{\pgf@ya}{\pgfpointanchor{#2}{south}}
    \addtolength{#1}{-\pgf@ya}
}
\makeatother

\newcommand{\textcontainer}[6]
{

    \node(mynode)[inner sep=0,outer sep=0,text width=#5,above] at(-#5/2-#4,#2)  {#6};
    \getheightofnode{\textHeight}{mynode}

    \draw[very thin](0,0)--(-#1-#4-#5,0)--(-#1-#4-#5,#2+#3+\textHeight);
}

\begin{document}
\begin{frame}
\begin{tikzpicture}
\newlength\textHeight;
\uncover<1-1>{

    \textcontainer{3.75pt}{3.75pt}{2.25pt}{10pt}{4cm}{\scriptsize{Here is some text.}}
}
\uncover<2-2>{
    \textcontainer{3.75pt}{3.75pt}{2.25pt}{10pt}{4cm}{\scriptsize{Here is some more text.}}
}

\end{tikzpicture}
\end{frame}
\end{document}

答案1

\newlength\textHeight(不以 ; 结尾)放在文档的序言或正文中,但不要放在图片或框架内:

姆韦

\documentclass[10pt]{beamer}
\mode<presentation>{ }
\usefonttheme{professionalfonts}
\usefonttheme{serif}
\usepackage{tikz, fontspec}
\makeatletter
\newcommand\getheightofnode[2]{
    \pgfextracty{#1}{\pgfpointanchor{#2}{north}}
    \pgfextracty{\pgf@ya}{\pgfpointanchor{#2}{south}}
    \addtolength{#1}{-\pgf@ya}}
\makeatother
\newcommand{\textcontainer}[6]{
    \node(mynode)[inner sep=0,outer sep=0,text width=#5,above]%
at(-#5/2-#4,#2)  {#6};
    \getheightofnode{\textHeight}{mynode}
    \draw[very thin](0,0)--%
(-#1-#4-#5,0)--(-#1-#4-#5,#2+#3+\textHeight);}

\newlength\textHeight

\begin{document}
\begin{frame}
\begin{tikzpicture}

\uncover<1-1>{
    \textcontainer{3.75pt}{3.75pt}{2.25pt}{10pt}{4cm}%
{\scriptsize{Here is some text.}}    }
\uncover<2-2>{
    \textcontainer{3.75pt}{3.75pt}{2.25pt}{10pt}{4cm}%
{\scriptsize{Here is some more text.}}}
\end{tikzpicture}
\end{frame}
\end{document}

相关内容