You could place the arrow's label's contents in a \parbox
:
\documentclass{article}
\usepackage{chemfig}
\begin{document}
\schemestart
A \arrow{->[\parbox{5cm}{\centering a\\b}][c]} B
\schemestop
\end{document}
or for convenience define a command:
\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}
The arrow's labels are tikz nodes. If we were able to set add align=center
to their properties we would not need the \parbox
. Unfortunately chemfig
doesn't provide an interface to access their properties directly. The nodes are placed by a command \CF@arrow@display@label@i
which we could redefine:
\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}
The last manual redefinition can be done easier with @egreg's regexpatch
package:
\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}
Best Answer
Here are two versions, one inspired by the example in the
chemfig
manual, the other closer to the image in your question: