我正在尝试垂直对齐文本,以便它看起来整洁并且不需要太多空间。文本宽度在本论坛中推荐过,但我不知道在森林中哪里调用该命令。:-)。谢谢帮助。
\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}
答案1
我对包不太熟悉forest
,因此我的回答可能包含非标准做法甚至错误。
笔记
- 该选项
node options={text width=3cm, align=center, anchor=south}}
已添加。 block/.style={...}
在您的forest
环境中被重新定义,因此我从中删除了该副本\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}
答案2
- 对于你的树,除了包之外,我还将
forest
使用mchem
化学公式包arrows.meta
和ext.paths.ortho
Ti钾箭头的 Z 库。 - 将树及其元素的所有样式定义移至
for tree
选项。 - 防止文本连字。
\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}