个人命令与 beamer 类不兼容

个人命令与 beamer 类不兼容

在这些线程中:个人命令与 tikz calc 库不兼容\compo允许您将图形放置在文本旁边的 个人命令已被更正以与tikz calc库一起使用,现在它运行良好。(感谢@Hood Chatham)

但是当我在中使用它时beamer class,出现此错误:

!包 tikz 错误:预期为 + 或 -。

宏代码为:

\newlength{\colG}\newlength{\colD}
% Wrapper command just changes catcodes and calls helper
\newcommand\compo{%
    \shorthandoff{!:}% Change the catcodes
    \compohelper % call helper to grab arguments
}
\newcommand{\compohelper}[3][0.5]{% do actual work
    \setlength{\colG}{#1\linewidth}%
    \setlength{\colD}{\linewidth}%
    \addtolength{\colD}{-\colG}%
    \addtolength{\colG}{-10pt}%
    \addtolength{\colD}{-10pt}%
    \par \noindent%
    \begin{minipage}[t]{\colG}#2\end{minipage}\hfill\vrule\hfill%    
    \begin{minipage}[t]{\colD}#3\end{minipage}%
    \par
    \shorthandon{!:}% restore catcodes
}

代码如下:

\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{babel}

\newlength{\colG}\newlength{\colD}
% Wrapper command just changes catcodes and calls helper
\newcommand\compo{%
    \shorthandoff{!:}% Change the catcodes
    \compohelper % call helper to grab arguments
}
\newcommand{\compohelper}[3][0.5]{% do actual work
    \setlength{\colG}{#1\linewidth}%
    \setlength{\colD}{\linewidth}%
    \addtolength{\colD}{-\colG}%
    \addtolength{\colG}{-10pt}%
    \addtolength{\colD}{-10pt}%
    \par \noindent%
    \begin{minipage}[t]{\colG}#2\end{minipage}\hfill\vrule\hfill%    
    \begin{minipage}[t]{\colD}#3\end{minipage}%
    \par
    \shorthandon{!:}% restore catcodes
}

\begin{document}
\begin{frame}


\compo[.5]{
  Un triangle

}{
\begin{tikzpicture}
\draw(-1,-1) rectangle (4,4);
\coordinate (B) at (0,0);
\coordinate  (C) at (3,0);
\coordinate(D) at (2,0);
\draw(B)--(C)--(D)--cycle;
\coordinate (Ap) at ($(C)!.35!-90:(B)$);
\draw (Ap)--(B)--(C)--cycle;
\end{tikzpicture}

}
\end{frame}
\end{document} 

我需要做哪些更改才能使该命令与 tikz calc 库和 beamer 类一起使用?

答案1

您的命令正在改变 catcodes,这意味着从 beamer 的角度来看,它是一种“逐字”命令,您需要使用[fragile]带有框架的选项:

 \begin{frame}[fragile]

相关内容