escapeinside 无法与 beamer 中的 tcolorbox 配合使用

escapeinside 无法与 beamer 中的 tcolorbox 配合使用

我试图在序言中用beamer以下声明来进行陈述。tcblisting

\newtcblisting{ListingBoxWithEscape}[2][]{
minted language=#2,
minted style=friendly,
minted options={breaklines,autogobble,fontsize=\footnotesize,tabsize=2,escapeinside=!!},
title=#1
}

在我的文档中我有:

\begin{ListingBoxWithEscape}{html}
    <body>
    <div class="container">
      <div class="jumbotron">
        <h1>Grid Cols and a Row</h1>!
        \tikz \node[coordinate] (a) {};
        !<p>Resize this responsive page to see the effect</p>
      </div>

      <div class="row">
        <div class="col-sm-4">
          <h3>Web Design</h3>
          <p>This is Web design. This is web design. This is web design..</p>
          <p>We are trying to learn Responsive web design using Bootstrap......</p>
        </div>
\end{ListingBoxWithEscape}

我收到以下错误:

! Package tikz Error: A node must have a (possibly empty) label text.

See the tikz package documentation for explanation.
Type  H <return>  for immediate help.
  ...                                              

l.6 \PYG{esc}{    \tikz \node[coordinate] (a) {};}

我不知道问题出在哪里。有人知道吗?

以下是 MWE:

\documentclass{beamer}

\usepackage{tikz}
\usepackage{tcolorbox}

\tcbuselibrary{xparse,minted}

\newtcblisting{ListingBoxWithEscape}[2][]{
    minted language=#2,
    minted style=friendly,
    minted options={breaklines,autogobble,fontsize=\footnotesize,tabsize=2,escapeinside=!!},
    title=#1
}

\usetikzlibrary{calc,shapes.callouts,shapes.arrows,positioning}

\begin{document}
\begin{frame}[c,fragile]
    \frametitle{Test}
    \begin{ListingBoxWithEscape}{html}
        <body>
        <div class="container">
          <div class="jumbotron">
            <h1>Grid Cols and a Row</h1>!
            \tikz \node[coordinate] (a) {};
            !<p>Resize this responsive page to see the effect</p>
          </div>

          <div class="row">
            <div class="col-sm-4">
              <h3>Web Design</h3>
              <p>This is Web design. This is web design. This is web design..</p>
              <p>We are trying to learn Responsive web design using Bootstrap......</p>
            </div>
    \end{ListingBoxWithEscape}
\end{frame}
\end{document}

答案1

我发现如果我隐藏tikzpicture命令中的,比如说\newcommand\tst{\tikz[remember picture]{\coordinate (a);}},然后使用此命令,错误消息就会消失。以下内容有很多来自@egreg的意见,我感谢他在下面的评论。正如@egreg指出的那样,问题在于和{}我只是猜测其中有些东西(我认为有些东西从根本上是错误的,但正如@egreg指出的那样,你可能想要添加listing only。)

\documentclass{beamer}

\usepackage{tikz}
\usepackage{tcolorbox}

\tcbuselibrary{xparse,minted}

\newtcblisting{ListingBoxWithEscape}[2][]{listing only,
    minted language=#2,
    minted style=friendly,
    minted options={breaklines,autogobble,fontsize=\footnotesize,tabsize=2,
    escapeinside=!!},
    title=#1
}

\usetikzlibrary{calc,shapes.callouts,shapes.arrows,positioning}
\begin{document}
\begin{frame}[c,fragile]
\newcommand\tst{\tikz[remember picture]{\coordinate (a);}}
    \frametitle{Test}
    \begin{ListingBoxWithEscape}{html}
        <body>
        <div class="container">
          <div class="jumbotron">
            <h1>Grid Cols and a Row</h1>!\tst!
            <p>Resize this responsive page to see the effect</p>
          </div>

          <div class="row">
            <div class="col-sm-4">
              <h3>Web Design</h3>
              <p>This is Web design. This is web design. This is web design..</p>
              <p>We are trying to learn Responsive web design using Bootstrap......</p>
            </div>
    \end{ListingBoxWithEscape}
    \begin{tikzpicture}[remember picture,overlay]
    \draw[red,latex-] (a) to[out=0,in=-90] ++ (1,1) node[above] {test};
    \end{tikzpicture}
\end{frame}
\end{document}

在此处输入图片描述

相关内容