Math & Sciencechemfig | vertical reaction scheme

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
niteshs
Posts: 45
Joined: Wed Jun 06, 2012 9:57 pm

chemfig | vertical reaction scheme

Post by niteshs »

Hi!

I am trying to produce some moderately complex reaction schemes using the chemfig package, but can't figure out how (or if it is even possible) to make a vertical reaction scheme (involving the + sign).

For example:
reactn scheme.png
reactn scheme.png (5.78 KiB) Viewed 7194 times
Is this possible using chemfig?

Here is some code that will produce part of the above scheme (without the + sign):

Code: Select all

%\schemedebug{true} % uncomment to make sense of the compound naming
\schemestart
\subscheme{A}\+{1em,1em}\subscheme{B}\arrow AB
\arrow(@c3--){0}[-90,0.6,] C
\arrow(@c5--)[-90] BC
\arrow(@c6--){0}[180,0.5,] A
\arrow(@c6--) ABC
\schemestop
And here is the output (couldn't get AB to align with ABC even with an invisible arrow):
reactn scheme2.png
reactn scheme2.png (1.32 KiB) Viewed 7194 times
I am vaguely guessing that anchoring may somehow be used but have no idea how. My other option is to produce the scheme image in a separate program and include the graphic, but using chemfig would definitely produce prettier results :)

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

chemfig | vertical reaction scheme

Post by cgnieder »

I myself don't use the \+ macro very often. Instead I make extensive use of the invisible arrow \arrow{0}. How about this:

Code: Select all

\documentclass{article}
\usepackage{chemfig}

\begin{document}

\schemestart
 A \arrow{0}[,.2]+\arrow{0}[,.2] B \arrow AB
 \arrow(@c3--){0}[-90,.2] +
 \arrow{0}[-90,.2] C
 \arrow[-90] BC \arrow ABC
 \arrow(@c7--){0}[180,.2] +
 \arrow{0}[180,.2] A
\schemestop

\end{document}
chemfig_ex.png
chemfig_ex.png (4.03 KiB) Viewed 7192 times
Regards
site moderator & package author
niteshs
Posts: 45
Joined: Wed Jun 06, 2012 9:57 pm

chemfig | vertical reaction scheme

Post by niteshs »

Hi cgnieder!

Thanks for the tip!

Is there a particular reason you prefer not using the \+ macro? (Incidentally I picked up the \+ macro from your reply to my previous post :) )

One reason I can think of is that each compound is automatically "separated" therefore \subscheme is not required. Any other reason for using the invisible arrow instead of \+ ?

Edit: Also, the compounds AB and ABC don't seem to be aligned properly. Adding an invisible vertical arrow between them did not do the trick. Can you think of a solution to this?
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

chemfig | vertical reaction scheme

Post by cgnieder »

Well, preferences... there are three reasons I can think of:
  1. as you mentioned instead of placing A + B in a single node both A, B and the + are placed in nodes for themselves which allows later references. But there's nothing wrong with \subscheme, so...
  2. vertical centering of the compounds and the +. Compare

    Code: Select all

    \schemestart\chemfig{*6(--=---)}\+A\schemestop
    to

    Code: Select all

    \schemestart\chemfig{*6(--=---)}\arrow{0}[,0]\+A\schemestop
  3. not the least: a matter of personal habit
To the second question: there are several solutions I can think of. This “problem” arises because the node of the B has a smaller width than the one of BC. One possibility would be to measure the width of BC and set the node of B to the respective width. However, this will create larger spaces around the B:

Code: Select all

\newlength\tmp
\settowidth\tmp{BC}

\schemestart
 A \arrow{0}[,.2]+\arrow(--b[minimum width=\tmp]){0}[,.2] B \arrow AB
 \arrow(@b--){0}[-90,.2] +
 \arrow{0}[-90,.2] C
 \arrow(--bc)[-90] BC \arrow ABC
 \arrow(@bc--){0}[180,.2] +
 \arrow{0}[180,.2] A
\schemestop
Regards
site moderator & package author
niteshs
Posts: 45
Joined: Wed Jun 06, 2012 9:57 pm

Re: chemfig | vertical reaction scheme

Post by niteshs »

Thank you cgnieder, your solution works fine and I don't mind the extra space around B. I was half expecting a solution having to do something with anchoring (which I haven't looked into myself yet).

Thanks again!
unbonpetit

chemfig | vertical reaction scheme

Post by unbonpetit »

niteshs wrote:I was half expecting a solution having to do something with anchoring
Something like this ?

Code: Select all

\documentclass{article}
\usepackage{chemfig}
\begin{document}
\schemestart
	\subscheme{%
		A \arrow{0}[,.2]+\arrow{0}[,.2] B
		\arrow(@c4--){0}[-90,.2] +
		\arrow{0}[-90,.2] C
		\arrow[-90] BC
		\arrow(@c7--){0}[180,.2] +
		\arrow{0}[180,.2] A}
	\arrow(@c1.mid east--) AB
	\arrow(@c7.mid east--) ABC
\schemestop
\end{document}
niteshs
Posts: 45
Joined: Wed Jun 06, 2012 9:57 pm

Re: chemfig | vertical reaction scheme

Post by niteshs »

Yes unbonpetit, that's the direction I was thinking in (without actually knowing how to do it).

Thanks to your solution I now also know how to use anchors (almost)! ;)
Post Reply