\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
% styles for flowcharts
\tikzstyle{block} = [rectangle, draw, text width=5em, text centered, rounded corners, minimum height=4em]
\begin{document}
\begin{frame}
\begin{tikzpicture}[node distance=2.6cm, auto, >=stealth]
% nodes
\node[block](Physiological Reflux)[0,0]{Physiological Reflux};
\node[block] (Symptomatic GERD) [right of=Physiological Reflux] {Symptomatic GERD};
\node[block,text width=2.8cm]
(Esophagitis) [right of=Symptomatic GERD, node distance=3.3cm] {Esophagitis};
\node[block] (Complicated GERD) [right of=Esophagitis, node distance=3.6cm] {Complicated GERD};
\node[block, textwidth=4cm] (Typical) [below left of=Symptomatic GERD, node distance=4cm] {{\bf Typical} \newline Heart burn \\ Regurgitation};
\node[block](Atypical)[below right of=Symptomatic GERD, node distance =4cm]{{\bf atypical}\\ \indent Chest pain\\dysphagia\\Cough \\ Asthma \\ Laryngitis };
\node [block](Complicated)[below of =Complicated GERD, node distance =4cm]{ {\bf Complicated }\\Ulcerations\\ Hemorrhages \\ Barret's esophagus \\ Stricture\\ Adenocarcinoma };
% edges
\draw[->] (Physiological Reflux) -- (Symptomatic GERD);
\draw[->] (Symptomatic GERD) -- (Esophagitis);
\draw[->] (Esophagitis) -- (Complicated GERD);
\draw[->] (Symptomatic GERD) -- (Typical);
\draw[->] (Symptomatic GERD)-- (Atypical);
\draw[->](Complicated GERD)--(Complicated);
%\draw[->] (e) -- (f);
%\draw[->] (f) -- (g);
%\draw[->] (g) -- (h);
\end{tikzpicture}
\end{frame}
\end{document}
答案1
我添加了一些颜色(可选)。
我从弃用
\tikzstyle
改为\tikzset
。我把这个图形稍微缩小了一点。
最重要的变化是
positioning
库的使用以及从弃用的语法转变of =
为更合适的语法= of
(这允许更好地定位节点)。
代码:
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes,arrows}
% styles for flowcharts
\tikzset{
block/.style = {
rectangle,
thick,
text width=6em,
align=center,
rounded corners,
draw=cyan!40!black,
fill=cyan!20,
inner ysep=10pt
}
}
\begin{document}
\begin{frame}
\centering
\begin{tikzpicture}[
node distance = 2cm and 0.8cm,
>=stealth,
scale=0.8,
transform shape
]
% nodes
\node[block]
(Physiological Reflux) {Physiological Reflux};
\node[block,right = of Physiological Reflux]
(Symptomatic GERD) {Symptomatic GERD};
\node[block,right = of Symptomatic GERD]
(Esophagitis) {Esophagitis};
\node[block,right = of Esophagitis]
(Complicated GERD) {Complicated GERD};
\node[block,below=of Symptomatic GERD,xshift=-2cm]
(Typical) {{\bfseries Typical} \\ Heart burn \\ Regurgitation};
\node[block,below=of Symptomatic GERD,xshift=2cm]
(Atypical) {{\bfseries Atypical}\\ Chest pain\\dysphagia\\Cough \\ Asthma \\ Laryngitis};
\node[block,below = of Complicated GERD,text width=8em]
(Complicated) {{\bfseries Complicated }\\Ulcerations\\ Hemorrhages \\ Barret's esophagus \\ Stricture\\ Adenocarcinoma };
% edges
\begin{scope}[cyan!40!black]
\draw[->] (Physiological Reflux) -- (Symptomatic GERD);
\draw[->] (Symptomatic GERD) -- (Esophagitis);
\draw[->] (Esophagitis) -- (Complicated GERD);
\draw[->] (Symptomatic GERD) -- (Typical);
\draw[->] (Symptomatic GERD)-- (Atypical);
\draw[->](Complicated GERD)--(Complicated);
%\draw[->] (e) -- (f);
%\draw[->] (f) -- (g);
%\draw[->] (g) -- (h);
\end{scope}
\end{tikzpicture}
\end{frame}
\end{document}
请注意,这\bf
是一个旧的 TeX 命令,不应在现代 LaTeX 文档中使用;\bfseries
而是使用。
另一个可能有用的改变是使用叠加层在多张幻灯片上显示图形:
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes,arrows}
% style for overlays
\tikzset{
invisible/.style={opacity=0},
visible on/.style={alt=#1{}{invisible}},
alt/.code args={<#1>#2#3}{%
\alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} % \pgfkeysalso doesn't change the path
},
}
% styles for flowcharts
\tikzset{
block/.style = {
rectangle,
thick,
text width=6em,
align=center,
rounded corners,
draw=cyan!40!black,
fill=cyan!20,
inner ysep=10pt
}
}
\begin{document}
\begin{frame}
\centering
\begin{tikzpicture}[
node distance = 2cm and 0.8cm,
>=stealth,
scale=0.8,
transform shape
]
% nodes
\node[block,visible on=<1->]
(Physiological Reflux) {Physiological Reflux};
\node[block,right = of Physiological Reflux,visible on=<2->]
(Symptomatic GERD) {Symptomatic GERD};
\node[block,right = of Symptomatic GERD,visible on=<5->]
(Esophagitis) {Esophagitis};
\node[block,right = of Esophagitis,visible on=<6->]
(Complicated GERD) {Complicated GERD};
\node[block,below=of Symptomatic GERD,xshift=-2cm,visible on=<3->]
(Typical) {{\bfseries Typical} \\ Heart burn \\ Regurgitation};
\node[block,below=of Symptomatic GERD,xshift=2cm,visible on=<4->]
(Atypical) {{\bfseries Atypical}\\ Chest pain\\dysphagia\\Cough \\ Asthma \\ Laryngitis};
\node[block,below = of Complicated GERD,text width=8em,visible on=<7>]
(Complicated) {{\bfseries Complicated }\\Ulcerations\\ Hemorrhages \\ Barret's esophagus \\ Stricture\\ Adenocarcinoma };
% edges
\begin{scope}[cyan!40!black]
\draw[->,visible on=<2->] (Physiological Reflux) -- (Symptomatic GERD);
\draw[->,visible on=<5->] (Symptomatic GERD) -- (Esophagitis);
\draw[->,visible on=<6->] (Esophagitis) -- (Complicated GERD);
\draw[->,visible on=<3->] (Symptomatic GERD) -- (Typical);
\draw[->,visible on=<4->] (Symptomatic GERD)-- (Atypical);
\draw[->,visible on=<7->](Complicated GERD)--(Complicated);
%\draw[->] (e) -- (f);
%\draw[->] (f) -- (g);
%\draw[->] (g) -- (h);
\end{scope}
\end{tikzpicture}
\end{frame}
\end{document}
答案2
基于 Gonzalo 代码的解决方案。我认为scale=0.8, transform shape
没有必要。可以修改node distance
并使用font
。使用 pgf 3 可以使用node font
。那么就没有必要使用text width
,我们可以避免最后一个范围
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes,arrows}
% styles for flowcharts
\tikzset{
block/.style = {
rectangle,
thick,
align=center,
rounded corners,
draw=cyan!40!black,
fill=cyan!20,
inner ysep=10pt
},
ar/.style = {cyan!40!black,->}
}
\begin{document}
\begin{frame}
\centering
\begin{tikzpicture}[
node distance = 1.75 cm and 0.75cm,font=\tiny,
>=stealth
]
% nodes
\node[block]
(Physiological Reflux) {Physiological Reflux};
\node[block,right = of Physiological Reflux]
(Symptomatic GERD) {Symptomatic GERD};
\node[block,right = of Symptomatic GERD]
(Esophagitis) {Esophagitis};
\node[block,right = of Esophagitis]
(Complicated GERD) {Complicated GERD};
\node[block,below=of Symptomatic GERD,xshift=-1.75cm]
(Typical) {{\bfseries Typical} \\ Heart burn \\ Regurgitation};
\node[block,below=of Symptomatic GERD,xshift=1.75cm]
(Atypical) {{\bfseries Atypical}\\ Chest pain\\dysphagia\\Cough \\ Asthma \\ Laryngitis};
\node[block,below = of Complicated GERD]
(Complicated) {{\bfseries Complicated }\\Ulcerations\\ Hemorrhages \\ Barret's esophagus \\ Stricture\\ Adenocarcinoma };
% edges
\draw[ar] (Physiological Reflux) -- (Symptomatic GERD);
\draw[ar] (Symptomatic GERD) -- (Esophagitis);
\draw[ar] (Esophagitis) -- (Complicated GERD);
\draw[ar] (Symptomatic GERD) -- (Typical);
\draw[ar] (Symptomatic GERD) -- (Atypical);
\draw[ar] (Complicated GERD)--(Complicated);
\end{tikzpicture}
\end{frame}
\end{document}