我得到了类似下面屏幕截图中显示的简单流程图。但是,我想垂直移动箭头,使它们位于中间,而不是位于行的顶部。
我使用的代码复制如下。有人能告诉我应该做哪些更改才能将箭头移到中间吗?谢谢!
\documentclass[table, 11pt, aspectratio=169]{beamer}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{calc}
\usetikzlibrary{arrows}
\usetikzlibrary{matrix,shapes,arrows}
\tikzset{
arrow/.style={draw,thick,->,>=stealth},
}
\usepackage[most]{tcolorbox}
\tcbset{
boxsep=-1pt, left=-2pt, right=-2pt,
boxrule=0.5pt,
colframe=black, colback=white, sharp corners
}
\begin{document}
\begin{frame}{}
\begin{minipage}{\textwidth}
\begin{tikzpicture}[
node distance=25pt,
every edge/.style={arrow}
]
\node[text width=0.25\textwidth] (A) {
\begin{tcolorbox}[title={},coltitle=black,attach title to upper={},enhanced jigsaw]
\centering
Some text
\end{tcolorbox}
};
\node[text width=0.25\textwidth] (B) [right=of A.east] {
\begin{tcolorbox}[title=\parbox{\textwidth}{},coltitle=black,attach title to upper={},enhanced jigsaw]
\centering
Some text
\end{tcolorbox}
};
\node[text width=0.25\textwidth] (C) [right=of B.east] {
\begin{tcolorbox}[title=\parbox{\textwidth}{},coltitle=black,attach title to upper={},enhanced jigsaw]
\centering
Some text
\end{tcolorbox}
};
\draw[arrow] (A) -- (B);
\draw[arrow] (B) -- (C);
\end{tikzpicture}
\end{minipage}
\end{frame}
\end{document}
答案1
您可以考虑以下简单的 MWE:
\documentclass[11pt, aspectratio=169]{beamer}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{arrows.meta,
chains,
positioning}
\begin{document}
\begin{frame}{}
\begin{center}
\begin{tikzpicture}[
node distance = 25pt,
start chain = going right,
arr/.style = {-Straight Barb, thick, shorten <=2pt, shorten >=2pt},
N/.style = {draw, thick, minimum width=0.25*\linewidth,
on chain, join=by arr}
]
\node (A) [N] {Some text};
\node (B) [N] {Some text};
\node (B) [N] {Some text};
\end{tikzpicture}
\end{center}
\end{frame}
\end{document}
- 可以看到,在MWE中使用了
chains
库来定位节点,为节点定义了通用样式N
,节点之间的箭头通过宏绘制join
。 - 我看不出有任何使用的理由
tcolorbox
(至少从你的问题中看不出来)。
附录1:
如果您喜欢使用带标题的节点,可以使用shapes.multipart
库来实现。以下 MWE 显示了tcolorbox
使用它的“模拟”:
\documentclass[11pt, aspectratio=169]{beamer}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
chains,
positioning,
shadows, shapes.multipart}
% for emulation tcolorbox with title
% unfortunately it is still not part of shapes.multipart library :-(
\pgfdeclarelayer{foreground}
\pgfdeclarelayer{background}
\pgfsetlayers{background,main,foreground}
\makeatletter
\def\tikz@extra@preaction#1{% hackery which enable preactions
% in multi-part node on a different layer
% suggested by Mark Wibrow on c.t.t. (2010)
{%
\pgfsys@beginscope%
\setbox\tikz@figbox=\box\voidb@x%
\begingroup\tikzset{#1}\expandafter\endgroup%
\expandafter\def\expandafter\tikz@preaction@layer
\expandafter{\tikz@preaction@layer}%
\ifx\tikz@preaction@layer\pgfutil@empty%
\path[#1];% do extra path
\else%
\begin{pgfonlayer}{\tikz@preaction@layer}%
\path[#1];%
\end{pgfonlayer}
\fi%
\pgfsyssoftpath@setcurrentpath\tikz@actions@path% restore
\tikz@restorepathsize%
\pgfsys@endscope%
}%
}
\let\tikz@preaction@layer=\pgfutil@empty
\tikzset{preaction layer/.store in=\tikz@preaction@layer}
\makeatother
\begin{document}
\begin{frame}[fragile] % <--- needed for style definition with #
\frametitle{test with of the Ti*k*Z library \texttt{shapes.multipart}
\begin{center}
\begin{tikzpicture}[
node distance = 25pt,
start chain = going right,
arr/.style = {-Straight Barb, thick, shorten <=4pt, shorten >=2pt},
mpnv/.style args = {#1/#2}{% multi part node horisontal % <---
rectangle split, rectangle split parts=2,
rectangle split part fill={blue!70!black, white},
preaction layer=background, % <-- prepare layer for drop shadow
drop shadow,
text width = 0.25*\linewidth, align=center,
draw, thick, rounded corners,
node contents = {\nodepart[font=\bfseries, text=yellow]{one} #1 % for title
\nodepart[align=left]{two} #2}, % for main text
on chain, join=by arr
}
]
\node (A) [mpnv=title/some longer text in wo lines];
\node (B) [mpnv=title/some short text];
\node (B) [mpnv=title/some text];
\end{tikzpicture}
\end{center}
\end{frame}
\end{document}
附录2:
如果你更喜欢使用 ses tcolorbox
,那么请尝试答案中提出的解决方案在两个颜色框之间添加箭头,您的问题实际上是重复的。将其应用于您的案例,MWE 可以是:
\documentclass[11pt, aspectratio=169]{beamer}
\usepackage[many]{tcolorbox}
\usetikzlibrary{arrows.meta,
chains,
positioning}
\tcbset{%
boxrule=2pt,
colback=white, % background color
colframe=cyan, % frame colour
halign=left,
valign=center,
sharp corners=all,
center title,
lower separated=false,
fonttitle=\sffamily\bfseries\large,
adjusted title=center,
width=0.25\linewidth % added
}
\begin{document}
\begin{frame}
\frametitle{test with \texttt{tcolorbox}}
\begin{center}
\begin{tikzpicture}[
node distance = 25pt,
start chain = going right,
arr/.style = {draw=cyan, -{Straight Barb[scale=0.8]}, line width=2pt,
shorten <=2pt, shorten >=2pt},
N/.style = {on chain, join=by arr}
]
\node(A) [N] {
\begin{tcolorbox}[title= Title 1]
some longer text in three lines
\end{tcolorbox}
};
\node(B) [N] { % added position of second box
\begin{tcolorbox}[title=Title 2]
some short text
\end{tcolorbox}
};
\node(C) [N] { % added position of second box
\begin{tcolorbox}[title=Title 3]
some text
\end{tcolorbox}
};
\end{tikzpicture}
\end{center}
\end{frame}
\end{document}