在 chemfig 中写下方箭头(\arrow{-U>})的简单方法?

在 chemfig 中写下方箭头(\arrow{-U>})的简单方法?

我已经使用 chemfig 一段时间了,我非常喜欢它。但有些小事我还是做不到。看看这个例子:

\schemestart
\chemname{\chemfig{[2]OH-[4]CH_2-CH(-[0]OH)-CH_2(-[0]OH)}}{Glycerol} 
\hspace{.3cm}
\arrow{-U>[\footnotesize ATP][\footnotesize ADP + H$^{+}$][][0.6][45]}
\hspace{.7cm}
\chemname{\chemfig{[2]O(-[0]\circleatom{P})-[4]CH_2-CH(-[0]OH)-CH_2(-[0]OH)}}{Glycerol 3-phosphate} 
\schemestop

我想在 U 形箭头下方写下酶的名称(甘油激酶)。有什么简单的方法可以做到这一点吗?

答案1

我猜这\circleatom我在这里用的是。我依稀记得以前定义过类似的东西。

箭头中间-U>是一个名为 的节点Uarrow@arctangent。如果你只有一个这样的箭头,你可以利用这个事实在它下面写一些内容\chemmove

\documentclass{article}
\usepackage{chemfig}
\newcommand*\circleatom[1]{\tikz\node[circle,draw]{\printatom{#1}};}

\begin{document}

\setarrowoffset{1cm}
\schemestart
  \chemname
    {\chemfig{[2]OH-[4]CH_2-CH(-[0]OH)-CH_2(-[0]OH)}}
    {Glycerol} 
  \arrow{-U>[\footnotesize ATP]%
            [\footnotesize ADP + H$^{+}$]%
            []%
            [.25]}[,3]
  \chemname
    {\chemfig{[2]O(-[0]\circleatom{P})-[4]CH_2-CH(-[0]OH)-CH_2(-[0]OH)}}
    {Glycerol 3-phosphate} 
\schemestop
\makeatletter
  \chemmove{\node[below] at (Uarrow@arctangent) {below}; }
\makeatother

\end{document}

在此处输入图片描述

如果你更经常需要这样做,你应该考虑使用 usingschemfig来添加新的箭头类型。例如,你可以调整箭头的定义-U>来定义一个接受第三个参数的变体:

\makeatletter
% define an arrow type `-y>' that takes 6 optional arguments
% \arrow{-y>[<label arc start>]%
%           [<label arc end>]%
%           [<label below>]%
%           [<arrow shift>]%
%           [<ratio arc radius/arrow length>]% default: 0.333
%           [<half of angle of arc>]% default: 60
\definearrow{6}{-y>}{%
    % shift the arrow:
    \CF@arrow@shift@nodes{#4}%
    % draw main arrow:
    \expandafter\draw\expandafter[\CF@arrow@current@style,-CF@full]
      (\CF@arrow@start@node)--(\CF@arrow@end@node)node[midway](yarrow@arctangent){};%
    % draw first half of arc if label #1 is given:
    \edef\CF@tmp@str{\ifx\@empty#1\@empty[draw=none]\fi}%
    \expandafter\draw\CF@tmp@str (yarrow@arctangent)%
        arc[
          radius=\CF@compound@sep*\CF@current@arrow@length*\ifx\@empty#5\@empty0.333\else#5\fi,
          start angle=\CF@arrow@current@angle-90,
          delta angle=-\ifx\@empty#6\@empty60\else#6\fi]
        node(yarrow@start){};
    % draw second half of arrow if label #2 is given:
    \edef\CF@tmp@str{[\ifx\@empty#2\@empty draw=none,\fi-CF@full]}%
    \expandafter\draw\CF@tmp@str (yarrow@arctangent)%
        arc[
          radius=\CF@compound@sep*\CF@current@arrow@length*\ifx\@empty#5\@empty0.333\else#5\fi,
          start angle=\CF@arrow@current@angle-90,%
          delta angle=\ifx\@empty#6\@empty60\else#6\fi]
        node(yarrow@end){};
    \edef\CF@tmp@str{\if\string-\expandafter\@car\detokenize{#4.}\@nil-\else+\fi}%
    % place labels #1 and #2:
    \CF@arrow@display@label{#1}{0}\CF@tmp@str{yarrow@start}{#2}{1}\CF@tmp@str{yarrow@end}%
    % place label #3:
    \CF@arrow@display@label{#3}{0.5}-\CF@arrow@start@node{}{}{}\CF@arrow@end@node
}
\makeatother

现在可以按如下方式使用它:

\schemestart
 A
 \arrow{-y>[a][b][below]}
 B
\schemestop

在此处输入图片描述

它有三个另外的可选参数,与的相同-U>


完整代码:

\documentclass{article}
\usepackage{chemfig}
\newcommand*\circleatom[1]{\tikz\node[circle,draw]{\printatom{#1}};}


\makeatletter
% define an arrow type `-y>' that takes 6 optional arguments
% \arrow{-y>[<label arc start>]%
%           [<label arc end>]%
%           [<label below>]%
%           [<arrow shift>]%
%           [<ratio arc radius/arrow length>]% default: 0.333
%           [<half of angle of arc>]% default: 60
\definearrow{6}{-y>}{%
    % shift the arrow:
    \CF@arrow@shift@nodes{#4}%
    % draw main arrow:
    \expandafter\draw\expandafter[\CF@arrow@current@style,-CF@full]
      (\CF@arrow@start@node)--(\CF@arrow@end@node)node[midway](yarrow@arctangent){};%
    % draw first half of arc if label #1 is given:
    \edef\CF@tmp@str{\ifx\@empty#1\@empty[draw=none]\fi}%
    \expandafter\draw\CF@tmp@str (yarrow@arctangent)%
        arc[
          radius=\CF@compound@sep*\CF@current@arrow@length*\ifx\@empty#5\@empty0.333\else#5\fi,
          start angle=\CF@arrow@current@angle-90,
          delta angle=-\ifx\@empty#6\@empty60\else#6\fi]
        node(yarrow@start){};
    % draw second half of arrow if label #2 is given:
    \edef\CF@tmp@str{[\ifx\@empty#2\@empty draw=none,\fi-CF@full]}%
    \expandafter\draw\CF@tmp@str (yarrow@arctangent)%
        arc[
          radius=\CF@compound@sep*\CF@current@arrow@length*\ifx\@empty#5\@empty0.333\else#5\fi,
          start angle=\CF@arrow@current@angle-90,%
          delta angle=\ifx\@empty#6\@empty60\else#6\fi]
        node(yarrow@end){};
    \edef\CF@tmp@str{\if\string-\expandafter\@car\detokenize{#4.}\@nil-\else+\fi}%
    % place labels #1 and #2:
    \CF@arrow@display@label{#1}{0}\CF@tmp@str{yarrow@start}{#2}{1}\CF@tmp@str{yarrow@end}%
    % place label #3:
    \CF@arrow@display@label{#3}{0.5}-\CF@arrow@start@node{}{}{}\CF@arrow@end@node
}
\makeatother

\begin{document}

\setarrowoffset{1cm}
\schemestart
  \chemname
    {\chemfig{[2]OH-[4]CH_2-CH(-[0]OH)-CH_2(-[0]OH)}}
    {Glycerol} 
  \arrow{-y>[\footnotesize ATP]%
            [\footnotesize ADP + H$^{+}$]%
            [below]%
            []%
            [.25]}[,3]
  \chemname
    {\chemfig{[2]O(-[0]\circleatom{P})-[4]CH_2-CH(-[0]OH)-CH_2(-[0]OH)}}
    {Glycerol 3-phosphate} 
\schemestop

\end{document}

答案2

以下是 @runiq 对上述 @clemens 代码的扩展的更新(部分是我的答案的扩展这里),与当前版本兼容chemfig (截至 2017 年,v1.2e),代表一支万能的-X>箭头,可以在箭头的上方、下方和中间进行标记。

看起来一样,我知道……

输出看起来相同,但有一些内部变化,如下所述。

但首先...

使用方法简介

语法与原始-U>箭头类似,并且(显然)与@runiq 的-X>箭头相同。

\arrow{-X>[#1][#2][#3][#4][#5][#6][#7][#8][#9]}

其中参数为:

  • [#1]:标签放置在顶部箭头(开始)处
  • [#2]:标签放置在顶部箭头(末端)
  • [#3]:标签放置在顶部箭头处(中间)
  • [#4]:标签放置在底部箭头(开始)处
  • [#5]:标签放置在底部箭头(末端)处
  • [#6]:标签放置在底部箭头处(中间)
  • [#7]:箭头方向为 Y 轴偏移,向上偏移为正,向下偏移为负
  • [#8]:圆弧半径(默认0.333)
  • [#9]:圆弧的角度(默认60)

与@runiq 的回答相比有什么变化

  • 整体代码结构不同。这是基于文档-U>中的定义chemfig
  • 正如评论中所指出的,箭头由 给出-CF,不再是 。-CF@full
  • 绘制箭头时作为样式包含CF@arrow@current@style。简而言之,这意味着默认箭头设置将传递给箭头-X>。如下所示:

修改版与原版


代码和结果

\makeatletter
% Arguments:
% #1, #2, #3, #4, #5, #6: Labels as shown in the output figure
% #7: yshift for the arrow, positive for upwards shift, vice versa
% #8: radius of arc (default 0.333)
% #9: angle for arc (default 60)
\definearrow9{-X>}{%
    \CF@arrow@shift@nodes{#7}%
    \expandafter\draw\expandafter[\CF@arrow@current@style](\CF@arrow@start@node)--(\CF@arrow@end@node)node[midway](Xarrow@arctangent){};%
    \CF@ifempty{#8}
    {\def\CF@Xarrow@radius{0.333}}
    {\def\CF@Xarrow@radius{#8}}%
    \CF@ifempty{#9}%
    {\def\CF@Xarrow@absangle{60}}
    {\pgfmathsetmacro\CF@Xarrow@absangle{abs(#9)}}
    % Draw top arrow (start)
    \edef\CF@tmp@str{[\CF@ifempty{#1}{draw=none}{\unexpanded\expandafter{\CF@arrow@current@style}},-]}%
    \expandafter\draw\CF@tmp@str (Xarrow@arctangent)%
    arc[radius=\CF@compound@sep*\CF@current@arrow@length*\CF@Xarrow@radius,start angle=\CF@arrow@current@angle-90,delta angle=-\CF@Xarrow@absangle]node(Xarrow1@start){};
    % Draw bottom arrow (end)
    \edef\CF@tmp@str{[\CF@ifempty{#2}{draw=none}{\unexpanded\expandafter{\CF@arrow@current@style}},-CF]}%
    \expandafter\draw\CF@tmp@str (Xarrow@arctangent)%
    arc[radius=\CF@compound@sep*\CF@current@arrow@length*\CF@Xarrow@radius,%
    start angle=\CF@arrow@current@angle-90,%
    delta angle=\CF@Xarrow@absangle]%
    node(Xarrow1@end){};
    % Draw bottom arrow (start)
    \edef\CF@tmp@str{[\CF@ifempty{#4}{draw=none}{\unexpanded\expandafter{\CF@arrow@current@style}},-]}%
    \expandafter\draw\CF@tmp@str (Xarrow@arctangent)%
    arc[radius=\CF@compound@sep*\CF@current@arrow@length*\CF@Xarrow@radius,start angle=\CF@arrow@current@angle+90,delta angle=\CF@Xarrow@absangle]node(Xarrow2@start){};
    % Draw bottom arrow (end)
    \edef\CF@tmp@str{[\CF@ifempty{#5}{draw=none}{\unexpanded\expandafter{\CF@arrow@current@style}},-CF]}%
    \expandafter\draw\CF@tmp@str (Xarrow@arctangent)%
    arc[radius=\CF@compound@sep*\CF@current@arrow@length*\CF@Xarrow@radius,%
    start angle=\CF@arrow@current@angle+90,%
    delta angle=-\CF@Xarrow@absangle]%
    node(Xarrow2@end){};
    % Insert labels
    \pgfmathsetmacro\CF@tmp@stra{\CF@Xarrow@radius*cos(\CF@arrow@current@angle)<0?"-":"+"}%
    \pgfmathsetmacro\CF@tmp@strb{\CF@Xarrow@radius*cos(\CF@arrow@current@angle)<0?"+":"-"}%
    \ifdim\CF@Xarrow@radius pt>\z@
        \CF@arrow@display@label{#1}{0}\CF@tmp@stra{Xarrow1@start}{#2}{1}\CF@tmp@stra{Xarrow1@end}%
        \CF@arrow@display@label{#4}{0}\CF@tmp@strb{Xarrow2@start}{#5}{1}\CF@tmp@strb{Xarrow2@end}%
        \CF@arrow@display@label{#3}{0.5}\CF@tmp@stra\CF@arrow@start@node{}{}{}\CF@arrow@end@node%
        \CF@arrow@display@label{#6}{0.5}\CF@tmp@strb\CF@arrow@start@node{}{}{}\CF@arrow@end@node%
    \else
        \CF@arrow@display@label{#2}{0}\CF@tmp@stra{Xarrow1@start}{#1}{1}\CF@tmp@stra{Xarrow1@end}%
        \CF@arrow@display@label{#5}{0}\CF@tmp@strb{Xarrow2@start}{#4}{1}\CF@tmp@strb{Xarrow2@end}%
        \CF@arrow@display@label{#3}{0.5}\CF@tmp@stra\CF@arrow@start@node{}{}{}\CF@arrow@end@node%
        \CF@arrow@display@label{#6}{0.5}\CF@tmp@strb\CF@arrow@start@node{}{}{}\CF@arrow@end@node%
    \fi
}
\makeatother

将上面的代码放在序言中,下面的代码产生以下输出:

\documentclass{article}
\usepackage{chemfig}
% <paste def. of -X> here>
\begin{document}
    \begin{center}
    \schemestart
    A
    \arrow{-X>[1][2][3][4][5][6][][0.333][60]}
    B
    \arrow{-X>[][2][][4][][][5pt][0.5][70]}% Note the yshift, radius and angle changes
    C
    \schemestop
    \end{center}
\end{document}

最终的


有虫子?

不幸的是,将半径(参数#8)设置为负数会水平翻转两个U箭头(即它们从 B 指向 A),但直箭头仍然会从 A 指向 B。就目前情况而言,我看不出有办法解决这个问题,除非完全重新定义,或者定义一个替代的、反向的-X>箭头。

答案3

编辑:请参阅 Troy 的回答,了解该命令的更新版本,该更新版本可与较新版本的 chemfig 配合使用。


我最近不得不使用类似的箭头并决定扩展@cgnieder 的-y>箭头:

\makeatletter
% Initial arguments:
% #1, #2: Same as for -U> (above arrow)
% #3: Additional label at midpoint (also above arrow)
% #4, #5, #6: Like #1, #2, and #3, but below arrow
\definearrow9{-X>}{%
    \CF@arrow@shift@nodes{#7}%
    \expandafter\draw\expandafter[\CF@arrow@current@style,-CF@full](\CF@arrow@start@node)--(\CF@arrow@end@node)node[midway](Xarrow@arctangent){};%
    \edef\CF@tmp@str{\ifx\@empty#1\@empty[draw=none]\fi}%
    \expandafter\draw\CF@tmp@str (Xarrow@arctangent)%
        arc[radius=\CF@compound@sep*\CF@current@arrow@length*\ifx\@empty#8\@empty0.333\else#8\fi,start angle=\CF@arrow@current@angle-90,%
        delta angle=-\ifx\@empty#9\@empty60\else#9\fi]node(Xarrow1@start){};
    \edef\CF@tmp@str{[\ifx\@empty#2\@empty draw=none,\fi-CF@full]}%
    \expandafter\draw\CF@tmp@str (Xarrow@arctangent)%
        arc[radius=\CF@compound@sep*\CF@current@arrow@length*\ifx\@empty#8\@empty0.333\else#8\fi,start angle=\CF@arrow@current@angle-90,%
        delta angle=\ifx\@empty#9\@empty60\else#9\fi]node(Xarrow1@end){};
    \edef\CF@tmp@str{\ifx\@empty#4\@empty[draw=none]\fi}%
    \expandafter\draw\CF@tmp@str (Xarrow@arctangent)%
        arc[radius=\CF@compound@sep*\CF@current@arrow@length*\ifx\@empty#8\@empty0.333\else#8\fi,start angle=\CF@arrow@current@angle+90,%
        delta angle=\ifx\@empty#9\@empty60\else#9\fi]node(Xarrow2@start){};
    \edef\CF@tmp@str{[\ifx\@empty#5\@empty draw=none,\fi-CF@full]}%
    \expandafter\draw\CF@tmp@str (Xarrow@arctangent)%
        arc[radius=\CF@compound@sep*\CF@current@arrow@length*\ifx\@empty#8\@empty0.333\else#8\fi,start angle=\CF@arrow@current@angle+90,%
        delta angle=-\ifx\@empty#9\@empty60\else#9\fi]node(Xarrow2@end){};
    \edef\CF@tmp@str{\if\string-\expandafter\@car\detokenize{#7.}\@nil-\else+\fi}%
    \CF@arrow@display@label{#1}{0}\CF@tmp@str{Xarrow1@start}{#2}{1}\CF@tmp@str{Xarrow1@end}%
    \CF@arrow@display@label{#3}{0.5}\CF@tmp@str\CF@arrow@start@node{}{}{}\CF@arrow@end@node%
    \edef\CF@tmp@str{\if\string-\expandafter\@car\detokenize{#7.}\@nil+\else-\fi}%
    \CF@arrow@display@label{#4}{0}\CF@tmp@str{Xarrow2@start}{#5}{1}\CF@tmp@str{Xarrow2@end}%
    \CF@arrow@display@label{#6}{0.5}\CF@tmp@str\CF@arrow@start@node{}{}{}\CF@arrow@end@node%
}
\makeatother

箭头-X>有 9 个可选参数。前三个与 的参数类似-y>,但所有参数都是多于箭头。第 4 至第 6 个类似,但位于箭头下方。第 7 至第 9 个是通常的垂直偏移、长度系数和半角,如-U>-y>箭头所示。

箭头-X>实际效果如下:

\schemestart
A
\arrow{-X>[1][2][3][4][5][6]}
B
\schemestop

在此处输入图片描述

答案4

如果将平衡箭头旋转 90°,两个相对箭头之间的距离就会消失。

\schemestart
   Z
     \arrow{-X>[][2][3][4][][]}
   Y
     \arrow{<=X=>[1][2][3][4][5][6]}[-90,1]
   X
\schemestop

[ 在此处输入图片描述]

相关内容