Math & Science ⇒ tikZ | Drawing Molecules
-
- Posts: 402
- Joined: Fri May 20, 2011 9:41 am
tikZ | Drawing Molecules
I want to draw molecules with tikZ not with chemfig because tikZ has more flexibility of tweaking bond lengths and atomic spacing. I tried to change these parameters with chemfig but there were lots of intricacies that I didn't like (for example really really short bonds). I can create single bonds between atoms, but how do you create double bonds/triple bonds for example between a carbon and oxygen atom or between two nitrogen atoms? Also, how do you orient bonds at different angles?
NEW: TikZ book now 40% off at Amazon.com for a short time.

- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
tikZ | Drawing Molecules
It is exactly the other way round.ghostanime2001 wrote:I want to draw molecules with tikZ not with chemfig because tikZ has more flexibility of tweaking bond lengths and atomic spacing. […]
And the chemfig manual didn't help? I'm sure that all your question are answered by just reading a bit in the package manual.ghostanime2001 wrote:[…] I tried to change these parameters with chemfig but there were lots of intricacies that I didn't like (for example really really short bonds). I can create single bonds between atoms, but how do you create double bonds/triple bonds for example between a carbon and oxygen atom or between two nitrogen atoms? Also, how do you orient bonds at different angles?
Code: Select all
\documentclass[11pt]{standalone}
\usepackage[T1]{fontenc}
\usepackage{chemfig}
\setatomsep{2em}
\begin{document}
\chemfig{N=[:30]N}
\end{document}
Thorsten
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
tikZ | Drawing Molecules
Of course you can but IMHO you will soon notice that it's also a lot more work.ghostanime2001 wrote:I want to draw molecules with tikZ not with chemfig because tikZ has more flexibility of tweaking bond lengths and atomic spacing.
If I had to guess (and apparently I have to) you probably set chemfig's atom sep to a short value but haven't read section 4 Length of a bond of the manual where the impacts are explained.ghostanime2001 wrote:I tried to change these parameters with chemfig but there were lots of intricacies that I didn't like (for example really really short bonds).
See section 2 Different kinds of bonds.ghostanime2001 wrote:I can create single bonds between atoms, but how do you create double bonds/triple bonds for example between a carbon and oxygen atom or between two nitrogen atoms
See section 3 Bond angle.ghostanime2001 wrote:Also, how do you orient bonds at different angles?
Regards
site moderator & package author
-
- Posts: 402
- Joined: Fri May 20, 2011 9:41 am
Re: tikZ | Drawing Molecules
Thank for all your help. But I already know what you were talking about. In my post I was wondering weather similar effects (bonds, angles, bond length) can be done with tikz. I already know how to do it with chemfig.
Also, I know that between "slimmer" and "thicker" atoms the bond length varies that is why I am trying to change to tikz so that the bond length remains exactly the same length regardless of how thick or thin the width of atoms are.
Also, I know that between "slimmer" and "thicker" atoms the bond length varies that is why I am trying to change to tikz so that the bond length remains exactly the same length regardless of how thick or thin the width of atoms are.
tikZ | Drawing Molecules
Well, of course you can draw molecules with TikZ. The proof: chemfig uses TikZ. There is no chemistry library for TikZ if that's what you mean. You'd have to draw everything “by hand”, i.e., program it yourself.
Regards
Regards
site moderator & package author
-
- Posts: 402
- Joined: Fri May 20, 2011 9:41 am
Re: tikZ | Drawing Molecules
That's exactly what I'm after but I how do you draw double bonds and triple bonds with TIKZ ?
Re: tikZ | Drawing Molecules
I'm unsure what you want really... Do you already have code and are struggling with adding a second line (or third, resp.)? If so, please show what you already have so far.
Regards
Regards
site moderator & package author
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
tikZ | Drawing Molecules
ghostanime2001 wrote:That's exactly what I'm after but I how do you draw double bonds and triple bonds with TIKZ ?
- Why are you so stubborn in this matter?
- Why do you insist on this more difficult and more complicated method?
- Are there any really good reasons against the package?
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
-
- Posts: 402
- Joined: Fri May 20, 2011 9:41 am
tikZ | Drawing Molecules
I guess this could work as a MWE example. How do I set the bond length to be the same length for example 1cm?
Code: Select all
\documentclass[fleqn]{article}
\usepackage[margin=1in]{geometry}
\usepackage{chemmacros}
\usepackage{chemfig}
\usepackage{mhchem}
\usepackage{tikz}
\setlength{\parindent}{0pt}
\setlength{\parskip}{0pt}
\setlength{\mathindent}{0pt}
\newcommand{\s}{\par\medskip}
\newcommand{\sm}{\par\smallskip}
\newcommand{\bs}{\par\bigskip}
\pagestyle{empty}
\usetikzlibrary{arrows,decorations.pathmorphing,backgrounds,positioning,fit,petri,matrix}
\begin{document}
\begin{tikzpicture}
\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=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.west) to (e.east);
\draw (f.east) to (g.west);
\end{tikzpicture}
\end{document}
- Attachments
-
- chemfig-bond-length.png (18.22 KiB) Viewed 11411 times
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
tikZ | Drawing Molecules
Isn't this exactly what chemfig does?ghostanime2001 wrote:[…] How do I set the bond length to be the same length for example 1cm? […]
Code: Select all
\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{chemfig}
\setatomsep{1cm}
\begin{document}
\chemfig{\chemabove{C}{\hspace{1pc}\scriptstyle +}(-[2]H)(-[4]H)(-[6]H)-C-[:-60]O-H}
\end{document}
- Attachments
-
- tmp.png (2.74 KiB) Viewed 11410 times
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10