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}
As I understand the question, the problem is in the "label" of the arrow and how to do the "circle" with arrows. One way to do this is to play with the properties of chemmove
and the arrows.
For example:
\schemestart
\chemfig{First molecule}
\arrow{->[
\chemname[24pt]{\chemfig{N@{st1}ADH}}{\scriptsize \parbox[c]{40pt}{\centering ammonium formate}}
\hspace{0.5cm}
\chemname[24pt]{\chemfig{N@{en1}AD}}{\chemfig{CO_2}}
\chemmove{\draw[->,shorten <=5pt, shorten >=5pt](st1) .. controls +(+50:8mm) and +(+130:8mm)..(en1);}
\chemmove{\draw[->,shorten <=5pt, shorten >=5pt](en1) .. controls +(-130:8mm) and +(-50:8mm)..(st1);}
\chemmove{\draw[->,shorten <=5pt, shorten >=5pt,transform canvas={yshift=-32pt}](st1) .. controls +(+50:8mm) and +(+130:8mm)..(en1);}
]}[,2.4]
\chemfig{second molecule}
\schemestop
Note that maybe further adjusting of the spaces is required.
Best Answer
Just put it in a
\scalebox
perhaps:However, to answer the more specific question of matching the figure width to the textwidth, we can borrow from Philipp's answer at How to find the ratio of a length command (e.g., \textwidth) to a reference value (e.g., 6cm) ?, and can indirectly scale the box to the textwidth as follows (note I add a lipsum paragraph to show it is the proper width). To do this, I save the figure in
\x
. Then I find the natural width of\x
, so that I can develop the proper scale ratio. Then I\scalebox
the image to the proper scale: