1

I created a lewis formula with chemfig:

enter image description here

Now I want to color only the charges like OP did in this question.

This is my code:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{verbatim}
\pagenumbering{gobble}
\usepackage{chemfig}
\usepackage[version=4]{mhchem}

\renewcommand*\printatom[1]{\sffamily{#1}}
\newcommand*\forcelen[1]{#1/\CF@atom@sep}

\begin{document}

\chemfig{\charge{90=\|,90:7pt=$\delta^-$}{N}(-[0]\charge{0:6pt=$\delta^+$}{H})(-[4]\charge{180:6pt=$\delta^+$}{H})(-[6]\charge{270:6pt=$\delta^+$}{H})}

\end{document}

I tried to use what I thought was his code but it didn't work:

\newcommand{\pol}[1]{\rlap{${}^{^{\color{red} \delta #1}}$}}

I also found this in the documentation:

\setchemfig{atom style=red}

Is there a chemfig style like "charge style" or something like that? Where can I find a list of all available chemfig styles?

1 Answer 1

0

Probably the following is closer to the expected output:

enter image description here

I modified the \pol command to yield an output similar to the code in your question. By default the output of \pol is red, but you can use its optional argument (such as \pol[blue]{+}) to locally override the color.

\documentclass{article}
\usepackage{chemfig}
\usepackage[version=4]{mhchem}

\renewcommand*\printatom[1]{\sffamily{#1}}
\newcommand*\forcelen[1]{#1/\CF@atom@sep}

\newcommand{\pol}[2][red]{$\color{#1} \delta^{#2}$}

\begin{document}
\chemfig{\charge{90=\|,90:7pt=\pol{-}}{N}(-[0]\charge{0:6pt=\pol{+}}{H})(-[4]\charge{180:6pt=\pol{+}}{H})(-[6]\charge{270:6pt=\pol[blue]{+}}{H})}
\end{document}
1
  • Thanks, that's perfect. Now I can color the negative charge blue and the positive charges red.
    – user363808
    Commented May 15, 2021 at 10:45

You must log in to answer this question.

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