6

With the chemfig package, is it possible to alter the bond length of the pi-bond in a double-bond? I know about the \setbondoffset{}-command, but in this case, this does not work. Hope the below example clarifies what i want to accomplish.

Input:

\documentclass{scrartcl}
\usepackage{chemfig}

\begin{document}
\chemfig{-[:120]=^[:180]-[:240]}
\end{document}

Output:

Output.

Desired ouput:

Desired output.

| improve this question | | | | |
  • 2
    IIRC there is no option to customize the second bond separately. You could define a TikZ-decoration that looks like it and use that instead. Or you can »cheat«: \chemfig{*6(-=-)} – cgnieder Dec 4 '13 at 12:56
  • 1
    It would be better if the length of second/third bond can be customized as this is the standard drawing of molecular structure involving unsaturated bond for linear molecule, according to IUPAC – bingung Dec 30 '13 at 16:15
  • @jc2254 really? This is interesting! Where does IUPAC say this? – cgnieder Feb 1 '14 at 18:14
  • 2
    @cgnieder Before I was wondering if there is some 'general rules' for representing chemical structure, and I found the 'Graphical representation standards for chemical structure diagrams' from IUPAC very useful (iupac.org/publications/pac/80/2/0277). GR-1.10 talks about the above issue. I don't know this is regarded as very 'official' or not, but it is sometimes great to have consistent representation. And there are many other recommendations! But the point is to represent clear structure. – bingung Feb 2 '14 at 23:15
6

I defined TikZ decorations:

\documentclass{article}
\usepackage{chemfig}
\usetikzlibrary{decorations}
\makeatletter
\newdimen\mystartshorten
\newdimen\myendshorten
\mystartshorten0pt
\myendshorten0pt
\pgfdeclaredecoration{sdbond}{initial}{
  \state{initial}[width=\pgfdecoratedremainingdistance,next state=final]
  {
    {
      \pgftransformyshift{\CF@double@sep}
      \pgfpathmoveto{\pgfqpoint{\mystartshorten}{0pt}}
      {
        \pgftransformxshift{\pgfdecoratedremainingdistance}
        \pgfpathlineto{\pgfqpoint{-\myendshorten}{0pt}}
      }
    }
    \pgfpathmoveto{\pgfpointorigin}
    \pgfpathlineto{\pgfqpoint{\pgfdecoratedremainingdistance}{0pt}}
  }
  \state{final}
  {}
}
\tikzset{
  lsdbond/.code 2 args={%
    \tikzset{decorate, decoration=sdbond}%
    \pgfmathsetlength\mystartshorten{\CF@double@sep*cot((#1)/2)}%
    \pgfmathsetlength\myendshorten{\CF@double@sep*cot((#2)/2}%
  },
  rsdbond/.code 2 args={%
    \tikzset{decorate, decoration={sdbond, mirror}}%
    \pgfmathsetlength\mystartshorten{\CF@double@sep*cot((#1)/2)}%
    \pgfmathsetlength\myendshorten{\CF@double@sep*cot((#2)/2}%
  }
}
\setdoublesep{0.4em}
\setatomsep{2em}
\makeatother
\begin{document}
\chemfig{[:60]--[::-60,,,,,rsdbond={120}{120}]-[::-60]}
\chemfig{[:90]--[::-90,,,,,rsdbond={90}{60}]-[::-120]}
\end{document}

Two decorations lsdbond (left short double bond) and rsdbond (right short double bond) are defined. lsdbond puts the shortened (pi) bond on the left of the middle (sigma) bond, and rsdbond on the right. They take two arguments: the first is the bond angle on the departure atom of the bond; the second on the arrival atom. The angles are in degrees and should be in the range of (0,180].

| improve this answer | | | | |
1

Six years later the accepted answer above does not work anymore with Chemfig in version 1.5 ... Use the following code

\documentclass{article}
\usepackage{chemfig}
\usetikzlibrary{decorations}
\makeatletter
\catcode`\_=11
\newdimen\mystartshorten
\newdimen\myendshorten
\mystartshorten0pt
\myendshorten0pt
% shorter double bond
\pgfdeclaredecoration{sdbond}{initial}{
  \state{initial}[width=\pgfdecoratedremainingdistance,next state=final]
  {
    {
      \pgftransformyshift{\CF_doublesep}%
      \pgfpathmoveto{\pgfqpoint{\mystartshorten}{0pt}}
      {
        \pgftransformxshift{\pgfdecoratedremainingdistance}
        \pgfpathlineto{\pgfqpoint{-\myendshorten}{0pt}}
      }
    },decorations.markings
    \pgfpathmoveto{\pgfpointorigin}
    \pgfpathlineto{\pgfqpoint{\pgfdecoratedremainingdistance}{0pt}}
  }
  \state{final}
  {}
}
\tikzset{
  lsdbond/.code 2 args={%
    \tikzset{decorate, decoration=sdbond}%
    \pgfmathsetlength\mystartshorten{\CF_doublesep*cot((#1)/2)}%
    \pgfmathsetlength\myendshorten{\CF_doublesep*cot((#2)/2}%
  },
  rsdbond/.code 2 args={%
    \tikzset{decorate, decoration={sdbond, mirror}}%
    \pgfmathsetlength\mystartshorten{\CF_doublesep*cot((#1)/2)}%
    \pgfmathsetlength\myendshorten{\CF_doublesep*cot((#2)/2}%
  }
}
\setchemfig{
  double bond sep=0.4em,%
  atom sep=2em%
}
\catcode`\_=8
\makeatother
%
\begin{document}
  \chemfig{[:60]--[::-60,,,,,rsdbond={120}{120}]-[::-60]}
  \chemfig{[:90]--[::-90,,,,,rsdbond={90}{60}]-[::-120]}
\end{document}

The chemfig options have changed and the catcode statements seem to be essential.

Edit: Experimenting with the answers given so far I detected that scaling of the formulas gave only poor results. Inspired from another thread here I propose the following

\documentclass[a5paper]{article}
\usepackage{geometry}
\usepackage{chemfig}
\usetikzlibrary{decorations.markings}
\newcommand{\actualscale}{2.0}% give here your wished scale
\setchemfig{
  atom style={scale=\actualscale},
  double bond sep=3.8pt,% bond spacing
}
%
\catcode`\_=11
\pgfmathsetmacro{\currentscale}{\actualscale}
\tikzset{
  shrtdbl/.code 2 args={
   \tikzset{,shorten >= 0pt,shorten <= 0pt}\global\CF_addtomacro\CF_currentbondstyle{,shorten >= #1*\currentscale,shorten <= #2*\currentscale}}
}
\catcode`\_=8
%
\begin{document}
\chemfig{[:60]-=_[::-60,,,,shrtdbl={2pt}{2pt}]-[::-60]}
\chemfig{[:90]-=_[::-90,,,,shrtdbl={4pt}{2pt}]-[::-120]}
\end{document}

The amount of shortening the double bond must be given in points for scale 1.0 ... You will find proper values for your purposes by trial and error.

| improve this answer | | | | |
  • Welcome to TeX.SE! The new code does not contain any @ symbols, so you don't need \makeatletter and \makeatother anymore. – Marijn Mar 28 at 16:26
  • @Marijn Thanks, you're right. – Erich Kuester Mar 28 at 17:50

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.