0

I am constructing a flow chart type diagram using tikzpicture package. Please find the code and the output belowenter image description here

However, as seen in the image, the text is not aligned in the box. The text is touching the upper end of the box. At the lower end of the box, it is leaving too much space. Please help me in aligning the text in the box. Another doubt in this figure is that the font of text is too light (dim). I want to customize (increase) bold-ness of the font, but not make it completely bold. Is there a solution for that?

\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}

ShJ
  • 891
  • remove all the anchors and try – js bibra Oct 05 '21 at 15:14
  • you do not require the controls etc since tikz has rectangle inbuilt in code with rounded corners -- one example of text alignment -- https://tex.stackexchange.com/questions/430001/vertical-alignment-of-text-in-tikz-node and --https://tex.stackexchange.com/a/519564/197451 – js bibra Oct 05 '21 at 15:22
  • @jsbibra No, removing anchor is not working. By removing anchor, some of the text goes out of box. Is it possible to align the text using this code only without using the rectangle – ShJ Oct 05 '21 at 15:33
  • have a look at the answer below – js bibra Oct 06 '21 at 00:51

2 Answers2

3

Your code is unnecessary complicated. Instead drawing rectangles you should use nodes with rectangle shape in insert text in them. Further simplification of flowchart code can be obtain by use of chains library:

\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}

enter image description here

Edit: In case, that you like to have reproduce your images (in above MWE in the left column is one node missed), you just add it and accordingly named it. With additional coordinate for both flowchart branch connection arrows the MWE is:

\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}

enter image description here

Zarko
  • 296,517
1

enter image description here

\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}

js bibra
  • 21,280