## LaTeX forum ⇒ Math & Science ⇒ tikZ | Drawing Molecules

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
cgnieder
Site Moderator
Posts: 1993
Joined: Sat Apr 16, 2011 7:27 pm

### Re: tikZ | Drawing Molecules

localghost wrote:
ghostanime2001 wrote:[…] How do I set the bond length to be the same length for example 1cm? […]

Isn't this exactly what chemfig does?

Actually not, and I guess this is what ghostanime refers to:
chemfig manual wrote:Rather than speaking of length of a bond, we should use the term interatomic spacing. If effect, only the interatomic spacing is adjustable with \setatomsep as we have seen on page 11. Once this parameter is set, the length of a bond depends on the content of atoms and, to a lesser extent, the angle the bond makes with the horizontal. It should be obvious that two “slimmer” atoms will have larger edge separations than two which are larger. This can be seen easily in the following example where an “I” atom is narrower than an “M” atom, which means that the bond between the “I” atoms is longer than that between the “M” atoms.

In my eyes chemfig's behaviour most times is a good thing, though.

@ghostanime: you need to specify the node distance property, see 16.5.3 Advanced Placement Options of the pgfmanual for details.

\documentclass{article}\usepackage[margin=1in]{geometry}\usepackage{tikz}\usetikzlibrary{positioning}\begin{document} \def\bondlength{7mm}\begin{tikzpicture}[node distance=\bondlength]  \node (a) {C};  \node (b) [above=of a] {H};  \node (c) [below=of a] {H};  \node (d) [left=of a] {H};  \node (e) [right=of a] {C};  \node (f) [below right=\bondlength of e] {O};  \node (g) [right=of f] {H};  \node at (a.north east) {+};  \draw (a.north) to (b.south);  \draw (a.south) to (c.north);  \draw (d.east) to (a.west);  \draw (e.west) to (a.east);  \draw (f.north west) to (e.south east);  \draw (f.east) to (g.west);\end{tikzpicture} \end{document}

Regards
site moderator & package author

Tags:

ghostanime2001
Posts: 402
Joined: Fri May 20, 2011 9:41 am
How to set the distance between the bond and the atom in this example ? I have tried \setatomsep but it gives no difference. If you don't mind me asking, can the above example's syntax be simplified ?
Last edited by cgnieder on Fri Oct 26, 2012 6:00 pm, edited 1 time in total.

cgnieder
Site Moderator
Posts: 1993
Joined: Sat Apr 16, 2011 7:27 pm
ghostanime2001 wrote:How to set the distance between the bond and the atom in this example ? I have tried \setatomsep but it gives no difference.

Are you refering to the example I've given? \setatomsep is a »chemfig« command and not a »TikZ« command! I defined the parameter

\def\bondlength{7mm}

in my example which can be adapted to a suitable value...

ghostanime2001 wrote:If you don't mind me asking, can the above example's syntax be simplified ?

Well, it never will be as simple as the »chemfig« syntax. You have two choices (or three, actually):
1. use chemfig with easy syntax an live with the fact that there is no exact bond length.
2. use TikZ directly and live with the fact that the syntax isn't as easy.
3. don't use LaTeX for the molecules but a program like chemdraw.

You can, however, simplify it a bit by defining suitable commands:

Regards
site moderator & package author

localghost
Site Moderator
Posts: 9204
Joined: Fri Feb 02, 2007 12:06 pm
ghostanime2001 wrote:How to set the distance between the bond and the atom in this example ? I have tried \setatomsep but it gives no difference. If you don't mind me asking, can the above example's syntax be simplified ?

In which example? Mine? What about just reading Section 2 of the chemfig manual and using \setbondoffset? m(
LaTeX Community Moderator

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1