在两张tikz图片之间画箭头
我想从一张 tikzpicture 到另一张 tikzpicture 绘制一个箭头,以包含在我在 Rmarkdown 中制作的 Beamer 演示文稿中。我尝试遵循此问题的答案:用箭头连接两张 tikz 图片。然而,它对我不起作用,因为它将两个图像连接在一起。这是我的初始代码(使其适合幻灯片中的要点):
编辑:我已将我的 YAML 包含在 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}
- \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
原始 tikzpictures 的图像,它们之间没有箭头 这是有效的,但两个 tikz 图片之间没有箭头。
这是我按照上面提供的链接的答案尝试的,其中我尝试将图像放入一张 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 的一个节点连接。 错误的 tikzpicture 的图像
我想要两个原始的 tikzpicture,它们之间有一个箭头,最好在5:ROSC 节点的高度。
I want to draw an arrow from one tikzpicture to another, to include in my Beamer presentation I am making in Rmarkdown. I tried following the answer to this question: Connecting two tikz pictures with arrow. However, it does not work for me as it connects the two images together instead. This is my initial code (to make it fit with bullet points in the slide):
Edit: I have inlcuded my YAML in 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}
- \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
Which works, but does not have an arrow between the two tikzpictures.
Here is what I tried following the answer of the link I provided above, where I tried putting the images into one tikzpicture and using scopes.
\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}
For some reason the pictures are now connected through the one node called 5: ROSC.
Image of the wrong tikzpicture
I want the two original tikzpictures with an arrow going between them, preferrably at the height of the 5:ROSC node.
Edit 2: I have included an image of what I would like the arrow to look like.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议使用
tikzmark
来完成这项工作:(需要至少两次编译才能获得正确的坐标)
这里与 rmarkdown 相同:
更新,
因为您的新草图没有显示箭头和图像之间的任何交互,只需添加第三列:
I suggest to use
tikzmark
s for this job:(needs at least two compilations to get the coordinates right)
Here the same in rmarkdown:
Update
As your new sketch does not show any interaction at all between your arrow and your images, just add a third column: