如何改变 chemfig 中双键的键长?

如何改变 chemfig 中双键的键长?

使用 chemfig 包,是否可以改变双键中 π 键的键长?我知道 -command \setbondoffset{},但在这种情况下,它不起作用。希望下面的例子能阐明我想要实现的目标。

输入:

\documentclass{scrartcl}
\usepackage{chemfig}

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

输出:

输出。

期望输出:

期望的输出。

答案1

我定义了 TiZ 装饰:

\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}

两个装饰品lsdbond埃夫特s霍特d欧布莱纽带) 和rsdbondrs霍特d欧布莱纽带) 的定义。 lsdbond将缩短的 (pi) 键放在中间 (sigma) 键的左侧,rsdbond右侧。它们采用两个参数:第一个是键出发原子的键角;第二个是到达原子的键角。角度以度为单位,应在 (0,180] 范围内。

答案2

六年后,上述接受的答案不再适用于 Chemfig 1.5 版本...使用以下代码

\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}

chemfig 选项已经改变,并且 catcode 语句似乎至关重要。

编辑:通过对目前给出的答案进行实验,我发现公式的缩放只会产生较差的结果。灵感来自另一个帖子这里我建议

\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}

缩短双键的量必须以 1.0 的比例给出...您可以通过反复试验找到适合您目的的值。

相关内容