5

Related to this question I am trying to generate a figure using package chemfig. Actually, my problem is that the lower part of the figure is cropped, specifically the H under the N.

This is the code:

\documentclass{standalone}
\usepackage{chemfig}
\begin{document}
\chemfig{*6(-\chembelow{\color{blue}N}{H}-(={\color{red}O})-{\color{blue}N}=(-{\color{blue}N}H_2)-=)}
\end{document}

Below, you see the figure as I got:

enter image description here

and as it should be:

enter image description here

werty
  • 311
  • Is there an environment version of \chemfig? e.g. \begin{chemfig}... \end{chemfig}? If so, use that and add \standaloneenv{chemfig} to the preamble. – cfr Aug 16 '15 at 14:07
  • @cfr I'm curious: why would or should that help? – cgnieder Aug 16 '15 at 14:31
  • 1
    @clements In fact, it does not help. – werty Aug 16 '15 at 14:56
  • @clemens It might not but it does with e.g. forest. If you are using forest, setting \standaloneenv{forest helps standalone get the cropping etc. correct. Especially if you are using multi because standalone starts a new page for each standaloneenv, which does not include forest by default. But I don't know if there is a macro equivalent e.g. \standalonecmd{} - I've never seen this. Then again, maybe I've just not looked in the right place? – cfr Aug 16 '15 at 16:17
  • @cfr Ah OK. I never used forest so I can't compare if the problems are anywhere similar to \chembelow in this case… – cgnieder Aug 16 '15 at 16:31
  • @clemens And I've never used \chembelow so I can't either ;). This is why it was a comment rather than an answer! – cfr Aug 16 '15 at 18:57

2 Answers2

4

Use \Chembelow (upper case!) instead of \chembelow. From the manual (emphasis by me):

The macro[...]

\chembelow[<dim>]{<code>}{<stuff>}

place[s] the <stuff> [...] below the <code> [...] without changing the bounding box of <code>.

The uppercase version on the other hand does extend the bounding box. (\lewis and \Lewis have the same relationship, by the way.)

JPi
  • 13,595
cgnieder
  • 66,645
1

The Chembelow macro can be used but the result is not perfect since the bounding box (too high) modifies the position of bonds coming and leaving N:

enter image description here

\Chembelow cannot give a good result and \chembelow sends H outside the croping. A solution is to use an invisible bond (the .25 lenght found with try/error):

\documentclass{standalone}
\usepackage{chemfig}
\begin{document}
\chemfig{*6(-\color{blue}{N}(-[,.25,,,draw=none]H)-(={\color{red}O})-{\color{blue}N}=(-{\color{blue}N}H_2)-=)}
\end{document}

enter image description here

Pershaps the better solution, but more verbose, is to use \chemfig* (with a star) since it the length of the invisible bond can be set to 0 (0 is 0.0001 for tikz):

\chemfig*{*6(-\color{blue}{N}(-[,.0001,,,draw=none]{\lower0.25ex\hbox{H}})-(={\color{red}O})-{\color{blue}N}=(-{\color{blue}N}H_2)-=)}
unbonpetit
  • 6,190
  • 1
  • 20
  • 26