我不得不再次请求你的帮助。我正在尝试制作一个框图,一个非常简单的框图。
到目前为止我已经到了这一部分:
\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
%%%<
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}%
%%%>
\begin{document}
\pagestyle{empty}
% Define block styles
\tikzstyle{answer} = [rectangle, draw, text width=15em, text badly centered, node distance=1cm, inner sep=0pt, minimum height=4em]
\tikzstyle{block} = [rectangle, draw, text width=30em, text centered, rounded corners, minimum height=4em]
\tikzstyle{line} = [draw, -latex']
\begin{tikzpicture}[node distance = 2cm, auto]
% Place nodes
\node [block] (development) {text};
\node [block, below of=development] (quantitive) {text};
\node [block, below of=quantitive] (significances) {text};
\node [block, below of=significances] (utility) {text};
\node [block, below of=utility] (optimization) {text};
\node [block, below of=optimization] (decide) {text?};\\
\matrix [column sep=2mm,row sep=3mm] {\node [answer, below of=decide, node distance=1cm] (answerno) {text}; & \node [answer, below of=decide, node distance=1cm] (answeryes) {text};\\};
% Draw edges
\path [line] (development) -- (quantitive);
\path [line] (quantitive) -- (significances);
\path [line] (significances) -- (utility);
\path [line] (utility) -- (optimization);
\path [line] (optimization) -- (decide);
\path [line] (decide) -- node {No} (answerno);
\path [line] (decide) -- node {Yes} (answeryes);
\path [line] (answerno) -- (development);
\end{tikzpicture}
\end{document}
而且它会产生令人讨厌的视图。有没有这样的两个箭头的选项?或者我必须重新考虑图表设计。欢迎提出任何建议。 睡眠
答案1
另一种更简洁的代码是使用来自包chain
和的宏quotes
:
\documentclass[margin=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, chains, positioning, quotes}
\begin{document}
\begin{tikzpicture}[
node distance = 5mm and 0mm,
start chain = A going below,
base/.style = {rectangle, draw, rounded corners,
minimum height=2em, text width=15em, align=flush center,
inner sep=2mm},
answer/.style = {base, text width=15em},
block/.style = {base, text width=32em, on chain, join=by line},
line/.style = {-Stealth},
]
% Place nodes
\begin{scope}[every node/.style={block}]
\node {text}; % name: A-1
\node {text};
\node {text};
\node {text};
\node {text};
\node {text}; % A-6
\end{scope}
\node (answerno) [answer, below right=of A-6.south west] {text};
\node (answeryes) [answer, below left=of A-6.south east] {text};
% Draw edges
\draw[line] (A-6.south -| answerno.north) to ["No"] (answerno);
\draw[line] (A-6.south -| answeryes.north) to ["Yes"] (answeryes);
\draw[line] (answerno.west) -- ++ (-2,0) |- (A-1);
\end{tikzpicture}
\end{document}
答案2
一些快速的改进:
\tikzstyle
已过时,请使用\tikzset
。查看我的代码以了解如何使用它。- 尽管
arrows
仍受支持,但已弃用。您可以根据需要使用它,但它arrows.meta
是当前的库。 positioning
应该使用库,从 更改below of=...
为below =of...
。- 该
standalone
课程对于展示小示例非常有用。 \path[draw]
相当于\draw
,但第二种意味着更少的输入和更整洁的代码。
输出
代码
\documentclass[margin=10pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{positioning, shapes, arrows.meta}
\tikzset{
answer/.style={rectangle, draw, text width=15em, text badly centered, node distance=1cm, inner sep=0pt, minimum height=4em},
block/.style={rectangle, draw, text width=30em, text centered, rounded corners, minimum height=4em},
line/.style={-{Stealth}}
}
\begin{document}
\begin{tikzpicture}[node distance = 5mm, auto]
% Place nodes
\node [block] (development) {text};
\node [block, below =of development] (quantitive) {text};
\node [block, below =of quantitive] (significances) {text};
\node [block, below =of significances] (utility) {text};
\node [block, below =of utility] (optimization) {text};
\node [block, below =of optimization] (decide) {text?};
\node [answer, below =of decide.south west, anchor=north west] (answerno) {text};
\node [answer, below =of decide.south east, anchor=north east] (answeryes) {text};
% Draw edges
\draw[line] (development) -- (quantitive);
\draw[line] (quantitive) -- (significances);
\draw[line] (significances) -- (utility);
\draw[line] (utility) -- (optimization);
\draw[line] (optimization) -- (decide);
\draw[{Stealth}-] (answerno) -- (answerno|-decide.south) node[right, midway] {No};
\draw[{Stealth}-] (answeryes) -- (answeryes|-decide.south) node[right, midway] {Yes};
\draw[line] (answerno.west) -- ++ (-2,0) |- (development.west);
\end{tikzpicture}
\end{document}