2

I am using beamer to create slides. I am not sure how to generate arrows from two sentences merging and pointing towards a word as shown in the below image.

enter image description here

1

1 Answer 1

5

This approach uses tikz and, in particular, referencing nodes outside the current picture (§17.13 of the manual, v.3.1.9a). I will first present the idea and then refactor it to be simpler to use.

At the end of each sentence, there is an invisible node (s1 and s2). There's also an invisible node (e1 and e2) at the right margin. We then make a node (w) with the "Word", midway between the nodes e1 and e2. We also make a coordinate (p) that is 1cm to the left of the word's left side. The arrows connect the node s1 (respectively, s2) to w via p, with perpendicular lines.

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{positioning,arrows.meta}
\tikzset{phantom/.style={inner sep=0,outer sep=0}}
\begin{document}
\begin{frame}
\begin{itemize}
\item Big sentence 1 aaaaaaaaaaaaaaaaa
      \tikz[baseline=(s1.base),remember picture] \node[phantom] (s1) {\strut}; \hfill
      \tikz[baseline=(e1.base),remember picture] \node[phantom] (e1) {\strut};
\item Big sentence 2 aaaaaaaaaaaaaaaaaaaaaaaa
      \tikz[baseline=(s2.base),remember picture] \node[phantom] (s2) {\strut}; \hfill
      \tikz[baseline=(e2.base),remember picture] \node[phantom] (e2) {\strut};
\end{itemize}
\begin{tikzpicture}[remember picture,overlay]
  \path (e1) -- (e2) node[midway,anchor=east] (w) {Word}
        (w.west) +(left:1cm) coordinate (p);
  \draw[-Stealth] (s1) -| (p) |- (w.west);
  \draw[-Stealth] (s2) -| (p) |- (w.west);
\end{tikzpicture}
\end{frame}
\end{document}

The result is the following: Result

With a little refactoring, this approach can be structured around two commands: \setpoint{p} for marking the end of a sentence as point p, and \mergepoints{p}{q}{Word} for drawing an arrow merging points p and q to the given word.

\newcommand\setpoint[1]{%
  \tikz[baseline=(s#1.base),remember picture] \node[phantom] (s#1) {\strut};
  \hfill
  \tikz[baseline=(e#1.base),remember picture] \node[phantom] (e#1) {\strut};
}
\newcommand{\mergepoints}[3]{%
  \begin{tikzpicture}[remember picture,overlay]
    \path (e#1) -- (e#2) node[midway,anchor=east] (w) {#3}
          (w.west) +(left:1cm) coordinate (p);
    \draw[-Stealth] (s#1) -| (p) |- (w.west);
    \draw[-Stealth] (s#2) -| (p) |- (w.west);
  \end{tikzpicture}
}

Then, the same example can be drawn as:

\begin{frame}
\begin{itemize}
  \item Big sentence 1 aaaaaaaaaaaaaaaaa \setpoint{1}
  \item Big sentence 2 aaaaaaaaaaaaaaaaaaaaaaaa \setpoint{2}
\end{itemize}
\mergepoints{1}{2}{Word}
\end{frame}

In fact, this can be used to construct more complex instances of the same idea, e.g.

\begin{frame}
Two sentences:
\begin{itemize}
  \item Big sentence 1 aaaaaaaaaaaaaaaaa \setpoint{1}
  \item Small sentence 1 aaaaaaaaa \setpoint{2}
\end{itemize}
and two more:
\begin{itemize}
  \item Big sentence 2 aaaaaaaaaaaaaaaaaaaaaaaa \setpoint{3}
  \item Small sentence 2 aaaaaaa \setpoint{4}
\end{itemize}
\mergepoints{1}{3}{Big}
\mergepoints{2}{4}{Small}
\end{frame}

which gives the following: More involved example

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