chemfig 中弯曲箭头的位置标签?

chemfig 中弯曲箭头的位置标签?

我正在尝试用 LaTeX 创建以下图像: 化学降解途径

但是,我无法将标签定位在第二个弯曲箭头上。下面是我能生成的。

LaTeX 产生的降解途径

如果您注意到第二个 O2 的间距与第一个 O2 的间距并不完全相同。以下是我的 MWE:

\documentclass{article}
\usepackage{chemfig}
\usepackage{fixltx2e}   % needed on my machine for textsubscript
\begin{document}
\begin{center}
\schemestart
\chemfig{*6(-=-=(-CH_3)-=)}
\arrow{-U>[O\textsubscript{2}][][][.5][]}
\chemfig{*6(-=-(-OH)=(-CH_3)-=)}
\arrow{-U>[*{0.north east}O\textsubscript{2}][][][-.5][-60]}
\chemfig{*6(-=(-OH)-(-OH)=(-CH_3)-=)}
\schemestop
\end{center}
\end{document}

我正在使用pdflatex mwe.tex编译pdfTeX 3.1415926502.6.1.40.15 (TeX Live 2015/dev/Debian)

答案1

总结:如果您只想要解决方案,请向下滚动到换行符后。

定义新的 -u> 箭头

据我所知,没有一种简单的方法可以将-U>箭头的标签放在底部而无需重新定义,如下所示(将其放在您的序言中):

\makeatletter
\definearrow5{-u>}{%
    \CF@arrow@shift@nodes{#3}%
    \expandafter\draw\expandafter[\CF@arrow@current@style](\CF@arrow@start@node)--(\CF@arrow@end@node)node[midway](uarrow@arctangent){};%
    \CF@ifempty{#4}
    {\def\CF@uarrow@radius{0.333}}
    {\def\CF@uarrow@radius{#4}}%
    \CF@ifempty{#5}%
    {\def\CF@uarrow@absangle{60}}
    {\pgfmathsetmacro\CF@uarrow@absangle{abs(#5)}}
    %
    \edef\CF@tmp@str{[\CF@ifempty{#1}{draw=none}{\unexpanded\expandafter{\CF@arrow@current@style}},-]}%
    \expandafter\draw\CF@tmp@str (uarrow@arctangent)%
    arc[radius=\CF@compound@sep*\CF@current@arrow@length*\CF@uarrow@radius,start angle=\CF@arrow@current@angle+90,delta angle=\CF@uarrow@absangle]node(uarrow@start){};
    %
    \edef\CF@tmp@str{[\CF@ifempty{#2}{draw=none}{\unexpanded\expandafter{\CF@arrow@current@style}},-]}%
    \expandafter\draw\CF@tmp@str (uarrow@arctangent)%
    arc[radius=\CF@compound@sep*\CF@current@arrow@length*\CF@uarrow@radius,%
    start angle=\CF@arrow@current@angle+90,%
    delta angle=-\CF@uarrow@absangle]%
    node(uarrow@end){};
    \pgfmathsetmacro\CF@tmp@str{\CF@uarrow@radius*cos(\CF@arrow@current@angle)<0?"+":"-"}%
    \ifdim\CF@uarrow@radius pt>\z@
    \CF@arrow@display@label{#1}{0}\CF@tmp@str{uarrow@start}{#2}{1}\CF@tmp@str{uarrow@end}%
    \else
    \CF@arrow@display@label{#2}{0}\CF@tmp@str{uarrow@start}{#1}{1}\CF@tmp@str{uarrow@end}%
    \fi
}
\makeatother

这是基于原始-U>定义,但对于标签以下箭头。这里的语法是(请注意使用小写字母u,而不是U):

\arrow{-u>[#1][#2][#3][#4][#5]}

与原始版本一样,它接受 5 个参数,如下所示:

  • #1:标签放置在“第一个”(箭头开始)
  • #2:要放置“第二个”标签(箭头末端)
  • #3:yshift 为箭头,正数为向上移动,反之亦然
  • #4:圆弧半径(默认0.333)
  • #5:圆弧的角度(默认 60)

只是为了证明它适用于所有 5 个参数:

\documentclass{article}
\usepackage{chemfig}
%\usepackage{fixltx2e}   % needed on my machine for textsubscript

\makeatletter
\definearrow5{-u>}{%
    \CF@arrow@shift@nodes{#3}%
    \expandafter\draw\expandafter[\CF@arrow@current@style](\CF@arrow@start@node)--(\CF@arrow@end@node)node[midway](uarrow@arctangent){};%
    \CF@ifempty{#4}
    {\def\CF@uarrow@radius{0.333}}
    {\def\CF@uarrow@radius{#4}}%
    \CF@ifempty{#5}%
    {\def\CF@uarrow@absangle{60}}
    {\pgfmathsetmacro\CF@uarrow@absangle{abs(#5)}}
    %
    \edef\CF@tmp@str{[\CF@ifempty{#1}{draw=none}{\unexpanded\expandafter{\CF@arrow@current@style}},-]}%
    \expandafter\draw\CF@tmp@str (uarrow@arctangent)%
    arc[radius=\CF@compound@sep*\CF@current@arrow@length*\CF@uarrow@radius,start angle=\CF@arrow@current@angle+90,delta angle=\CF@uarrow@absangle]node(uarrow@start){};
    %
    \edef\CF@tmp@str{[\CF@ifempty{#2}{draw=none}{\unexpanded\expandafter{\CF@arrow@current@style}},-]}%
    \expandafter\draw\CF@tmp@str (uarrow@arctangent)%
    arc[radius=\CF@compound@sep*\CF@current@arrow@length*\CF@uarrow@radius,%
    start angle=\CF@arrow@current@angle+90,%
    delta angle=-\CF@uarrow@absangle]%
    node(uarrow@end){};
    \pgfmathsetmacro\CF@tmp@str{\CF@uarrow@radius*cos(\CF@arrow@current@angle)<0?"+":"-"}%
    \ifdim\CF@uarrow@radius pt>\z@
    \CF@arrow@display@label{#1}{0}\CF@tmp@str{uarrow@start}{#2}{1}\CF@tmp@str{uarrow@end}%
    \else
    \CF@arrow@display@label{#2}{0}\CF@tmp@str{uarrow@start}{#1}{1}\CF@tmp@str{uarrow@end}%
    \fi
}
\makeatother

\begin{document}
    \begin{center}
        \schemedebug{true} % Only to show boxes, nodes etc.
        \schemestart
        \chemfig{*6(-=-=(-CH_3)-=)}
        \arrow{-U>[\chemfig{O_2}][][][.5][]}
        \chemfig{*6(-=-(-OH)=(-CH_3)-=)}
        \arrow{-u>[A][B][5pt][.5][75]} % <---------- applying the new arrow type here
        \chemfig{*6(-=(-OH)-(-OH)=(-CH_3)-=)}
        \schemestop
    \end{center}
\end{document}

产量:

例子

注意:

  • AB按照指定顺序放置在箭头的起点和终点处。
  • 我指出积极的yshift 值,事实上,箭头发生了移动向上. (比较箭头的红色节点和白色节点)
  • 圆弧的半径也明显更长,因为 0.5 > 默认值的 0.333。
  • 可以看出圆弧的角度比默认值要大,因为 75 > 60(改成其他值自己看看就知道了)。

您的解决方案

\documentclass{article}
\usepackage{chemfig}
%\usepackage{fixltx2e}   % needed on my machine for textsubscript

\makeatletter
\definearrow5{-u>}{%
    \CF@arrow@shift@nodes{#3}%
    \expandafter\draw\expandafter[\CF@arrow@current@style](\CF@arrow@start@node)--(\CF@arrow@end@node)node[midway](uarrow@arctangent){};%
    \CF@ifempty{#4}
    {\def\CF@uarrow@radius{0.333}}
    {\def\CF@uarrow@radius{#4}}%
    \CF@ifempty{#5}%
    {\def\CF@uarrow@absangle{60}}
    {\pgfmathsetmacro\CF@uarrow@absangle{abs(#5)}}
    %
    \edef\CF@tmp@str{[\CF@ifempty{#1}{draw=none}{\unexpanded\expandafter{\CF@arrow@current@style}},-]}%
    \expandafter\draw\CF@tmp@str (uarrow@arctangent)%
    arc[radius=\CF@compound@sep*\CF@current@arrow@length*\CF@uarrow@radius,start angle=\CF@arrow@current@angle+90,delta angle=\CF@uarrow@absangle]node(uarrow@start){};
    %
    \edef\CF@tmp@str{[\CF@ifempty{#2}{draw=none}{\unexpanded\expandafter{\CF@arrow@current@style}},-]}%
    \expandafter\draw\CF@tmp@str (uarrow@arctangent)%
    arc[radius=\CF@compound@sep*\CF@current@arrow@length*\CF@uarrow@radius,%
    start angle=\CF@arrow@current@angle+90,%
    delta angle=-\CF@uarrow@absangle]%
    node(uarrow@end){};
    \pgfmathsetmacro\CF@tmp@str{\CF@uarrow@radius*cos(\CF@arrow@current@angle)<0?"+":"-"}%
    \ifdim\CF@uarrow@radius pt>\z@
    \CF@arrow@display@label{#1}{0}\CF@tmp@str{uarrow@start}{#2}{1}\CF@tmp@str{uarrow@end}%
    \else
    \CF@arrow@display@label{#2}{0}\CF@tmp@str{uarrow@start}{#1}{1}\CF@tmp@str{uarrow@end}%
    \fi
}
\makeatother

\begin{document}
    \begin{center}
%       \schemedebug{true} % Activate if you want to see the nodes etc.
        \schemestart
        \chemfig{*6(-=-=(-CH_3)-=)}
        \arrow{-U>[\chemfig{O_2}][][][.5][]}
        \chemfig{*6(-=-(-OH)=(-CH_3)-=)}
        \arrow{-u>[\chemfig{O_2}][][][.5][]}
        \chemfig{*6(-=(-OH)-(-OH)=(-CH_3)-=)}
        \schemestop
    \end{center}
\end{document}

最终图片

一些评论:

  • 我用它\chemfig{O_2}来代替\textsubscript你原始代码中的版本。
  • 传递的其他可选参数只有0.5圆弧半径,这是您原始问题中提到的。其余的可以留空。请注意,如果您只需要 60 度,则无需指定角度,因为这是默认值。

相关内容