2
\documentclass{scrartcl}
\usepackage{chemfig}
\begin{document}
    \par ggg jjj ggg jjj ggg jjj ggg jjj
    \par
    \schemestart
    \chemfig{A-\charge{90:5pt=\textcolor{red}{+}}{B}-C}
    \schemestop
\end{document}

enter image description here

How do I separate the chemical formula from surrounding text?

I'm not looking for a \vspace{} answer, if I have to choose a suitable measure manually for every such instance. I'd like it to be automated.

Using \Charge instead of \charge disturbs the vertical alignment of A, B, C.

Putting the scheme into a minipage environment did not help.

2
  • Unrelated, but why do you start your line with \par? You should rather end the lines with \par or just put one empty line which means the same. Dec 10, 2023 at 0:36
  • End of line, beginning of line: is there a great difference? And I don't mind the \par, it feels to me like the Python saying "Explicit is better than implicit."
    – Wolfram
    Dec 10, 2023 at 1:20

3 Answers 3

3

A way to bypass overlay with \tikzmarknode

\documentclass{scrartcl}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\usepackage{chemfig}
\begin{document}
    \par ggg jjj ggg jjj ggg jjj ggg jjj
    \par
    \schemestart
    \chemfig{A-\charge{90:5pt=\subnode{a1}{\textcolor{red}{+}}}{B}-C}
    \tikz[remember picture]\path (a1.north) ++(0,2pt);
    \schemestop
\end{document}

enter image description here

1
  • Interesting method. But for me it doesn't work. My compilation has the plus sign in the text, and with every compilation it says „LaTeX Warning: Label(s) may have changed. Rerun to get cross-references right."
    – Wolfram
    Dec 10, 2023 at 1:36
2

The chemfig manual (on page 32) suggests something like the following which, however, extends the bond between the atoms next to the charged one:

\documentclass{scrartcl}
\usepackage{chemfig}
\definesubmol\X{\vphantom{X}}

\begin{document}
    ggg jjj ggg jjj ggg jjj ggg jjj

    \chemfig[anchor=atom.base]{A-!\X|\Charge{90:5pt[red]=+}{B}|!\X-C}

    ggg jjj ggg jjj ggg jjj ggg jjj
\end{document}

enter image description here

First, we use the \Charge command to add the plus sign. The \Charge command, unlike the \charge command, will not print the charge as overlay. Then, we define a submol \X that is essentially a box of zero width and of the height of the letter X. We append this "zero-width atom" to the left and right of the actual (charged) atom using !\X. We then need to split the atoms using |, so that the "molecule" now becomes !\X|\Charge{...}|!\X. This way, when chemfig connects other atoms to this molecule, it sees just an atom with the height of X and hence aligns everything vertically correctly.

--

If you want the bonds to have the original length, you can adjust this using the second argument of the bond options:

\documentclass{scrartcl}
\usepackage{chemfig}
\definesubmol\X{\vphantom{X}}

\begin{document}
    ggg jjj ggg jjj ggg jjj ggg jjj

    \chemfig[anchor=atom.base]{A-[,.87]!\X|\Charge{90:5pt[red]=+}{B}|!\X-[,.87]C}

    ggg jjj ggg jjj ggg jjj ggg jjj

    \chemfig[anchor=atom.base]{A-\charge{90:5pt[red]=+}{B}-C}

    ggg jjj ggg jjj ggg jjj ggg jjj
\end{document}

enter image description here

2
  • Thank you. Good explanation! I didn't understand it so clearly, when I skimmed that section in the manual. Just not quite satisfied with the change in bond length.
    – Wolfram
    Dec 10, 2023 at 0:39
  • @Wolfram It is in fact not that easy to understand. You can adjust the bond length manually, but it still feels a bit hacky. Dec 10, 2023 at 0:46
1

if you use \begin{center} \end{center} for the ChemFig figures there will be no overlap.

   \documentclass{scrartcl}
\usepackage{chemfig}
\begin{document}
    \par ggg jjj ggg jjj ggg jjj ggg jjj
\begin{center}
    \schemestart
    \chemfig{A-\charge{90:5pt=\textcolor{red}{+}}{B}-C}
    \schemestop
\end{center}
\end{document}

enter image description here

5
  • That is like a vspace{} solution, because the center environment adds some space. With \charge{90:12pt the plus will be again in the text above the formula.
    – Wolfram
    Dec 9, 2023 at 23:31
  • 2
    When Chemfig adds a sign using \charge, the sign may even be outside the figure if you are creating a "standalone" document. One possibility is to create images with Chemfig "standalone" format and insert them into the text as PDF figures.
    – CrocoDuck
    Dec 9, 2023 at 23:42
  • Interesting! Thank you. It sounds possible (maybe cropping the image with pdfcrop), but quite complicated. Is there no possibility to do that within LaTeX?
    – Wolfram
    Dec 9, 2023 at 23:56
  • Isn't necessary "crop", use \documentclass{standalone} \usepackage{chemfig} \begin{document} \chemfig{XXXXX} \end{document} and use latexpdf to rum. you will create a PDF picture of the molecule.
    – CrocoDuck
    Dec 10, 2023 at 0:01
  • pdflatex, not "latexpdf", sorry
    – CrocoDuck
    Dec 10, 2023 at 0:12

You must log in to answer this question.

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