3

I have a beamer frame as shown below. It draws two nodes of tikzpeople and then an arrow between them. However, what I want to draw is a rectangle in the middle of the arrow and write some text inside the rectangle. So something like "NODE --[some text]--> NODE". How can I draw a closed rectangle and fill it with text?

\documentclass[xcolor=table,10pt,aspectratio=169]{beamer}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[american]{babel}
\usepackage{amsmath,amssymb,amsthm}
\usepackage[beamer,customcolors]{hf-tikz}
\usepackage{booktabs} % Tables
\usepackage{tikz}
\usetikzlibrary{
    arrows,
    calc,
    chains,
    decorations,
    decorations.text,
    decorations.pathmorphing,
    matrix,
    overlay-beamer-styles,
    positioning,
    shapes,
    tikzmark
}
\usepackage{tikzpeople}
\tikzset{hl/.style={
    set fill color=red!80!black!40,
    set border color=red!80!black,
  },
}

\begin{document}

\begin{frame}{Test}
\begin{figure}
    \begin{tikzpicture}[font=\small]
        \node[alice,minimum size=1.5cm] (A) {};
        \node[bob,right=8cm of A,minimum size=1.5cm,mirrored] (B) {};
        \draw (A.0) edge[->] node[above] {} (B.180);
    \end{tikzpicture}
\end{figure}    
\end{frame}

\end{document}
1
  • please see the answer below - I could not get package tikzpeople to compile so have commented it out -- used two simple nodes A and B with arrow in between -- positions can be specified as midway, near end, near start with white fill behind the text
    – js bibra
    Commented Feb 19, 2021 at 11:08

2 Answers 2

6

Here you have two solutions. The first one draws the node and fills it with white to cover the line which goes behind it. The second is better when you want to respect the background. In this case, you draw the node and later on two lines between them.

\documentclass[xcolor=table,10pt,aspectratio=169]{beamer}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[american]{babel}
\usepackage{amsmath,amssymb,amsthm}
\usepackage[beamer,customcolors]{hf-tikz}
\usepackage{booktabs} % Tables
\usepackage{tikz}
\usetikzlibrary{
    arrows,
    calc,
    chains,
    decorations,
    decorations.text,
    decorations.pathmorphing,
    matrix,
    overlay-beamer-styles,
    positioning,
    shapes,
    tikzmark
}
\usepackage{tikzpeople}
\tikzset{hl/.style={
    set fill color=red!80!black!40,
    set border color=red!80!black,
  },
}

\begin{document}

\begin{frame}{Test}
\begin{figure}
    \begin{tikzpicture}[font=\small]
        \node[alice,minimum size=1.5cm] (A) {};
        \node[bob,right=8cm of A,minimum size=1.5cm,mirrored] (B) {};
        \draw (A) edge[->] node[draw, fill=white, text width=2cm, align=center] {some text inside a rectangle} (B);
    \end{tikzpicture}
\end{figure}    

\begin{figure}
    \begin{tikzpicture}[font=\small]
        \node[alice,minimum size=1.5cm] (A) {};
        \node[bob,right=8cm of A,minimum size=1.5cm,mirrored] (B) {};
        \path (A) -- node[draw, text width=2cm, align=center] (C) {some text inside a rectangle} (B);
        \draw[->] (A)--(C);
        \draw[->] (C)--(B);
    \end{tikzpicture}
\end{figure}    

\end{frame}

\end{document}

enter image description here

0
3

enter image description here

\documentclass[xcolor=table,10pt,aspectratio=169]{beamer}

%\usepackage[T1]{fontenc}
%\usepackage[utf8]{inputenc}
%\usepackage[american]{babel}
%\usepackage{amsmath,amssymb,amsthm}
%\usepackage[beamer,customcolors]{hf-tikz}
%\usepackage{booktabs} % Tables
\usepackage{tikz}
\usetikzlibrary{
    arrows,
    calc,
    chains,
    decorations,
    decorations.text,
    decorations.pathmorphing,
    matrix,
    overlay-beamer-styles,
    positioning,
    shapes,
    tikzmark
}
%\usepackage{tikzpeople}
%\tikzset{hl/.style={
%       set fill color=red!80!black!40,
%       set border color=red!80!black,
%   },
%}

\begin{document}
    
    \begin{frame}{Test}
%       \begin{figure}
            \begin{tikzpicture}[font=\small]
                \node[]at(0,0) (A) {};
                \node[]at(5,0) (B) {};
                \draw (A.0) edge[->,]node [midway, fill=white] {Label Text} (B.180);
            \end{tikzpicture}
%       \end{figure}    
    \end{frame}
    
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .