[Tex/LaTex] Easy way to write below arrow (\arrow{-U>}) in chemfig

arrowschemfig

I have been using chemfig for a while and I like it very much. But some small things I still can't do. Check this example:

\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

I would like to write the enzyme's name (glycerol kinase) below the U-shaped arrow. Is there an easy way to do that?

Best Answer

I'm guessing the \circleatom is a copy of what I used here. I vaguely remembered having defined something like it before.

The middle of an -U> arrow is a node named Uarrow@arctangent. If you have only one such arrow you can use that fact to write something beneath it with \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}

enter image description here

If you need that more often you should consider usings chemfig's possibility to add new arrow types. You could for example adapt the definition of the -U> arrow to define a variant that takes a third argument:

\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

It can now be used as follows:

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

enter image description here

It has three further optional arguments which are the same as the ones of -U>.


The complete code:

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