2

I last used chemfig a while ago. Much has changed since then, especially the \charge command.

I'm trying to draw a simple molecule. In number 3 it looks exactly as I want, but I'd like to be able to be able to have the methyl first in the code. I do this in #2 (works well) and #4 (adding \charge causes an error. Why is this? How can I avoid it?

! Package chemfig Error: no atom found at position 2, pershaps you mispelled the optional argument of the bond...\CF_error ...e {Package \CFname \space Error: #1.} -[:-30]F}

MWE:

\documentclass[11pt,tikz,margin=1.5mm]{standalone}

\usepackage{chemfig}

\begin{document}

% works with methyl as branch
\chemfig{H_2N(-[:90,,2])
-[:-30]F}

% correct, but without charge
\chemfig{-[:270,,,2]H_2N
-[:-30]F}

% #1 with charge
\chemfig{H_2\charge{45:2pt=$+$}{N}(-[:90,,2])
-[:-30]F}

% #2 with charge
\chemfig{-[:270,,,2]H_2\charge{45:2pt=$+$}{N}
-[:-30]F}

\end{document}

enter image description here

1 Answer 1

2

You can split the H_2 and the N with | and then you can tell chemfig where to arrive at the atom. Is this how you want it?


\documentclass[border=1cm]{standalone}

\usepackage{chemfig}

\begin{document}

\chemfig{-[:-90,,,2]H_2|\charge{45:2pt=$+$}{N}-[:-30]F}

\end{document}

enter image description here

2
  • It is! Does \charge fuse the H_2 and the N somehow?
    – Imp54
    Apr 16, 2021 at 3:00
  • 1
    @imp54 I can only guess how it works: You draw a molecule like CH3-CH3. \chemfig splits these groups (CH3) into their atoms (ignoring that H3 is not a real atom). So CH3 is split into C and H3. But \chemfig ignores everything in {} according to the \chemfig manual. Therefore the N in brackets of \charge is not recognized as an atom and thus it is not available as a destination for a bond. That is way your error says that there is no atom at this position. Splitting these molecules manualy tells \chemfig here is a molecule that consists of more than one atom.
    – Roland
    Apr 16, 2021 at 3:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .