我正在尝试在 Beamer 中构建以下流程图,并希望得到一些关于如何构建的答案。我想要的是这样的:
我开始使用 tikz 包执行此操作,但遇到了两个主要麻烦。
问题 1)如何获取与 No 对应的箭头
问题 2)如何真正让这个图形适合投影仪幻灯片。
我将附上我目前拥有的代码。我\resizebox
也尝试过使用该命令,但没有效果。
\documentclass[t,compress,10pt,xcolor=dvipsnames]{beamer}
\definecolor{LHCblue}{RGB}{4, 114, 255}
\usecolortheme[named=LHCblue]{structure}
\usepackage[bars]{beamerthemetree} %Beamer theme v 2.2
%\usepackage{kerkis}
\setbeamercovered{invisible}
\usetheme{Ilmenau} % Beamer theme v 3.0
\useoutertheme[subsection=true]{smoothbars}%Beamer Outer Theme-circles on top
%\usefonttheme{serif}
\useinnertheme{circles} %rectangle bullet points instead of circle ones
\usepackage{beamerthemebars}
%\usefonttheme[mathonly]{serif}
\usepackage{amsmath,amssymb,mathrsfs,fancyhdr,syntonly,lastpage,hyperref,graphicx,subfigure}
\usepackage{natbib}
\usepackage{algorithm2e}
\usepackage{animate}
\setbeamerfont{section in toc}{size=\normalsize}
\setbeamerfont{subsection in toc}{size=\tiny}
\setbeamertemplate{navigation symbols}{}%remove navigation symbols
\usepackage{times}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}
\tikzstyle{startstop} = [rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=red!30]
\tikzstyle{io} = [trapezium, trapezium left angle=70, trapezium right angle=110, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=blue!30]
\tikzstyle{process} = [rectangle, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=blue!30]
\tikzstyle{decision} = [rectangle, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=green!30]
\tikzstyle{arrow} = [thick,->,>=stealth]
\begin{document}
\begin{frame}
\frametitle{Hierarchy of decisions}
\resizebox{2in}{2in}{
\begin{tikzpicture}[node distance=2cm]
\node (start) [startstop] {User Input};
\node (in1) [decision, below of=start] {Is the input valid?};
\node (out1) [process, below of=in1] {Make of Vehicle};
\node (out2) [process, below of=out1] {Model of Vehicle};
\node (out3) [process, below of=out2] {Body Type};
\draw [arrow] (start) -- (in1);
%\draw [arrow] (in1)-| ([xshift=-0.25cm]pro1.south west) |- (start);
\end{tikzpicture}}
\end{frame}
\end{document}
您可以随意使用任何我不使用的命令,或者重新定义颜色和形状。我也很乐意获得代码来执行此操作,而不必实际使用我的代码。
答案1
使用链条的一种可能性:
代码:
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows,chains}
\tikzset{
startstop/.style={
rectangle,
rounded corners,
minimum width=3cm,
minimum height=1cm,
align=center,
draw=black,
fill=red!30
},
process/.style={
rectangle,
minimum width=3cm,
minimum height=1cm,
align=center,
draw=black,
fill=blue!30
},
decision/.style={
rectangle,
minimum width=3cm,
minimum height=1cm, align=center,
draw=black,
fill=green!30
},
arrow/.style={thick,->,>=stealth},
dec/.style={
ellipse,
align=center,
draw=black,
fill=green!30
},
}
\begin{document}
\begin{frame}
\frametitle{Hierarchy of decisions}
\centering
%\resizebox{!}{.8\textheight}{% if required
\begin{tikzpicture}[
start chain=going below,
every join/.style={arrow},
node distance=0.6cm
]
\node (start) [startstop,on chain,join] {User Input};
\node (in1) [dec,on chain] {Is the input valid?};
\node (out1) [process,on chain,join] {Make of Vehicle};
\node (out2) [process,on chain,join] {Model of Vehicle};
\node (out3) [process,on chain,join] {Body Type};
\draw[arrow] (in1.east) -- node[auto] {No} ++(20pt,0pt) |- (start.east);
\draw[arrow] (start) -- node[left] {Yes} (in1);
\end{tikzpicture}%
%}
\end{frame}
\end{document}
现在使用该positioning
库:
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows,positioning}
\tikzset{
startstop/.style={
rectangle,
rounded corners,
minimum width=3cm,
minimum height=1cm,
align=center,
draw=black,
fill=red!30
},
process/.style={
rectangle,
minimum width=3cm,
minimum height=1cm,
align=center,
draw=black,
fill=blue!30
},
decision/.style={
rectangle,
minimum width=3cm,
minimum height=1cm, align=center,
draw=black,
fill=green!30
},
arrow/.style={draw,thick,->,>=stealth},
dec/.style={
ellipse,
align=center,
draw=black,
fill=green!30
},
}
\begin{document}
\begin{frame}
\frametitle{Hierarchy of decisions}
\centering
%\resizebox{!}{.8\textheight}{% if required
\begin{tikzpicture}[
node distance=0.6cm,
every edge/.style={arrow}
]
\node (start) [startstop] {User Input};
\node (in1) [dec,below=of start] {Is the input valid?};
\node (out1) [process,below=of in1] {Make of Vehicle};
\node (out2) [process,below=of out1] {Model of Vehicle};
\node (out3) [process,below=of out2] {Body Type};
\draw[arrow] (in1.east) -- node[auto] {No} ++(20pt,0pt) |- (start.east);
\draw[arrow] (start) -- node[left] {Yes} (in1);
\path
(in1) edge (out1)
(out1) edge (out2)
(out2) edge (out3);
\end{tikzpicture}%
%}
\end{frame}
\end{document}
一些评论
- 我从旧的语法改为新的
\tikzstyle
语法\tikzset
。 - 如果您决定不使用链,请使用
=of
定位库中的语法而不是of=
。 - 如果需要,可以
\resizebox
用来控制高度(请参阅代码中的注释行)。 - 我
dec
使用库ellipse
中的形状 定义了一种样式shapes.geometric
。 - 您可以使用 控制节点之间的距离
node distance
。
答案2
这从你的代码开始,尽管我也喜欢chains
。如果你把东西弄小一点,你不需要调整图形的大小。我还把你的\tikzstyle
s 转换为\tikzset
因为以前的语法已被弃用。
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,arrows}
\tikzset{
basics/.style={minimum width=30mm, minimum height=7.5mm, text centered, draw=black},
startstop/.style={rectangle, rounded corners, basics, fill=red!30},
io/.style={trapezium, trapezium left angle=70, trapezium right angle=110, basics, fill=blue!30},
process/.style={rectangle, basics, fill=blue!30},
decision/.style={ellipse,basics, fill=green!30},
arrow/.style={thick,->,>=stealth},
}
\begin{document}
\begin{frame}
\frametitle{Hierarchy of decisions}
\begin{tikzpicture}[node distance=17.5mm]
\node (start) [startstop] {User Input};
\node (in1) [decision, below of=start] {Is the input valid?};
\node (out1) [process, below of=in1] {Make of Vehicle};
\node (out2) [process, below of=out1] {Model of Vehicle};
\node (out3) [process, below of=out2] {Body Type};
\foreach \i/\j/\k in {start/in1/,in1/out1/yes,out1/out2/,out2/out3/}
\draw [arrow] (\i) -- node[anchor=east] {\k} (\j);
\draw [arrow] (in1.east) -- +(20pt,0) |- (start.east) node [pos=.25, right] {No};
\end{tikzpicture}
\end{frame}
\end{document}
编辑
如果您想调整箭头的长度,这里有一个版本可以让您指定每个节点的节点距离(以毫米为单位):
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,arrows,positioning}
\tikzset{
basics/.style={minimum width=30mm, minimum height=7.5mm, text centered, draw=black},
startstop/.style={rectangle, rounded corners, basics, fill=red!30},
io/.style={trapezium, trapezium left angle=70, trapezium right angle=110, basics, fill=blue!30},
process/.style={rectangle, basics, fill=blue!30},
decision/.style={ellipse,basics, fill=green!30},
arrow/.style={thick,->,>=stealth},
}
\begin{document}
\begin{frame}
\frametitle{Hierarchy of decisions}
\begin{tikzpicture}
\node (start) [startstop] {User Input};
\node (in1) [decision, below=10mm of start] {Is the input valid?};
\foreach \i/\j/\k/\m/\n in
{%
in1/out1/yes/15/Make of Vehicle,
out1/out2//7.5/Model of Vehicle,
out2/out3//9/Body Type
}
{
\node (\j) [process, below=\m mm of \i] {\n};
\draw [arrow] (\i) -- node[anchor=east] {\k} (\j);
}
\draw [arrow] (in1.east) -- +(20pt,0) |- (start.east) node [pos=.25, right] {No};
\end{tikzpicture}
\end{frame}
\end{document}
显然,您可能不希望每一个都有不同的值 - 这只是为了说明:
但chains
图书馆确实会容易得多;)。