Chemfig 新线反应方案

Chemfig 新线反应方案

我最近才开始使用 LaTeX,并且chemfig对在反应箭头下方或上方的文本中创建新行有疑问。我试图将 MW、160 °C、5 分钟置于 Na₂CO₃、H₂O 下作为新行。我将不胜感激任何帮助!

答案1

您可以将箭头标签的内容放在\parbox

\documentclass{article}
\usepackage{chemfig}
\begin{document}

\schemestart
 A \arrow{->[\parbox{5cm}{\centering a\\b}][c]} B
\schemestop

\end{document}

在此处输入图片描述

或者为了方便定义一个命令:

\documentclass{article}
\usepackage{chemfig}

\makeatletter
\newcommand\stack[2][5cm]{\parbox{#1}{\centering#2}}
\makeatother

\begin{document}

\schemestart
 A \arrow{->[\stack{a\\b}][c]} B
\schemestop

\end{document}

箭头的标签是节点。如果我们能够将 add 设置align=center为它们的属性,我们就不需要了\parbox。不幸的是,chemfig它没有提供直接访问其属性的接口。节点由\CF@arrow@display@label@i我们可以重新定义的命令放置:

\documentclass{article}
\usepackage{chemfig}

\makeatletter
\def\CF@arrow@display@label@i#1#2#3{%
  \ifx\@empty#1\@empty\else
    \if*\expandafter\@car\detokenize{#1}\@nil
      \ifCF@reac@debug
         node[pos=#2,sloped,yshift=#3\CF@arrow@labelsep,draw,fill,cyan](shifted@node){}%
         node[
           draw,rotate=\CF@rotate@node#1\@nil,anchor=\CF@anchor@node#1\@nil#3,at=(shifted@node),
           align=center% <= this is new
         ]{\expandafter\@gobble\@gobble#1}%
      \else
        node[pos=#2,sloped,yshift=#3\CF@arrow@labelsep](shifted@node){}%
        node[
          rotate=\CF@rotate@node#1\@nil,anchor=\CF@anchor@node#1\@nil#3,at=(shifted@node),
          align=center% <= this is new
        ]{\expandafter\@gobble\@gobble#1}%
      \fi
    \else
      \ifCF@reac@debug
        node[pos=#2,sloped,yshift=#3\CF@arrow@labelsep,draw,fill,cyan](shifted@node){}%
        node[
          draw,pos=#2,anchor=-#390,sloped,yshift=#3\CF@arrow@labelsep,
          align=center% <= this is new
        ]{#1}%
      \else
        node[
          pos=#2,anchor=-#390,sloped,yshift=#3\CF@arrow@labelsep,
          align=center% <= this is new
        ]{#1}%
      \fi
    \fi
  \fi
}
\makeatother

\begin{document}

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

\end{document}

最后一次手动重新定义可以更容易地完成@egregregexpatch包裹:

\documentclass{article}
\usepackage{chemfig}
\usepackage{regexpatch}
\makeatletter
% \xpatchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>}
% the starred variant replaces all occurrences of <search>
\xpatchcmd*\CF@arrow@display@label@i{node[}{node[align=center,}{}{}
\makeatother

\begin{document}

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

\end{document}

相关内容