我有一个生成流程图的代码。它并不完整,除了一切之外,它只需要箭头。我遇到的问题是流程节点、梯形,尽管我预先定义了它们,但它们的大小却不一样。
代码:
\documentclass{article}
%----------------------------------------------------------------------------------------
% PACKAGES
%----------------------------------------------------------------------------------------
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}
\usetikzlibrary{positioning}
\tikzstyle{startstop} = [rectangle, text centered, rounded corners, minimum width=3cm, minimum height=1cm, draw=black, fill=red!30]
\tikzstyle{io} = [trapezium, trapezium left angle=70, trapezium right angle=-70,text centered,text width = 2cm,minimum height=1cm, minimum width=2cm, draw=black, fill=blue!30]
\tikzstyle{process} = [rectangle, text centered, minimum width=3cm, minimum height=1cm, draw=black, fill=orange!30]
\tikzstyle{decision} = [diamond, text badly centered, text width=4.5em, draw=black, fill=green!30]
\tikzstyle{arrow} = [thick,->,>=stealth]
% Does Node distance by sides instead of centers.
\tikzstyle{my below of} = [below=of #1.south]
\tikzstyle{my right of} = [right=of #1.east]
\tikzstyle{my left of} = [left=of #1.west]
\tikzstyle{my above of} = [above=of #1.north]
%----------------------------------------------------------------------------------------
% DOCUMENT INFO
%----------------------------------------------------------------------------------------
\begin{document}
\begin{tikzpicture}[node distance=0.1cm,auto]
\node (Start) [startstop] {Program Startup};
\node (UsrStat) [decision, my below of=Start] {New or Returning User?};
\node (CrtUsr) [process, my right of=UsrStat] {Create User};
\node (LogCred) [io, my below of=UsrStat] {Login Credentials};
\node (ValCred) [process, my below of=LogCred] {Validate Credentials};
\node (ValRes) [decision, my below of=ValCred] {Valid or Invalid Credentials?};
\node (Login) [process, my below of=ValRes] {Login};
\node (ConUI) [process, my below of=Login] {Contact UI};
\node (Com) [io, my below of=ConUI, text width = 2.1cm] {Command};
\node (ExDec) [decision, my below of=Com] {Exit Command?};
\node (ComPros) [process, my right of=Com] {Command Process};
\node (Exit) [startstop, my below of=ExDec] {Exit Program};
\end{tikzpicture}
\end{document}
但当我运行它时,我得到以下结果我尝试过更改文本宽度、最小高度和宽度,但似乎无法正确设置。我希望它们的最小宽度与其他宽度一样为 2cm。
答案1
乍一看,这看起来像是一个错误,但是阅读文档时,敲击评论表明,在这种情况下trapezium stretches=true
应该将选项添加到节点样式定义中:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{arrows, positioning, shapes.geometric, }
\tikzset{flowchart/.style = {
base/.style = {draw=black,
inner sep=1mm, outer sep=0mm,
text width=3cm, minimum height=1cm,
align=flush center},
startstop/.style = {base, fill=red!30},
process/.style = {base, fill=orange!30},
decision/.style = {base, diamond, aspect=1.2, fill=green!30},
io/.style = {base, trapezium,
trapezium left angle=70, trapezium right angle=-70,
trapezium stretches=true, %%%% <-- added
fill=blue!30},
arrow/.style = {thick, -stealth}
}}
\begin{document}
\begin{tikzpicture}[flowchart,
node distance=0.5cm, auto
]
\node (n1) [io] {Login Credentials};
\node (n2) [io, below=of n1] {Command};
\node (n3) [io, below=of n2] {Command Command Command};
\node (n4) [process, below=of n3] {Validate Credentials};
%
\draw[dashed]
(n4.north west) -- ++ (0,5)
(n4.north east) -- ++ (0,5);
\end{tikzpicture}
\end{document}
无关: 上述 MWE 与您的 MWE 相比有以下变化:
- 相反
\tikzstyle
,这被认为是过时\tikzset
的 \tikzset
包含流程图中使用的节点定义的 被命名为“流程图”(如果您不喜欢,只需删除 的这一部分\tikzset
)。因此,tikzpicture
带有流程图的 s 必须用其名称调用此设置(请参阅上面的 MWE)- 定位时(直接)使用
positioning
库中确定的语法 - 定义是通用
base
样式,然后在所有其他节点的样式中使用