[Tex/LaTex] Any way to get neato-like node placement in a TikZ graph


I'm interested in drawing molecular connectivity graphs in TikZ. Using \node and child without any positions I am able to draw a tree diagram which is semi-useful as I can easily illustrate the hierarchical relationships of the implied z-matrix.

Here's an example for ethanol (CH3CH2OH) that I've been using in my dabblings.

\node[carbon] (C1) {C}
child {node [hydrogen] (H1) {H}}
child {node [hydrogen] (H2) {H}}
child {node [hydrogen] (H3) {H}}
child {node [carbon] (C2) {C}
child {node [hydrogen] (H4) {H}}
child {node [hydrogen] (H5) {H}}
child {node [oxygen] (O1) {O} child {node [hydrogen] (H6) {H}}}};
\draw [dashed] (H6) -- (H4);

A program like Graphviz, however, can take a similar graph and arrange the nodes automagically in a number of ways. The neato package in Graphviz can for instance arrange the nodes in a relaxed ball-and-spring fashion that is rather fitting for molecules. I've been looking through the TikZ documentation and have found mindmaps, petri nets, finite state automata, digraphs etc., however I have not seen any invocation of automatic layouts. Can it be done in TikZ?

Best Answer

You are better with the excellent »chemfig« package. It is based on »PGF/TikZ« and offers an easy syntax.




The package manual has the details.

enter image description here

Related Question