[Tex/LaTex] How to alter the bond length of a double bond in chemfig

chemfig

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.

Best Answer

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].

Related Question