2

I'm using chemfig (perhaps improperly) for relational algebra graphs. Here, for example, is a simple one:

\documentclass{article}
\usepackage[italian]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{chemfig}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{relsize}

\newcommand{\select}{\sigma}
\newcommand{\project}{\pi}
\newcommand{\join}{\mathlarger{\mathlarger{\mathlarger{\mathlarger{\Join}}}}}

\begin{document}
    \chemfig{R-[:30]\join(-[:90]\project_{CodR,NomeR})-[:330]
        \select_{Argomento='moto'}-[:270]A}
\end{document}

It results in:

graph

I'd like to make the atoms containing \select and \project "right-aligned", so that the bond would touch the sigma and the pi. I didn't find a solution in the chemfig documentation.

If what I want is not possible with chemfig, are there viable alternatives?

EDIT: Maybe there is a way by redefining \printatom? I found an example in the docs in which it shows how to change font, so maybe it's possible to make a custom box.

  • This could help you texample.net/tikz/examples/feature/nodes-and-shapes – Sigur Jul 12 '15 at 11:47
  • @Sigur Thanks, I was aware of tikz, but it seems much more complex than chemfig for these simple graphs. I think I'll fallback on tikz if there is no way with chemfig. – rubik Jul 12 '15 at 11:49
  • are you sure that you don't want `moto' instead of 'moto'? – Sigur Jul 12 '15 at 12:08
  • @Sigur Oh right I missed that bit. I always forget that in text mode that happens. Thanks again! – rubik Jul 12 '15 at 12:27
2

The solution is simple: add | after \select:

The character “|” forces splitting of the atom when it is encountered. Thus we can write C|{(CH_3)_3} to ensure that ChemFig separates just two atoms here: “C” and “{(CH_3)_3}”.

Without \select_{Argomento='moto'} is considered one atom and the bond is centered. With | we have two atoms where the bond can go to. In this case \select is chosen. If it weren't the optional arguments of the bonds would allow to determine which atom the bond should go to.

\documentclass{article}
\usepackage[italian]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{chemfig}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{relsize}

\newcommand{\select}{\sigma}
\newcommand{\project}{\pi}
\newcommand{\join}{\mathlarger{\mathlarger{\mathlarger{\mathlarger{\Join}}}}}

\begin{document}

\chemfig{
  R-[:30]\join
  (-[:90]\project_{CodR,NomeR})
  -[:330]
  \select|_{Argomento='moto'}
  -[:270]A
}

\end{document}

enter image description here

  • @rubik, this solution is much more simpler than mine and it is the right one! – Sigur Jul 12 '15 at 12:50
  • The only advantage I see in my solution is the alignment of the structure. In my code the \Join is the center since the script text is not taking horizontal space. This could be good if using captions. – Sigur Jul 12 '15 at 12:56
  • 1
    @Sigur probably depends on the overall layout where this figure is used :) What needs more fixing is the spacing in the subscripts (I am also not sure the two primes around moto are actually wanted) – but that wasn't the question, so… – clemens Jul 12 '15 at 12:59
  • yes. I recommended the OP to accept your solution. Also I did a comparison between them. Nice! – Sigur Jul 12 '15 at 13:03
  • Ah, this is really nice. I encountered this in the documentation, but I didn't understand how it actually works and ended up discarding it. But why isn't the figure centered, even if I added \centering? If it's possible to center the figure I'll accept this answer! – rubik Jul 12 '15 at 17:21
2

Is this what you want?

\documentclass{article}
\usepackage[italian]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{chemfig}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{relsize}

\newcommand{\select}{\sigma}
\newcommand{\project}{\pi}
\newcommand{\join}{\mathlarger{\mathlarger{\mathlarger{\mathlarger{\Join}}}}}

\begin{document}
    \chemfig{R-[:30]\join(-[:90]\project_{\rlap{\scriptsize CodR,NomeR}})-[:330]
        \select_{\rlap{\scriptsize Argomento='moto'}}-[:270]A}
\end{document}

enter image description here

Edit: here is a comparison with the right solution given by @clemens. The difference will appears with we want to centre the chain.

My solution using \rlap{} makes the script 'invisible' with respect to horizontal alignment. This makes the \Join be the centre of the chain.

enter image description here

  • Wow, I'm surprised it's so simple! Yes, that's exactly what I was looking for! Never heard of \rlap before thanks! One thing: this makes the subscript text normally sized, I had to get it back to a smaller size with \scriptsize. – rubik Jul 12 '15 at 12:00
  • 1
    @rubik, well observed. I edited the post to insert \scriptsize. As you could imagine, there is also the \llap{}. – Sigur Jul 12 '15 at 12:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.