如何制作指向盒子的箭头

如何制作指向盒子的箭头

我有一张投影仪幻灯片,我想通过向变量添加一个带箭头的框来显示变量的含义。这是我失败的尝试:

\documentclass{beamer}
\usetheme{default}
\beamertemplatenavigationsymbolsempty
\usepackage[skins]{tcolorbox}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes}
\newtcolorbox{myexample}[0]{%
    text width=2cm, text height=0.1cm, enhanced,colback=green,colframe=black, coltitle=black,boxrule=0.8mm, tikz={rotate=90,transform shape}
}
\begin{document}
\begin{frame}
    Therefore
    \only<1>{
    $\Pr(A, B)$ 
    }
    \only<2>{
    $\Pr(\tikz{
    \node[fill=blue!20,,ellipse, anchor=base] (t1)
    {A, B};
    })$
    }
    $=0$
    \only<2>{
    \begin{myexample}
        ${\scriptstyle 0,1,2,3,4,4,5,6,7,8,9}$
    \end{myexample}
    }
\end{frame}

\end{document}

我怎么能够:

  • 使垂直 tcolorbox 在我选择的垂直位置右对齐?
  • 仅在第二个过渡中从 tcolorbox 绘制一个弯曲箭头到 $A, B$ 周围的椭圆
  • 使 tcolorbox 中的文本位于框的中心。 text height = 0.1cm也不正确,但这是我使框变小的唯一方法,但它仍然不够小。
  • 使椭圆变小、垂直居中正确,并且添加时周围的文本不会移动?

抱歉,问题太多了。

在此处输入图片描述


最终我想在此投影仪幻灯片中使用它:

\documentclass{beamer}
\usetheme{default}
\beamertemplatenavigationsymbolsempty
\setbeamertemplate{frametitle}[default][center]
\usepackage[skins]{tcolorbox}
\newtcolorbox{myexample}[2][]{%
    text width=\textwidth-1cm, text height=2.5cm, enhanced,colback=white,colframe=black, coltitle=black,
    sharp corners,boxrule=0.8mm,
    attach boxed title to top left={yshift=-0.3\baselineskip-0.4pt,xshift=2mm},
    boxed title style={tile,size=minimal,left=0.5mm,right=0.5mm,
        colback=white,before upper=\strut},
    title=#2,#1
}
\begin{document}
\begin{frame}{}

\begin{myexample}[text height=3cm]{}
    Suppose you pick a uniformly random integer from $\{1, \dots, 100\}$. If $A$ is the event that the last digit is a $3$ then $\Pr(A) = 1/10$.  If $B$ is the event that the number is prime then $\Pr(B) = 1/4$. 
    \[ 
    \Pr(A \mid B) = \frac{\Pr(A, B)}{\Pr(B)} = \frac{7/100}{1/4} = \frac{28}{100}
    \] 
\end{myexample}

\end{frame}
\end{document}

答案1

带有tikztikzmark

\documentclass{beamer}
\usetheme{default}
\beamertemplatenavigationsymbolsempty
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                shapes,
                tikzmark}

                            
\begin{document}
\begin{frame}
\tikzset{baseline,
 E/.style={ellipse, fill=gray!30, inner sep=2pt, anchor=base},
 N/.style={draw=green!60!black, very thick, rounded corners, fill=green!30,
           font=\scriptsize, rotate=90, anchor=east}
        }
\rule[-2ex]{0pt}{5ex} % <--- approximation of the equation height
Therefore
\only<1>{
    $\Pr(A, B)$
            }% <---
\only<2>{
    $\Pr(\tikz[baseline]\node[E] {\subnode{a}{A, B}};) =0$
% <---
\begin{tikzpicture}[remember picture, overlay]
    \node (b) [N]
        at (current page.center)
        {0,1,2,3,4,4,5,6,7,8,9};
    \draw[-Stealth, shorten <=1mm, shorten >=1mm]
        (a) to [bend right] (b.north); 
    \end{tikzpicture}
            }
\end{frame}

\end{document}

