Nodes overlapping with TikZ graphdrawing library
As it stands, your example will not compile because the node names are not unique. Probably, you want to use the \graph
command and create the nodes implicitly. When you repeat a name, only one node will be created but it may, of course, have many relationships to other nodes.
It is important to choose an appropriate algorithm and to then use the options relevant to that algorithm to adjust the layout. node distance
is right for some cases, but not all.
Here's one version with a layered layout
which uses sibling distance
and level distance
to enforce the desired spacing.
\RequirePackage{luatex85}
\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{graphdrawing,graphs}
\usegdlibrary{layered}
\begin{document}
\begin{tikzpicture}
\graph [layered layout, sibling distance=10cm, level distance=10cm, edges={draw, very thick}, nodes={minimum width=6cm, minimum height=5cm, draw, as=}]
{
CA -- { FA, DHCA -- { DHFA, DHCA3OG -- { DHFA4OG, DHFA4OS }, DHCA3OS, DHIFA -- DHIFA3OG }, IEA -- { IFA3OG, IFA3OS }, CA4OS, CA3OS, 4OCQAL -- 5OFQA -- FA -- { FA4OS, FG, DHFA }, 5OCQA };
};
\end{tikzpicture}
\end{document}
Changing
layered layout, sibling distance=10cm, level distance=10cm,
to
spring layout, node distance=20cm,
we have
The cooling factor
, convergence tolerance
etc. will also influence the result in this case.
Or change the above to
spring electrical layout, node distance=10cm, electric charge=5,
to produce
Or without the increased electric charge
:
In case you meant that you wanted arrows, replace --
with ->
or <-
or <->
and set the arrow tip using >=Latex
or whatever.
Ok, using @cfr's suggestions I implemented the layered layout
and spring electrical layout
using some tricks for the electrical layout
. To change between layouts just change the style use layers
to spreaded
and uncomment the line
% ,O[the central] --[draw=none] {CA,DHCA,FA,DHFA}% For spreaded layout
Result with layered layout
Result with spring electrical layout
The code
\RequirePackage{luatex85}
\documentclass[margin=5mm]{standalone}
\usepackage{tikz,chemfig}
\renewcommand*\printatom[1]{\ensuremath{\mathsf{#1}}}
\newcommand*{\HOOC}[2]{HOOC-[1]-[2]-[1]*6(=-=(-#1)-(-#2)=-)}
\newcommand*{\radicals}[2]{\edef\X{#1}\edef\Y{#2}}
\definesubmol{hooc}{HOOC-[1]-[2]-[1]*6(=-=(-!{\X})-(-!{\Y})=-)}
\definesubmol{isohooc}{HOOC-[1]=[2]-[1]*6(=-=(-!{\X})-(-!{\Y})=-)}
\definesubmol{quinic}{HOOC-[7]?(-[6]OH)-[:15]-[:-15](-[6]OH)-[:60](-[:-30]OH)-[:195](-[:60,3]O-[7](=[6]O)-[1]=[2]-[1]*6(=-=(-!{\X})-(-!{\Y})=-))-[:165]?}
\def\glucuronide{O-[:30](-[:60](-[:190,0.75]OH)-[:-15](-[:75,0.75]OH)-[:15]?-[:-15,0.75]OH)(-[:15]O-[::-30]?-[0,0.75]COOH)}
\setatomsep{2em}
\usetikzlibrary{graphs,graphdrawing}
\usegdlibrary{layered,force}
\begin{document}
\begin{tikzpicture}[label position=below,
every label/.style={red},
>=latex,
rounded corners,
every edge/.append style={line width=6pt},
graphs/use layers/.style={layered layout,
sibling distance=8cm,
level distance=10cm,
/tikz/the central/.style={electric charge=-1.2},
/tikz/4OCQAL/.style={},
/tikz/DHIFA3OG/.style={},
/tikz/IFA/.style={},
/tikz/CA/.style={},
/tikz/DHCA/.style={}
},
graphs/spreaded/.style={spring electrical layout, node distance=11cm,
/tikz/the central/.style={electric charge=-1.2},
/tikz/4OCQAL/.style={node distance=15cm},
/tikz/DHIFA3OG/.style={orient=up, orient tail=DHIFA},
/tikz/IFA/.style={},
/tikz/CA/.style={electric charge=1.5, orient=up, orient tail=DHFA},
/tikz/DHCA/.style={orient=left, orient tail=FA}
}]
\graph[use layers, nodes={circle, minimum size=6cm, as=}]{%
CA[CA] <- {4OCQAL[4OCQAL] -> 5OFQA -> FA, 5OCQA},
CA -> {FA -> {FA4OS, FG, DHFA},
DHCA[DHCA] -> {DHFA -> {DHFA4OG, DHFA4OS},
DHCA3OG,
DHCA3OS,
DHIFA -> DHIFA3OG[DHIFA3OG]},
CA4OS,
CA3OS,
IFA[IFA] -> {IFA3OG, IFA3OS}
}
% ,O[the central] --[draw=none] {CA,DHCA,FA,DHFA}% For spreaded layout
};
\node[label={Ferulic acid}] at (FA) {\radicals{OH}{OCH_3}\chemfig*{!{isohooc}}};
\node[label={Caffeic acid}] at (CA) {\radicals{OH}{OH}\chemfig*{!{isohooc}}};
\node[label={Isoferulic acid}] at (IFA) {\radicals{OCH_3}{OH}\chemfig*{!{isohooc}}};
\node[label={Isoferulic acid-3-O-sulfate}] at (IFA3OS) {\radicals{OSO_3^{-}}{OH}\chemfig*{!{isohooc}}};
\node[label={Dihydrocaffeic acid}] at (DHCA)
{\radicals{OH}{OH}\chemfig*{!{hooc}}};
\node[label={Dihydrocaffeic acid-3-O-glucuronide}] at (DHCA3OG)
{\radicals{OH}{\glucuronide}\chemfig*{!{hooc}}};
\node[label={Dihydroferulic acid-4-O-sulfate}] at (DHFA4OS)
{\radicals{OSO_3^{-}}{OCH_3}\chemfig*{!{hooc}}};
\node[label={Dihydrocaffeic acid-3-O-sulfate}] at (DHCA3OS)
{\radicals{OH}{OSO_3^{-}}\chemfig*{!{hooc}}};
\node[label={Dihydro(iso)ferulic acid-3-O-glucuronide}] at (DHIFA3OG)
{\radicals{OCH_3}{\glucuronide}\chemfig*{!{hooc}}};
\node[label={Dihydro(iso)ferulic acid}] at (DHIFA)
{\radicals{OCH_3}{OH}\chemfig*{!{hooc}}};
\node[label={Isoferulic acid-3-O-glucuronide}] at (IFA3OG)
{\radicals{OCH_3}{\glucuronide}\chemfig*{!{isohooc}}};
\def\glucuronide{O-[:-30,1.5](-[:60](-[:190,0.5]OH)-[:-15](-[:75,0.75]OH)-[:15]?-[:-15,0.75]OH)(-[:15]O-[::-30]?-[0,0.75]COOH)}
\node[label={Dihydroferulic acid-4-O-glucuronide}] at (DHFA4OG)
{\radicals{\glucuronide}{OCH_3}\chemfig*{!{hooc}}};
\node[label={Dihydroferulic acid}] at (DHFA)
{\radicals{OH}{OCH_3}\chemfig*{!{hooc}}};
\node[label={Caffeic acid-4-O-sulfate}] at (CA4OS)
{\radicals{OSO_3^{-}}{OH}\chemfig*{!{hooc}}};
\node[label={Caffeic acid-3-O-sulfate}] at (CA3OS)
{\radicals{OCH_3}{OSO_3^{-}}\chemfig*{!{hooc}}};
\node[label={Ferulic acid-4-O-sulfate}] at (FA4OS)
{\radicals{OSO_3^{-}}{OCH_3}\chemfig*{!{isohooc}}};
\node[label={Feruloglycine}] at (FG)
{\chemfig*{HOOC-[:60]-[:20]NH-[:80](=[:120]O)(-[1]=[2]-[1]*6(=-=(-OH)-(-OCH_3)=-))}};
\node[label={5-O-Feruloyquinic acid}] at (5OFQA)
{\radicals{OH}{OCH_3}\chemfig*{!{quinic}}};
\node[label={5-O-Caffeoylquinic acid}] at (5OCQA)
{\radicals{OH}{OH}\chemfig*{!{quinic}}};
\node[label={4-O-Caffeoylquinic acid lactone}] at (4OCQAL)
{\chemfig*{?[a](=[:135]O)-[:280,2.5]?[b](-[6]OH)-[:15]-[:-15](-[6]OH)-[:60](-[:-30]O-[7](=[6]O)-[1]=[2]-[1]*6(=-=(-OH)-(-OH)=-))-[:195](-[:60]O?[a])-[:165]?[b]}};
\end{tikzpicture}
\end{document}
Some things still need to be taken care of, but the main idea is there. Hope it can be of help to some chemist or whoever :)