我正在使用 tikzpicture 包构建流程图类型图表。请参阅下面的代码和输出
但是,如图所示,文本在框中没有对齐。文本接触到框的上端。在框的下端,它留下了太多空间。请帮我对齐框中的文本。此图中的另一个疑问是文本的字体太浅(暗)。我想自定义(增加)字体的粗细,但不想使其完全加粗。有解决方案吗?
\documentclass{article}
\usepackage{tikz}
\begin{document}
\tikzset{every picture/.style={line width=1pt}} %set default line width to 0.75pt
\begin{tikzpicture}[x=0.75pt,y=0.75pt,yscale=-1,xscale=1]
%uncomment if require: \path (0,1307); %set diagram left start at 0, and has height of 1307
%Flowchart: Terminator [id:dp817315463198161]
\draw [line width=1.5] (184.4,579.41) -- (232,579.41) .. controls (238.19,579.41) and (243.2,588.37) .. (243.2,599.41) .. controls (243.2,610.46) and (238.19,619.41) .. (232,619.41) -- (184.4,619.41) .. controls (178.21,619.41) and (173.2,610.46) .. (173.2,599.41) .. controls (173.2,588.37) and (178.21,579.41) .. (184.4,579.41) -- cycle ;
%Straight Lines [id:da593004103091213]
\draw (208.2,619.41) -- (208.2,645.63) ;
\draw [shift={(208.2,648.63)}, rotate = 270] [fill={rgb, 255:red, 0; green, 0; blue, 0 } ][line width=0.08] [draw opacity=0] (8.93,-4.29) -- (0,0) -- (8.93,4.29) -- cycle ;
%Shape: Rectangle [id:dp4636072145556138]
\draw [line width=1.5] (87,648.41) -- (338,648.41) -- (338,688.41) -- (87,688.41) -- cycle ;
%Straight Lines [id:da760654823788836]
\draw [line width=0.75] (208.4,688.41) -- (208.4,714.63) ;
\draw [shift={(208.4,717.63)}, rotate = 270] [fill={rgb, 255:red, 0; green, 0; blue, 0 } ][line width=0.08] [draw opacity=0] (8.93,-4.29) -- (0,0) -- (8.93,4.29) -- cycle ;
%Shape: Rectangle [id:dp7160972372053898]
\draw [line width=1.5] (85,716.41) -- (341,716.41) -- (341,756.41) -- (85,756.41) -- cycle ;
%Straight Lines [id:da9982972789879592]
\draw (208.4,756.41) -- (208.4,782.63) ;
\draw [shift={(208.4,785.63)}, rotate = 270] [fill={rgb, 255:red, 0; green, 0; blue, 0 } ][line width=0.08] [draw opacity=0] (8.93,-4.29) -- (0,0) -- (8.93,4.29) -- cycle ;
%Shape: Rectangle [id:dp13232867845023288]
\draw [line width=1.5] (85,784.41) -- (341,784.41) -- (341,824.41) -- (85,824.41) -- cycle ;
%Straight Lines [id:da8594576131820797]
\draw (199.2,826.03) -- (199.2,851.03) ;
%Straight Lines [id:da5091009734627427]
\draw (199.2,851.03) -- (373.3,848.81) ;
%Straight Lines [id:da8424577163431968]
\draw (376,611.23) -- (373.3,848.81) ;
%Straight Lines [id:da9352818404180732]
\draw (376,611.23) -- (544,611.23) ;
%Straight Lines [id:da5902618988740569]
\draw (544,611.23) -- (544,637.44) ;
\draw [shift={(544,640.44)}, rotate = 270] [fill={rgb, 255:red, 0; green, 0; blue, 0 } ][line width=0.08] [draw opacity=0] (8.93,-4.29) -- (0,0) -- (8.93,4.29) -- cycle ;
%Shape: Rectangle [id:dp22708478679078814]
\draw [line width=1.5] (432.2,640.41) -- (683.2,640.41) -- (683.2,680.41) -- (432.2,680.41) -- cycle ;
%Straight Lines [id:da4167029594900722]
\draw (544.4,679.41) -- (544.4,705.63) ;
\draw [shift={(544.4,708.63)}, rotate = 270] [fill={rgb, 255:red, 0; green, 0; blue, 0 } ][line width=0.08] [draw opacity=0] (8.93,-4.29) -- (0,0) -- (8.93,4.29) -- cycle ;
%Shape: Rectangle [id:dp6747807246601145]
\draw [line width=1.5] (421,707.41) -- (677,707.41) -- (677,747.41) -- (421,747.41) -- cycle ;
% Text Node
\draw (445,704.41) node [anchor=north west][inner sep=0.75pt] [align=left] {\begin{minipage}[lt]{145.04pt}\setlength\topsep{0pt}
\begin{center}
{\small {\fontfamily{helvet}\selectfont Chemical Reaction: Hydrogen and }}\\{\small {\fontfamily{helvet}\selectfont oxygen form water}}
\end{center}
\end{minipage}};
% Text Node
\draw (451,637.41) node [anchor=north west][inner sep=0.75pt] [align=left] {\begin{minipage}[lt]{145.04pt}\setlength\topsep{0pt}
\begin{center}
{\small {\fontfamily{helvet}\selectfont Chemical Reaction: Hydrogen and }}\\{\small {\fontfamily{helvet}\selectfont oxygen form water}}
\end{center}
\end{minipage}};
% Text Node
\draw (106,781.41) node [anchor=north west][inner sep=0.75pt] [align=left] {\begin{minipage}[lt]{145.04pt}\setlength\topsep{0pt}
\begin{center}
{\small {\fontfamily{helvet}\selectfont Chemical Reaction: Hydrogen and }}\\{\small {\fontfamily{helvet}\selectfont oxygen form water}}
\end{center}
\end{minipage}};
% Text Node
\draw (103,713.41) node [anchor=north west][inner sep=0.75pt] [align=left] {\begin{minipage}[lt]{145.04pt}\setlength\topsep{0pt}
\begin{center}
{\small {\fontfamily{helvet}\selectfont Chemical Reaction: Hydrogen and }}\\{\small {\fontfamily{helvet}\selectfont oxygen form water}}
\end{center}
\end{minipage}};
% Text Node
\draw (102,648.41) node [anchor=north west][inner sep=0.75pt] [align=left] {\begin{minipage}[lt]{145.04pt}\setlength\topsep{0pt}
\begin{center}
{\small {\fontfamily{helvet}\selectfont Chemical Reaction: Hydrogen and }}\\{\small {\fontfamily{helvet}\selectfont oxygen form water}}
\end{center}
\end{minipage}};
% Text Node
\draw (188.2,589.41) node [anchor=north west][inner sep=0.75pt] [align=left] {{\fontfamily{helvet}\selectfont {\small Start}}};
% Text Node
\draw (428,671) node [font=\footnotesize,color={rgb, 255:red, 74; green, 144; blue, 226 } ,opacity=1 ] {$B$};
\end{tikzpicture}
\end{document}
答案1
\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,calc,positioning}
\begin{document}
\pagestyle{empty}
% Define block styles
\tikzstyle{block} = [
rectangle,
draw,
text width=6cm,
text centered,
minimum height=3em]
\tikzstyle{line} = [draw, -latex']
\begin{tikzpicture}[node distance = 1cm, line width=1pt]
% Place nodes
\node [block, rounded corners, text width=2cm, text centered, minimum height=3em ] (a) {Start};
\node [block, below =of a] (b) {Chemical Reaction: Hydrogen and \\ oxygen form water};
\node [block, below =of b] (c) {Chemical Reaction: Hydrogen and \\ oxygen form water};
\node [block, below =of c] (d) {Chemical Reaction: Hydrogen and \\ oxygen form water};
\node [block, right =2cm of b] (b1) {Chemical Reaction: Hydrogen and \\ oxygen form water};
\node [block, below =of b1] (c1) {Chemical Reaction: Hydrogen and \\ oxygen form water};
\coordinate(temp) at ($(b)!0.5!(b1)$);
\coordinate(temp1) at ($(b1.north)+(0,8pt)$);
\draw[line] (a) -- (b);
\draw[line] (b) -- (c);
\draw[line] (c) -- (d);
\draw[] (d) -- ($(d.south)+(0,-8pt)$) -| (temp) |- (temp1) ;
\draw[line] (temp1) -- (b1);
\draw[line] (b1) -- (c1);
\end{tikzpicture}
\end{document}
答案2
您的代码没有必要那么复杂。您应该使用具有矩形形状的节点来插入文本,而不是绘制矩形。通过使用chains
库可以进一步简化流程图代码:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
calc, chains,
positioning}
\makeatletter
\tikzset{
suspend join/.code={\def\tikz@after@path{}} % for interrupt drawing arrows between nodes
}
\makeatother
\begin{document}
\noindent
\begin{tikzpicture}[
node distance = 4mm and 16mm,
start chain = going below,
arr/.style = {-Straight Barb, semithick},
base/.style = {shape=rectangle, draw, semithick,
align=flush center, inner ysep=2mm,
on chain, join=by arr}, % common style
start/.style = {base, rounded corners, text width=22mm},
block/.style = {base, text width=50mm}
]
% placing of nodes
\node [start] (a) {Start};
\node [block] (b) {Chemical Reaction: Hydrogen and oxygen form water};
\node [block] (c) {Chemical Reaction: Hydrogen and oxygen form water};
%
\node [block, right=of b, suspend join]
(d) {Chemical Reaction: Hydrogen and oxygen form water};
\node [block] (e) {Chemical Reaction: Hydrogen and oxygen form water};
% connections between nodes
\coordinate[above=of $(b.north)!0.5!(d.north)$] (aux);
\draw[arr] (c) -- ++ (0,-1) -| (aux) -| (d);
\end{tikzpicture}
\end{document}
编辑: 如果您希望重现图像(在左列的 MWE 上方缺少一个节点),只需添加它并相应地命名即可。通过为两个流程图分支连接箭头添加附加坐标,MWE 为:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
calc, chains,
positioning}
\makeatletter
\tikzset{
suspend join/.code={\def\tikz@after@path{}} % for interrupt drawing arrows between nodes
}
\makeatother
\begin{document}
\noindent
\begin{tikzpicture}[
node distance = 4mm and 16mm,
start chain = going below,
arr/.style = {-Straight Barb, semithick},
base/.style = {shape=rectangle, draw, semithick,
align=flush center, inner ysep=2mm,
on chain, join=by arr}, % common style
start/.style = {base, rounded corners, text width=22mm},
block/.style = {base, text width=50mm}
]
% placing of nodes
\node [start] (a) {Start};
\node [block] (b) {Chemical Reaction: Hydrogen and oxygen form water};
\node [block] {Chemical Reaction: Hydrogen and oxygen form water};
\node [block] (c) {Chemical Reaction: Hydrogen and oxygen form water};
%
\node [block, right=of b, suspend join]
(d) {Chemical Reaction: Hydrogen and oxygen form water};
\node [block] {Chemical Reaction: Hydrogen and oxygen form water};
% connections between nodes
\coordinate[below=of c] (aux1);
\coordinate[above=of $(b.north)!0.5!(d.north)$] (aux2);
\draw[arr] (c) -- (aux1) -| (aux2) -| (d);
\end{tikzpicture}
\end{document}