4

I have a problem aligning atoms in chemfig when one of the atoms has a descender. The solution proposed in the manual is not really good, because it changes the position of bonds. Consider the test case:

\documentclass{article}
\usepackage{tikz}
\usepackage{chemfig}
\begin{document}

\fbox{\chemfig{A-X-M} \chemfig{A-X-Mg}}

\fbox{\chemfig{A-X-M} \chemfig{{A\strut}-{X\strut}-Mg}}

\end{document}

which gives:

enter image description here

In the top row, the second formula has Mg too high. When adding the \strut (or \vphantom) to the other atoms, the bond lines are then too low, which is especially bad if you are displaying different formulas side by side, as in the example.

Is there any way I can move the Mg label down or make the descender invisible to \chemfig?

6
  • This is addressed in part III section 4 Vertical alignment of the chemfig manual.
    – cgnieder
    Commented Nov 7, 2013 at 10:00
  • @cgnieder And the suggested workaround is exactly what I described, and I don't find the solution entirely satisfactory. Unless I'm missing something...
    – Jellby
    Commented Nov 7, 2013 at 10:13
  • 2
    Maybe \chemfig{A-X-\smash{\printatom{Mg}}}?
    – cgnieder
    Commented Nov 7, 2013 at 10:36
  • @cgnieder That seems to do it. I just need to manually offset any bond arriving at the bottom of Mg, but I don't mind doing that in my current document.
    – Jellby
    Commented Nov 7, 2013 at 10:59
  • @cgnieder Possibly better \smash[b]{\printatom{Mg}} (requires amsmath).
    – egreg
    Commented Nov 7, 2013 at 11:58

1 Answer 1

4

\smash or (maybe even better) amsmath's \smash[b] can help here \chemfig{A-X-\smash[b]{\printatom{Mg}}}. For the sake of not having to type \smash and \printatom I define a \smashatom below:

\documentclass{article}
\usepackage{chemfig}
\usepackage{amsmath}
\newcommand*\smashatom[2][]{%
  \if\relax\detokenize{#1}\relax
    \smash{\printatom{#2}}%
  \else
    \smash[#1]{\printatom{#2}}%
  \fi
}

\begin{document}

\fbox{\chemfig{A-X-M} \chemfig{A-X-Mg}}

\fbox{\chemfig{A-X-M} \chemfig{{A\strut}-{X\strut}-Mg}}

\fbox{\chemfig{A-X-M} \chemfig{A-X-\smashatom[b]{Mg}}}

\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 .