在两张tikz图片之间画箭头

Draw arrow between two tikz pictures

我想从一张 tikzpicture 到另一张 tikzpicture 绘制一个箭头,以包含在我在 Rmarkdown 中制作的 Beamer 演示文稿中。我试着按照这个问题的答案:Connecting two tikz pictures with arrow。但是,它对我不起作用,因为它将两个图像连接在一起。这是我的初始代码(使其符合幻灯片中的要点):

编辑:我在 Rmarkdown 中包含了我的 YAML。

---
title: "This title must be included in the first slide but is very very long"
subtitle: "Masters Thesis presentation"
institute: "My school"
author: First Last
date: March 2022
output: 
  beamer_presentation: 
    theme: "Madrid"
header-includes:
   - \AtBeginDocument{\title[short title for footline]{This title must be included in the first slide but is very very long}}
   - \usepackage{tikz}
   - \usepackage{subfig}
   - \usepackage{natbib}
   - \usetikzlibrary{automata, positioning, arrows, calc}
   - \usepackage{algorithm}
   - \usepackage{algpseudocode}
   - \usepackage{caption}
   - \captionsetup[table]{position=bottom}
   - \usepackage[utf8]{inputenc}
   - \usepackage{graphics}
   - \usepackage{amsmath}
   - \usepackage{bm}
---
# Recode to three states

\begin{columns}
\column{0.5\textwidth}
\begin{figure}[ht]
  \centering
  \resizebox{0.6\textwidth}{!}{% 
  \begin{tikzpicture}[every state/.style={minimum width={2cm} ,thick,align=center}]
  \node[state] (1) {1: DEAD};
  \node[state] at (3, 2) (3) {3:VFT};
  \node[state] at (6, 0) (5) {5:ROSC};
  \node[state] at (1.5, -3.3) (2) {2:ASY};
  \node[state] at (4.5, -3.3) (4) {4:PEA};
  
  \draw[<-] (1) -- node [midway,above] {} (2);
  \draw[<-] (1) -- node [midway,below] {} (3);
  \draw[<-] (1) -- node [midway,below] {} (4);
  \draw[<-] (1) -- node [midway,below] {} (5);
  
  \draw[<->] (2) -- node [midway,below] {} (3);
  \draw[<->] (2) -- node [midway,below] {} (4);
  \draw[<->] (2) -- node [midway,below] {} (5);
  
  \draw[<->] (3) -- node [midway,below] {} (4);
  \draw[<->] (3) -- node [midway,below] {} (5);
  
  \draw[<->] (4) -- node [midway,below] {} (5);
  \end{tikzpicture}
  }%
\end{figure}


\column{0.4\textwidth}
\begin{figure}%[H]
    \centering
    \resizebox{0.6\textwidth}{!}{% 
    \begin{tikzpicture}[>=stealth', shorten >=1pt, auto, scale=1, 
    transform shape, align=center, 
    state/.style={circle, draw, minimum size=2cm}]

    \node[state] at (0,0) (5) {5:ROSC};  
    \node[state] at (3,-2) (1) {1:DEAD};
    \node[state] at (3,2) (2) {2:PEASY};

    \path[->] (5) edge node {$h_{51}$} (1)
              (5) edge node {$h_{52}$} (2)
              (2) edge node {$h_{21}$} (1)
              (2) edge [bend left] node [right] {$h_{25}$} (5);

    \end{tikzpicture}
    }%
\end{figure}
\end{columns}

Steps to recode:

>- Combine states 2 and 4 into state 2
>- Write function that discards redundant rows (2 $\rightarrow$ 2)
>- Delete `from` = 3 rows
>- Expand dataset to keep censored cases
>- Delete `to` = 3 rows

Image of the original tikzpictures without arrow between them 哪个有效,但两个 tikzpictures 之间没有箭头。

这是我根据上面提供的 link 的回答尝试的,我尝试将图像放入一个 tikzpicture 并使用范围。

\begin{center}
\begin{tikzpicture}[every state/.style={minimum width={2cm} ,thick,align=center}]

\begin{scope}
  \node[state] (1) {1: DEAD};
  \node[state] at (3, 2) (3) {3:VFT};
  \node[state] at (6, 0) (5) {5:ROSC};
  \node[state] at (1.5, -3.3) (2) {2:ASY};
  \node[state] at (4.5, -3.3) (4) {4:PEA};
  
  \draw[<-] (1) -- node [midway,above] {} (2);
  \draw[<-] (1) -- node [midway,below] {} (3);
  \draw[<-] (1) -- node [midway,below] {} (4);
  \draw[<-] (1) -- node [midway,below] {} (5);
  
  \draw[<->] (2) -- node [midway,below] {} (3);
  \draw[<->] (2) -- node [midway,below] {} (4);
  \draw[<->] (2) -- node [midway,below] {} (5);
  
  \draw[<->] (3) -- node [midway,below] {} (4);
  \draw[<->] (3) -- node [midway,below] {} (5);
  
  \draw[<->] (4) -- node [midway,below] {} (5);