在此处输入图片描述

笔记:为了获得上述结果,您需要编译 MWE(至少)两次。

编辑:代码略有改进。现在方程式在两张幻灯片上的垂直位置相同。

答案2

使用 tikZ 获得你想要的东西的一个简单方法:

\begin{frame}
    \begin{tikzpicture}
        \only<1,2>{%
        \node [minimum height=20pt] (T1) at (0,0) {Therefore $\Pr($};
        \node [minimum height=20pt] (T2) at (1.6,0) {$A, B$};
        \node [minimum height=20pt] (T3) at (2.5,0) {$)= 0$};
        }
        \only<2>{%
        \node [%
            fill=green,
            draw,
            rounded corners=5pt,
            rotate=90,
            anchor=east,
            text height=11pt
            ]
            (X) at (0.25,-0.75) {0,1,2,3,4,5,6,7,8,9};
        \draw [->, thick, blue] (X.south) to [in=-90, out=0] (T2.south);
        \node [%
            minimum height=20pt,
            ellipse,
            x radius=0.5,
            y radius=1,
            fill=blue!20!white,
            inner sep=0
            ]
            (T2) at (1.6,0) {$A, B$};
        }
    \end{tikzpicture}
\end{frame}

答案3

只需pst-node

\documentclass[svgnames]{beamer}
\usetheme{default}
\beamertemplatenavigationsymbolsempty
\usepackage{pst-node}

\begin{document}

\begin{frame}
    Therefore
    \only<1>{
    $\Pr(A, B)$
    }
    \only<2>{
    $\Pr\bigl(\!\ovalnode[linestyle=none, fillstyle=solid, fillcolor=blue!20,] {E}{A, B}\!\bigr)$
    }
    $=0$

    \only<2>{%
\rotatebox[origin=lB]{90}{
        $\scriptstyle \pnode{A}0,1,2,3,4,\rnode{R}{4},5,6,7,8,9\pnode{B}\ncbox[fillstyle=solid, fillcolor=SeaGreen!65, linearc=0.1, boxsize=1.5ex, nodesep=2pt]{A}{B}
\rput[l](A){\scriptstyle 0, 1,2,3,4,4,5,6,7,8,9}$
}
    }
\nccurve[arrows=->, arrowinset=0.12, nodesepA=1.5ex, angleB=-150]{R}{E}
\end{frame}

\end{document} 

在此处输入图片描述

答案4

像这样 ?

我用注释掉了代码来%<--解释这些变化。

截屏

\documentclass{beamer}
\usetheme{default}
\beamertemplatenavigationsymbolsempty
\usepackage[skins]{tcolorbox}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,positioning}
\newtcolorbox{myexample}[0]{%
    width=4.5cm,%<-- width of the tcbox
    halign=center,%<-- align of text
    text height=0.1cm,enhanced,colback=green,colframe=black,
    % coltitle=black, <-- useless option
    boxrule=0.8mm, tikz={rotate=90,transform shape}}
\begin{document}
\begin{frame}

\begin{overlayarea}{0.9\textwidth}{0.4\textheight}% <- reserved area of the tikzpicture
Therefore\;\begin{tikzpicture}[baseline]
    \node  [anchor=base] (t1){ $\Pr(A,B)=0$};%<- the node is around math text
    \fill<2>[blue!40,fill opacity=.5%<-- the ellipse is build over the node with fill opacity=.5
    ] ([shift={(-4pt,.7pt)}]t1)% <- shift to center the ellipse on the node
     circle[x radius=4mm,y radius=2.2mm];
    \node<2>[below right= 5 mm and 5mm of t1] %<-- with positioning library second node is relative of first node
    (t2){
    \begin{myexample}
        ${\scriptstyle 0,1,2,3,4,4,5,6,7,8,9}$
    \end{myexample}
    } edge[->,out=180,in=-70,very thick] (t1.south);%<-- arrow from tcbox to text
    
    \end{tikzpicture}   
 \end{overlayarea}
\end{frame}

\end{document}

相关内容