我怎样才能绘制如下图所示的水平边缘?我的代码如下。谢谢。
\documentclass[12pt]{book}
\usepackage[paperwidth=16cm, paperheight=24cm]{geometry}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\usepackage{tabularx,ragged2e}
\newcolumntype{R}{>{\RaggedLeft}X}
\usepackage{tikz}
\usetikzlibrary{arrows,automata,matrix,positioning}
\begin{document}
\begin{tikzpicture} [every node/.style={block}, block/.style={minimum height=1.5em,outer sep=0pt,draw,rectangle,node distance=1 cm}]
\node (A){Source code};
\node (B) [below=of A] {Lexical analysis};
\node (C) [below=of B] {Syntaxical analysis};
\node (D) [below=of C] {Semantical analysis};
\node (E) [below=of D] {Code generation};
\node (F) [below=of E] {Code optimization};
\node (G) [below=of F] {Code generation};
\node (H) [below=of G] {Object code};
\path[->] (A) edge (B);
\path[->] (B) edge (C);
\path[->] (C) edge (D);
\path[->] (D) edge (E);
\path[->] (E) edge (F);
\path[->] (F) edge (G);
\path[->] (G) edge (H);
\end{tikzpicture}
\end{document}
答案1
感谢 Muzimuzhi 的评论。为了可能对其他人有用,我根据 Muzimuzhi 的评论在下面发布了我所期望的完整代码:
\documentclass[12pt]{book}
\usepackage[paperwidth=16cm, paperheight=24cm]{geometry}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\usepackage{tabularx,ragged2e}
\newcolumntype{R}{>{\RaggedLeft}X}
\usepackage{tikz}
\usetikzlibrary{arrows,automata,matrix,positioning,calc}
\begin{document}
\begin{tikzpicture} [every node/.style={block}, block/.style={minimum height=1.5em,outer sep=0pt,draw,rectangle,node distance=1 cm}]
\node (A){Source code};
\node (B) [below=of A] {Lexical analysis};
\node (C) [below=of B] {Syntaxical analysis};
\node (D) [below=of C] {Semantical analysis};
\node (E) [below=of D] {Code generation};
\node (F) [below=of E] {Code optimization};
\node (G) [below=of F] {Code generation};
\node (H) [below=of G] {Object code};
\path[->] (A) edge (B);
\path[->] (B) edge (C);
\path[->] (C) edge (D);
\path[->] (D) edge (E);
\path[->] (E) edge (F);
\path[->] (F) edge (G);
\path[->] (G) edge (H);
\draw[->] ($ (A)!.5!(B) $) -- +(3, 0) node[align=center, right] {text\\more text};
\draw[->] ($ (B)!.5!(C) $) -- +(3, 0) node[align=center, right] {text\\more text};
\draw[->] ($ (C)!.5!(D) $) -- +(3, 0) node[align=center, right] {text\\more text};
\draw[->] ($ (D)!.5!(E) $) -- +(3, 0) node[align=center, right] {text\\more text};
\draw[->] ($ (E)!.5!(F) $) -- +(3, 0) node[align=center, right] {text\\more text};
\draw[->] ($ (F)!.5!(G) $) -- +(3, 0) node[align=center, right] {text\\more text};
\draw[->] ($ (G)!.5!(H) $) -- +(3, 0) node[align=center, right] {text\\more text};
\end{tikzpicture}
\end{document}
答案2
您的问题已经得到解决@muzimuzhi Z评论,所以这里只有一个建议,如何编写流程图的代码,通过使用chains
Ti来显示问题钾Z 库,更短:
\documentclass[12pt]{book}
\usepackage[paperwidth=16cm, paperheight=24cm]{geometry}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
calc, chains,
positioning,
babel}
\begin{document}
\begin{tikzpicture} [
node distance = 10mm,
start chain = going below,
> = Straight Barb,
block/.style = {draw, minimum height=1.5em, outer sep=0pt}
]
\begin{scope}[nodes={block, on chain, join=by ->}]
\node (A) {Source code};
\node (B) {Lexical analysis};
\node (C) {Syntaxical analysis};
\node (D) {Semantical analysis};
\node (E) {Code generation};
\node (F) {Code optimization};
\node (G) {Code generation};
\node (H) {Object code};
\end{scope}
%
\begin{scope}[nodes={align=left, right}]
\draw[->] ($ (B)!.5!(C) $) -- +(3, 0) node {Getting string of tokens\\
or symbols here};
\draw[->] ($ (C)!.5!(D) $) -- +(3, 0) node {Getting derivation tree\\
as output here};
\end{scope}
\end{tikzpicture}
\end{document}