6

It would be nice if you could help me to draw NO2 in LaTeX. The figure should look like the example image.NO2

On this website is some information about the chemfig/chemmakro package. My code untill now shows a NO2 molecule. Now I just need to add the arrows and nodes (red areas on the original image). How to do that? First of all I will thank @Sigur (he let the chemfig code work) and @ajeh who corrected my angles. And I will thank the German Texwelt (German LaTeX help forum). On that website a user named "Clemens" helped (20 Jul, 05:27) the user "goldsonne23" with the delocated bondings on this website. So all the Tikz part is just "stolen" from Clemns. Here the code:

\documentclass[a4paper, 12pt, twocolumn]{article}
\usepackage[utf8]{inputenc}
\usepackage{libertine}
\usepackage{chemfig, chemmacros}
\usetikzlibrary{decorations}

%delocated bondings
\pgfdeclaredecoration{ddbond}{initial}{
  \state{initial}[width=4pt]{
    \pgfpathlineto{\pgfpoint{4pt}{0pt}}
    \pgfpathmoveto{\pgfpoint{2pt}{2pt}}
    \pgfpathlineto{\pgfpoint{4pt}{2pt}}
    \pgfpathmoveto{\pgfpoint{4pt}{0pt}}
  }
  \state{final}{\pgfpathlineto{\pgfpointdecoratedpathlast}}
}
\tikzset{
  lddbond/.style={decorate,decoration=ddbond},
  rddbond/.style={decorate,decoration={ddbond,mirror}},
  elmove/.style={->,red,shorten >=3pt, shorten <=3pt}
}


\begin{document}
%\chemfig{<atom1><bond type>[<angle>,<coeff>,<tikz code>]<atom2>}
\chemfig{O-[:22.85,,,,rddbond]N-[:-22.85,,,,rddbond]O}
\end{document}

Anyone who can help? Yours faithfully, Basilius

  • 1
    What does 'don't work' mean? – user31729 Nov 26 '14 at 21:33
  • 1
    You need to use : for specified angles. Also, removing draw works very well: \chemfig{O=[:67.15,1]N=[:-67.15, 1]O} – Sigur Nov 26 '14 at 21:40
  • @Sigur: Does this provide the dashed bond lines (whatever they mean) – user31729 Nov 26 '14 at 21:42
  • I don't use this package and I don't know how to produce double (solid/dashed) lines. Did you read the documentation? – Sigur Nov 26 '14 at 21:43
  • When I am trying to compile the MWE using MikTex 2.9, pdflatex crashes with the following error: starting package maintenance... installation directory: "d:\Program Files (x86)\MiKTeX 2.9" package repository: ftp://ctan.mirror.rafal.ca/pub/CTAN/systems/win32/miktex/tm/packages/ lightweight database digest: 759477432c5e6ba0426dad097cdc7af3 pdflatex.EXE: Unknown archive file size. pdflatex.EXE: Data: mh ! LaTeX Error: File 'mathtools.sty' not found. Type X to quit or <RETURN> to proceed, or enter new name. (Default extension: sty) Enter file name: – ajeh Nov 26 '14 at 21:44
4

I cobbled this together using the example in the chemfig package (section 12.7).

Edit: I also added a plain label (without arrows) next to the bond. I think this looks better because the line with arrows is not quite parallel to the line indicating the bond.

enter image description here

\documentclass[a4paper, 12pt, twocolumn]{article}
\usepackage[utf8]{inputenc}
\usepackage{libertine}
\usepackage{chemfig, chemmacros}
\setatomsep{5em}
\usepackage{siunitx}
\usetikzlibrary{calc,decorations}

%delocated bondings
\pgfdeclaredecoration{ddbond}{initial}{
  \state{initial}[width=4pt]{
    \pgfpathlineto{\pgfpoint{4pt}{0pt}}
    \pgfpathmoveto{\pgfpoint{2pt}{2pt}}
    \pgfpathlineto{\pgfpoint{4pt}{2pt}}
    \pgfpathmoveto{\pgfpoint{4pt}{0pt}}
  }
  \state{final}{\pgfpathlineto{\pgfpointdecoratedpathlast}}
}
\tikzset{
  lddbond/.style={decorate,decoration=ddbond},
  rddbond/.style={decorate,decoration={ddbond,mirror}},
  elmove/.style={->,red,shorten >=2pt, shorten <=2pt}
}

\begin{document}
%\chemfig{<atom1><bond type>[<angle>,<coeff>,<tikz code>]<atom2>}
\chemfig{O-[:22.85,,,,rddbond]N-[:-22.85,,,,rddbond]O}

\newcommand\namebond[4][5pt]{\chemmove{\path(#2)--(#3)
node[midway,sloped,yshift=#1]{\color{red}#4};
}}

\newcommand\bondlengtharrows[4][9pt]{\chemmove{\path(#2)--(#3)
node(p1)[above,at end]{}
node(p2)[above,at start]{}
node[midway,sloped,yshift=#1]{\color{red}#4};
\draw[red,stealth-stealth](p1)--(p2);
}}

\newcommand\arcbetweennodes[3]{%
\pgfmathanglebetweenpoints{\pgfpointanchor{#1}{center}}{\pgfpointanchor{#2}{center}}% 
\let#3\pgfmathresult}

\newcommand\arclabel[6][red,thick,shorten <=2pt,shorten >=2pt]{%
\chemmove{%
\arcbetweennodes{#4}{#3}\anglestart \arcbetweennodes{#4}{#5}\angleend \draw[#1]([shift=(\anglestart:#2)]#4)arc(\anglestart:\angleend:#2); \pgfmathparse{(\anglestart+\angleend)/2}\let\anglestart\pgfmathresult \node[shift=(\anglestart:#2+1pt)#4,anchor=\anglestart+180,rotate=\anglestart+90,inner sep=0pt,outer sep=0pt]at(#4){\color{red}#6};}}

\chemfig[scale=2]{@{1}O-[:22.85,,,,rddbond]@{2}N-[:-22.85,,,,rddbond]@{3}O}
\namebond{1}{2}{\footnotesize\SI{119.7}{\pico\meter}}
\bondlengtharrows{2}{3}{\footnotesize\SI{119.7}{\pico\meter}}
\arclabel{5mm}{1}{2}{3}{\footnotesize104.45\si\degree}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.