\end{scope}



\begin{scope}[xshift=6cm]
    \node[state] at (0,0) (5) {5:ROSC};  
    \node[state] at (3,-2) (1) {1:DEAD};
    \node[state] at (3,2) (2) {2:PEASY};
    \path[->] (5) edge node {$h_{51}$} (1)
              (5) edge node {$h_{52}$} (2)
              (2) edge node {$h_{21}$} (1)
              (2) edge [bend left] node [right] {$h_{25}$} (5);
\end{scope}

\draw[red,->] (6,0) -- (10,0);

\end{tikzpicture}
\end{center}

出于某种原因,图片现在通过名为 5 的节点连接:ROSC。 Image of the wrong tikzpicture

我想要两个原始的 tikzpictures,它们之间有一个箭头,最好在 5:ROSC 节点的高度。

编辑 2:我已经包含了我希望箭头看起来像的图像。

我建议使用 tikzmarks 来完成这项工作:

\documentclass{beamer}

\usepackage{tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{tikzmark}


\begin{document}
    
\begin{frame}
\begin{columns}
\begin{column}{0.5\textwidth}
\centering
  \begin{tikzpicture}[scale=0.6,transform shape,every state/.style={minimum width={2cm} ,thick,align=center},state/.style={circle, draw, minimum size=2cm}]
  \node[state] (1) {1: DEAD};
  \node[state] at (3, 2) (3) {3:VFT};
  \node[state] at (6, 0) (5) {\tikzmark{foo}5:ROSC};
  \node[state] at (1.5, -3.3) (2) {2:ASY};
  \node[state] at (4.5, -3.3) (4) {4:PEA};
  
  \draw[<-] (1) -- node [midway,above] {} (2);
  \draw[<-] (1) -- node [midway,below] {} (3);
  \draw[<-] (1) -- node [midway,below] {} (4);
  \draw[<-] (1) -- node [midway,below] {} (5);
  
  \draw[<->] (2) -- node [midway,below] {} (3);
  \draw[<->] (2) -- node [midway,below] {} (4);
  \draw[<->] (2) -- node [midway,below] {} (5);
  
  \draw[<->] (3) -- node [midway,below] {} (4);
  \draw[<->] (3) -- node [midway,below] {} (5);
  
  \draw[<->] (4) -- node [midway,below] {} (5);
  \end{tikzpicture}
\end{column}

\begin{column}{0.4\textwidth}
\centering
    \begin{tikzpicture}[scale=0.6,transform shape, >=stealth', shorten >=1pt, auto, scale=1, 
    transform shape, align=center, 
    state/.style={circle, draw, minimum size=2cm}]

    \node[state] at (0,0) (5) {5:ROSC};  
    \node[state] at (3,-2) (1) {1:DEAD};
    \node[state] at (3,2) (2) {\tikzmark{bar}2:PEASY};

    \path[->] (5) edge node {$h_{51}$} (1)
              (5) edge node {$h_{52}$} (2)
              (2) edge node {$h_{21}$} (1)
              (2) edge [bend left] node [right] {$h_{25}$} (5);

    \end{tikzpicture}
\end{column}
\end{columns}

\begin{tikzpicture}[remember picture,overlay]
\draw[red,->] (pic cs:foo) -- (pic cs:bar);
\end{tikzpicture}

\end{frame} 
    
\end{document}

(至少需要两次编译才能得到正确的坐标)


这里在rmarkdown中也是一样的:

---
title: "This title must be included in the first slide but is very very long"
subtitle: "Masters Thesis presentation"
institute: "My school"
author: First Last
date: March 2022
output: 
  beamer_presentation: 
    theme: "Madrid"
header-includes:
   - \AtBeginDocument{\title[short title for footline]{This title must be included in the first slide but is very very long}}
   - \usepackage{tikz}
   - \usepackage{subfig}
   - \usepackage{natbib}
   - \usetikzlibrary{automata, positioning, arrows, calc,tikzmark}
   - \usepackage{algorithm}
   - \usepackage{algpseudocode}
   - \usepackage{caption}
   - \captionsetup[table]{position=bottom}
   - \usepackage[utf8]{inputenc}
   - \usepackage{graphics}
   - \usepackage{amsmath}
   - \usepackage{bm}
---
# Recode to three states

\begin{columns}
\begin{column}{0.5\textwidth}
\centering
  \begin{tikzpicture}[scale=0.6,transform shape,every state/.style={minimum width={2cm} ,thick,align=center},state/.style={circle, draw, minimum size=2cm}]
  \node[state] (1) {1: DEAD};
  \node[state] at (3, 2) (3) {3:VFT};
  \node[state] at (6, 0) (5) {\tikzmark{foo}5:ROSC};
  \node[state] at (1.5, -3.3) (2) {2:ASY};
  \node[state] at (4.5, -3.3) (4) {4:PEA};
  
  \draw[<-] (1) -- node [midway,above] {} (2);
  \draw[<-] (1) -- node [midway,below] {} (3);
  \draw[<-] (1) -- node [midway,below] {} (4);
  \draw[<-] (1) -- node [midway,below] {} (5);
  
  \draw[<->] (2) -- node [midway,below] {} (3);
  \draw[<->] (2) -- node [midway,below] {} (4);
  \draw[<->] (2) -- node [midway,below] {} (5);
  
  \draw[<->] (3) -- node [midway,below] {} (4);
  \draw[<->] (3) -- node [midway,below] {} (5);
  
  \draw[<->] (4) -- node [midway,below] {} (5);
  \end{tikzpicture}
\end{column}

\begin{column}{0.4\textwidth}
\centering
    \begin{tikzpicture}[scale=0.6,transform shape, >=stealth', shorten >=1pt, auto, scale=1, 
    transform shape, align=center, 
    state/.style={circle, draw, minimum size=2cm}]

    \node[state] at (0,0) (5) {5:ROSC};  
    \node[state] at (3,-2) (1) {1:DEAD};
    \node[state] at (3,2) (2) {\tikzmark{bar}2:PEASY};

    \path[->] (5) edge node {$h_{51}$} (1)
              (5) edge node {$h_{52}$} (2)
              (2) edge node {$h_{21}$} (1)
              (2) edge [bend left] node [right] {$h_{25}$} (5);

    \end{tikzpicture}
\end{column}
\end{columns}

\begin{tikzpicture}[remember picture,overlay]
\draw[red,->] (pic cs:foo) -- (pic cs:bar);
\end{tikzpicture}

更新

由于您的新草图没有显示箭头和图像之间的任何交互,只需添加第三列:

\documentclass{beamer}

\usepackage{tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{tikzmark}


\begin{document}
    
\begin{frame}
\begin{columns}
\begin{column}{0.5\textwidth}
\centering
  \begin{tikzpicture}[scale=0.6,transform shape,every state/.style={minimum width={2cm} ,thick,align=center},state/.style={circle, draw, minimum size=2cm}]
  \node[state] (1) {1: DEAD};
  \node[state] at (3, 2) (3) {3:VFT};
  \node[state] at (6, 0) (5) {5:ROSC};
  \node[state] at (1.5, -3.3) (2) {2:ASY};
  \node[state] at (4.5, -3.3) (4) {4:PEA};
  
  \draw[<-] (1) -- node [midway,above] {} (2);
  \draw[<-] (1) -- node [midway,below] {} (3);
  \draw[<-] (1) -- node [midway,below] {} (4);
  \draw[<-] (1) -- node [midway,below] {} (5);
  
  \draw[<->] (2) -- node [midway,below] {} (3);
  \draw[<->] (2) -- node [midway,below] {} (4);
  \draw[<->] (2) -- node [midway,below] {} (5);
  
  \draw[<->] (3) -- node [midway,below] {} (4);
  \draw[<->] (3) -- node [midway,below] {} (5);
  
  \draw[<->] (4) -- node [midway,below] {} (5);
  \end{tikzpicture}
\end{column}

\begin{column}{.1\textwidth}
\tikz\draw[blue,->] (0,0) -- (\textwidth,0);
\end{column}

\begin{column}{0.4\textwidth}
\centering
    \begin{tikzpicture}[scale=0.6,transform shape, >=stealth', shorten >=1pt, auto, scale=1, 
    transform shape, align=center, 
    state/.style={circle, draw, minimum size=2cm}]

    \node[state] at (0,0) (5) {5:ROSC};  
    \node[state] at (3,-2) (1) {1:DEAD};
    \node[state] at (3,2) (2) {2:PEASY};

    \path[->] (5) edge node {$h_{51}$} (1)
              (5) edge node {$h_{52}$} (2)
              (2) edge node {$h_{21}$} (1)
              (2) edge [bend left] node [right] {$h_{25}$} (5);

    \end{tikzpicture}
\end{column}
\end{columns}

\end{frame} 
    
\end{document}