4

i am trying to align the text in vertical, so that it looks tidy and doesn't require much space. text width was recommended here in this forum, but I don't know where to call that command in forest. :-). Thanks for help.

\documentclass[tikz, border=5mm]{standalone}   
   \usetikzlibrary{positioning, fit, calc}   
    \tikzset{block/.style={draw, thick, text width=2cm ,minimum height=1.7cm, align=center},   
    line/.style={-latex}     
    }  
\usepackage[edges]{forest}

\begin{document} 

\begin{forest}
block/.style={draw, thick, minimum width=6.5em ,
minimum height=2cm, align=center,text depth=0.25ex,text height=0.8em},
forked edges,
for tree={block,edge={-latex,semithick},l sep+=1em,fork sep=1em,
    where level=3{minimum height=7em}{}}
[\textbf{H\textsubscript{2}S Control in sewer systems}
 [Inhibition of H\textsubscript{2}S generated 
  [General inhibition of biological activity
   [{ph elevation, addition of NaOH or Ca(CO)\textsubscript{2}}]
   [Addition of biocides]
  ]
  [Specific prevention of SRB activity,alias=specific
  ]
 ]
 [Elimination of H\textsubscript{2}S formed
  [Biological Oxidation of H\textsubscript{2}S formed
   [{Addition of alternative electron acceptors (O\textsubscript{2}, NO\textsubscript{3}\textsuperscript{-}, NO\textsubscript{2}\textsuperscript{-})},fill=black!20,minimum width=9em,alias=cool]
  ]
  [Chemical Oxidation of H\textsubscript{2}S formed
   [{Addition of chemical oxidants (O\textsubscript{2}, H\textsubscript{2}O\textsubscript{2}, Cl\textsubscript{2}, NaClO, KMnO\textsubscript{4}, CaO\textsubscript{2}, MgO\textsubscript{2})},fill=black!20,minimum width=9em]
  ]
  [Chemical precipitation of H\textsubscript{2}S formed
   [{Addition of iron Salts (Fe\textsuperscript{2+}, Fe\textsuperscript{3+})},fill=black!20,minimum width=9em]
  ]
 ]
]
\draw[-latex,semithick] (specific.south) -- ++ (0,-1em) -| (cool.north);
\end{forest}


\end{document}
2
  • What do you mean "align the text in vertical"? Do you want to set a maximum width for text and any long text is auto-wrapped into lines? Commented May 27, 2020 at 9:55
  • Yes, exactly. seperate the text in a box to 3 or 4 lines
    – Phil
    Commented May 27, 2020 at 10:09

2 Answers 2

5

I am not familiar with forest package, hence my answer may contain non-standard practices and even mistakes.

Note

  • The option node options={text width=3cm, align=center, anchor=south}} is added.
  • The block/.style={...} is redefined inside your forest environment, hence I removed that copy from \tikzset{...}.
\documentclass[tikz, border=5mm]{standalone}   
\usetikzlibrary{positioning, fit, calc}   
\tikzset{
  line/.style={-latex}     
}  
\usepackage[edges]{forest}

\begin{document} 

\begin{forest}
  block/.style={draw, thick, minimum width=3em, minimum height=2cm, node options={text width=3cm, align=center, anchor=south}},
  forked edges,
  for tree={block, edge={-latex,semithick},l sep+=1em,fork sep=1em,
      where level=3{minimum height=7em}{}}
  [\textbf{H\textsubscript{2}S Control in sewer systems}
   [Inhibition of H\textsubscript{2}S generated 
    [General inhibition of biological activity
     [{ph elevation, addition of NaOH or Ca(CO)\textsubscript{2}}]
     [Addition of biocides]
    ]
    [Specific prevention of SRB activity,alias=specific
    ]
   ]
   [Elimination of H\textsubscript{2}S formed
    [Biological Oxidation of H\textsubscript{2}S formed
     [{Addition of alternative electron acceptors (O\textsubscript{2}, NO\textsubscript{3}\textsuperscript{-}, NO\textsubscript{2}\textsuperscript{-})},fill=black!20,minimum width=9em,alias=cool]
    ]
    [Chemical Oxidation of H\textsubscript{2}S formed
     [{Addition of chemical oxidants (O\textsubscript{2}, H\textsubscript{2}O\textsubscript{2}, Cl\textsubscript{2}, NaClO, KMnO\textsubscript{4}, CaO\textsubscript{2}, MgO\textsubscript{2})},fill=black!20,minimum width=9em]
    ]
    [Chemical precipitation of H\textsubscript{2}S formed
     [{Addition of iron Salts (Fe\textsuperscript{2+}, Fe\textsuperscript{3+})},fill=black!20,minimum width=9em]
    ]
   ]
  ]
  \draw[-latex,semithick] (specific.south) -- ++ (0,-1em) -| (cool.north);
\end{forest}


\end{document}

enter image description here

1
  • Ah remove from tikzset was the trick! Exactly like a want it. Thank you very much.
    – Phil
    Commented May 27, 2020 at 11:03
1
  • For your tree I would beside forest package use mchem package for chem formulae, and arrows.meta and ext.paths.ortho TikZ libraries for arrows.
  • Move all style definitions for tree and its elements to for tree options.
  • Prevent text hyphenation.
\documentclass[margin=5mm]{standalone}
\usepackage[version=4]{mhchem}
\usepackage[edges]{forest}
\usetikzlibrary{arrows.meta,
                ext.paths.ortho}

\begin{document}

\begin{forest}
    for tree = {
% nodes style
     draw, thick, 
    where level = 3{minimum height=5\baselineskip}{minimum height=3\baselineskip}, 
     text width = 10em, 
/tikz/align = flush center,     % <---
% edges,
     edge = {-Latex, semithick},
% three style
    anchor=north,
    forked edge,
    s sep = 2mm,     
    l sep = 7mm,     
 fork sep = 3mm,     
                }
[\ce{H2S} Control in sewer systems, font=\bfseries
   [Inhibition of \ce{H2S} generated
        [General inhibition of biological activity
            [{ph elevation, addition of \ce{NaOH} or \ce{Ca(CO)2}}]%
            [Addition of biocides]
        ]
        [Specific prevention of SRB activity, alias=specific]
   ]
   [Elimination of \ce{H2S} formed
        [Biological Oxidation of \ce{H2S} formed
            [Addition of alternative electron acceptors\newline 
             {(\ce{O2}, \ce{NO3^-}, \ce{NO3^{-}})},
             fill=gray!30,alias=cool]
        ]
        [Chemical Oxidation of \ce{H2S} formed
            [Addition of chemical oxidants 
             {(\ce{O2}, \ce{H2O2}, \ce{Cl2}, \ce{NaClO}, \ce{KMnO4}, 
              \ce{CaO2}, \ce{MgO2})},
              fill=gray!30]
        ]
        [Chemical precipitation of \ce{H2S} formed
            [Addition of iron Salts 
             {(\ce{Fe^{2+}}, \ce{Fe^{3+}})},
             fill=gray!30]
        ]
   ]
]
  \draw[-Latex, semithick] (specific.south) |-| (cool.north);
\end{forest}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .