1

I am using \makebox to control how atoms are printed for consistent results. I would like to print my atoms as a circle instead of a box so that all bonds at all angles will be equidistant from the boundaries of the atom. I noticed that the \charge command has an option to print charges along a circular boundary; however, there isn't a similar option for the \chemfig command. Is there a command like \makebox that produces a circular boundry or would there be another way to accomplish this goal? See the below demonstrations.

enter image description here

\documentclass[border=10pt]{standalone}
\usepackage{adjustbox}
\usepackage{chemfig}

\begin{document}
%
    \def\foreverunspace{%
      \ifnum\lastnodetype=11
        \unskip\foreverunspace
      \else
        \ifnum\lastnodetype=12
          \unkern\foreverunspace
        \else
          \ifnum\lastnodetype=13
            \unpenalty\foreverunspace
          \fi
        \fi
      \fi
    }%
%
    \renewcommand{\printatom}[1]{%
        \setbox0=\hbox{#1\foreverunspace}\ifdim\wd0=0pt% if the argument doesn't have a size
            \ensuremath{\mathrm#1}%
        \else%
            \makebox(2.5ex,2.5ex){\ensuremath{\mathrm#1}}% use makebox for atoms
        \fi%
    }%
%
    \setchemfig{%
        % circle=true% not a defined key!
        fixed length=false%
    }%
    \noindent%
    \chemfig{%
        C%
            (-[:0]F)%
            (-[:45]F)%
    }%
%
    \setchemfig{debug=true}%
    \chemfig{%
        C%
            (-[:0]F)%
            (-[:45]F)%
    }%
%
    \hspace{2ex}%
%
    \setchemfig{debug=false}%
    \chemfig{\charge{[overlay=false]0=\:,45=\:}{O}}\hspace{2ex}%
%
    \setcharge{debug=true}%
    \chemfig{\charge{[overlay=false]0=\:,45=\:}{O}}\hspace{2ex}%
%
    \setcharge{debug=false,circle=true}%
    \chemfig{\charge{[overlay=false]0=\:,45=\:}{O}}\hspace{3ex}%
%
    \setcharge{debug=true}%
    \chemfig{\charge{[overlay=false]0=\:,45=\:}{O}}
%
\end{document}
4
  • see the answer at tex.stackexchange.com/questions/216353/…
    – CrocoDuck
    Aug 23, 2022 at 23:09
  • @EdsonMarcon That isn't related to my question. I need each atom to take up the space of a circle rather than a circle being drawn around the atom.
    – Jon
    Aug 23, 2022 at 23:51
  • 1
    @Jon, do you need graphical elements and outputs different from what the example and your question indicate? Put it differently, why do you need the package chemfig? Would a straight answer not using the package interest you?
    – Daniel N
    Aug 24, 2022 at 7:35
  • @DanielN Chemfig has a lot of things set up how I want them (it will save me time), but there are a few things that I wish it had to make it nearly perfect for how I want to use it. If there is another package or a method that would be able to do what I want, I am interested.
    – Jon
    Aug 24, 2022 at 15:12

1 Answer 1

1

enter image description here

I defined two pic objects. One has the border always drawn and is simpler. It is named atom and has two arguments: its name and the list of angles of the small bullets, if any. The other one, atom o depends on three arguments; its third defines the opacity of the border. The top element in the figure is given by atom o.

So what do you think? Note that other decorations may be similarly added.

The code

\tikzset{%
  pics/atom/.style 2 args={%  name, list of angles (charges?)
    code={%
      \path (0, 0)
      node[circle, draw,
      minimum width=6.6ex, minimum height=6.6ex,
      inner sep=1ex, outer sep=1ex,
      text=black] (#1) {$#1$};
      \foreach \i in {#2}{%
        \filldraw[black] (\i: 3.3ex) circle (.25ex);
      }
    }
  },  
  pics/atom o/.style n args={3}{%  name, list of angles, border's opacity
    code={%
      \path (0, 0)
      node[circle, draw, opacity=#3, text opacity=1,
      minimum width=6.6ex, minimum height=6.6ex,
      inner sep=1ex, outer sep=1ex,
      text=black] (#1) {$#1$};
      \foreach \i in {#2}{%
        \filldraw[black] (\i: 3.3ex) circle (.25ex);
      }
    }
  }
}

\begin{tikzpicture}
  \path (0, 0) pic {atom={F}{0, 30}};
  \path (2, 0) pic[red] {atom={He}{90}};
  \path (F) edge[-] (He);

  \path (2, 2) pic[blue] {atom o={O}{80, 110, 180}{.2}};
\end{tikzpicture}

\end{document}
1
  • Thank you, it's in the spirit of what I am looking for. If I choose to go that route, this should help me get started.
    – Jon
    Aug 24, 2022 at 20:04

You must log in to answer this question.

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