3

I'm trying to make a figure to show hydrogen bounds. But the figure, draw using chemfig and tikz, but the figure overlaps the surrounding text.

Here is my MWE:

\documentclass{article}
\usepackage{chemfig}
\usepackage{lipsum}

\begin{document}
\lipsum[10]


\begin{figure}[h]
\centering
\begin{tikzpicture}
  \schemestart
  \draw (0,0) node {\chemfig{H-@{doublet}\charge{[circle]270=\|,340=\|}{O}-[:75]H}}
   (340:3) node [rotate=-20] {\chemfig{{@{hydrogene}H-\charge{[circle]270=\|,340=\|}{O}-[:75]H}}};
  \schemestop
  \chemmove{\draw [dashed,-] (doublet.340)--(hydrogene.160);}
\end{tikzpicture}
\caption{Schématisation d'une liaison hydrogène dans l'eau}
\label{fig:liaisonH}
\end{figure}

\lipsum[1]

\end{document}

As the chemfig/tikz code is obviously not perfect, any help to improve it is welcome. My primary concern is about the overlap between the figure and the text.

overlap between text and figure

Edit: I found an unsatisfaying way to get it right: I added \vspace{1cm} before the picture and the caption. And then it almost looks like what I want: no more overlap I would prefer: the figure centered, and if someone wants to correct the figure, the dashed line should go from O to H.

5
  • What should it look like in the end and why are you using a tikz enviroment. The problem is chemfig is already laoding a tikz enviroment and uses it´s commands. That is I think what causes the problem.
    – Roland
    Jan 26, 2022 at 2:48
  • @Roland I would like to draw the H-bound, and make a picture with some extras as compared to pure chemfig... As written page 36 of the chemfig manual: "10 Using \chemfig in the tikzpicture environment It is possible to call the \chemfig inside a tikzpicture environment", followed by an example mixing tikz code and chemfig, so I tried something alike... Jan 26, 2022 at 3:11
  • Ah I see so it is possible to call chemfig commands in tikz enviroment.
    – Roland
    Jan 26, 2022 at 4:13
  • Why are you calling a \schemestart are you making a reaction scheme?
    – Roland
    Jan 26, 2022 at 4:38
  • See also: tex.stackexchange.com/q/577565/134144
    – leandriis
    Jan 26, 2022 at 6:28

2 Answers 2

4

Since the combination of a tikz enviroment with \schemestart and \chemove seem to cause the problem, I simply added an invisible arrow and removed your nodes (they were not necessary).

The figure is now centered and the dashed line goes from the O to H molecule.

You can adjust the angle between the two molecules as you please by changing the value in \setchemfig{arrow angle=<value>} and the distance by changing the value in \arrow{0}[,<value>].

\documentclass{article}
\usepackage{chemfig}
\usepackage{lipsum}


\begin{document}
    \lipsum[10]
    

\begin{figure}[h]
    \centering
        \setchemfig{arrow angle=-5}
        \schemestart
        \chemfig{H-@{doublet}\charge{[circle]270=\|,340=\|}{O}-[:75]H}  
        \arrow{0}[,2.5] 
        \chemfig{{@{hydrogene}H-\charge{[circle]270=\|,340=\|}{O}-[:75]H}}
        \schemestop
        \chemmove{\draw [dashed,-] (doublet.340)--(hydrogene.160);}
    \caption{Schématisation d'une liaison hydrogène dans l'eau}
    \label{fig:liaisonH}
\end{figure}


\lipsum[10]

\end{document}

enter image description here

3

you can make the job easier if you create a separate figure for the molecules and then insert the figure into the text. In this way, the overlap between figure and text will not occur.

\documentclass[margin={2mm 2mm}]{standalone}
\usepackage{chemfig}

\begin{document}

\schemestart
            \chemfig{H-\charge{344=\|, 254=\|}{O}(-[:76]H)-[:344,3,,,,dotted]H-\charge{344=\|, 254=\|}{O}(-[:76]H)}
\schemestop

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .