3

I want to show three different molecules on a beamer slide. The slide contains a tikzpicture (for positioning and uncovering together with the other elements), three nodes contain one molecule each.

The compounds have different sizes in terms of atoms and bonds, but I want them to be scaled the same way. If I use default settings, they are way too large. But I cannot come up with a solution to make them smaller that looks good.

I tried:

  • Scaling them with the scale argument of chemfig. The font gets very tiny and you can hardly detect double bonds or stereochemistry anymore.
  • Using setatomsep. If I use a small enough value, only the ring systems of the smallest molecule are visible. The other bonds vanish completely, and in the largest molecule, everything gets messed up.
  • Using setatomsep together with scalebox. This gets close to what I want. The smallest molecule looks good, the one in the middle ok (I know that it will be hard to make it look really good in that scale, given the stereochemistry). But the last molecule on the right looks strange: all horizontal bonds (i.e., all with an angle of 0) are too short.

Is there any better way to put Chemfigs in tikz nodes and scale them appropriately?

\documentclass{beamer}

\usepackage{chemfig}
\usepackage{tikz}

\newcommand{\ass}[1][]{\chemfig[][#1]{[:-30]O=([:30]-OH)-[:-90]*6(-=-=-([:30]-O-[:-30]([:-90]=O)-CH_3)=)}}
\newcommand{\lov}[1][]{\chemfig[][#1]{[:-30]H_3C-[:30]-(<:[:110]H)(<[:-90]H_3C)-[:30]([:90]=O)-O>:[:-90](<[:145]H)% left chain
    *6(--(<:[:210]H_3C)(<[:250]H)-=(*6(-=-(<:[:-20]H)(<[:40]CH_3)-(% double ring system part 1
    (<:[:30]H)<-[:30]-(<[:-30]H)*6(-O-(=O)--(<:[:-150]H)(<[:130]HO)--)% upper ring and linker
    )-))-(<[:90]H)-)% double ring system part 2
}}
\newcommand{\nel}[1][]{\chemfig[][#1]{[:150]*6(=-[,1.5]=-=-)-[:0]S*6(--% left ring and linker
    (<NH*6(-(=O)-*6(-=-=(-OH)-=)--))% lower ring and linker
    -(--[:60]N*6(-(<([:-120]=O)-[:0]\chemabove{N}{H}-([:-150]-)([:30]-)-)--*6(-----)(<:[:0]H)-(<:[:180]H)--))<:HO)% upper ring system, linker and chain
}}

\tikzstyle{compound} = [draw, rounded corners, text centered, node distance=.3\textheight, text width=.2\textwidth, minimum height=.2\textheight]

\begin{document}

    \begin{frame}{Default}
        \begin{tikzpicture}
            \node[compound] (cpd1) {\ass};
            \node[compound, right of=cpd1] (cpd2) {\lov};
            \node[compound, right of=cpd2] (cpd3) {\nel};
        \end{tikzpicture}
    \end{frame}

    \begin{frame}{Scaling in Chemfig}
        \begin{tikzpicture}
            \node[compound] (cpd1) {\ass[scale=.25]};
            \node[compound, right of=cpd1] (cpd2) {\lov[scale=.25]};
            \node[compound, right of=cpd2] (cpd3) {\nel[scale=.25]};
        \end{tikzpicture}
    \end{frame}

    \begin{frame}{Scaling using \textbackslash setatomsep}
        \begin{tikzpicture}
            \setatomsep{5pt}
            \node[compound] (cpd1) {\tiny \ass};
            \node[compound, right of=cpd1] (cpd2) {\tiny \lov};
            \node[compound, right of=cpd2] (cpd3) {\tiny \nel};
        \end{tikzpicture}
    \end{frame}

    \begin{frame}{Scaling using \textbackslash setatomsep and \textbackslash scalebox}
        \begin{tikzpicture}
            \setatomsep{15pt}
            \node[compound] (cpd1) {\scalebox{.3}{\ass}};
            \node[compound, right of=cpd1] (cpd2) {\scalebox{.3}{\lov}};
            \node[compound, right of=cpd2] (cpd3) {\scalebox{.3}{\nel}};
        \end{tikzpicture}
    \end{frame}

\end{document}

  • The scaling via the optional argument of \chemfig is working as your picture shows. But since you restrict the compound nodes to a fixed width the sometimes still don't fit. I'd be less restrictive there… – clemens Sep 18 '15 at 10:19
2

You can fit this three figures with \scalebox just play around minimum height, minimum width and node distance.

We use \centerline to center figures which exceed textwidth.

\documentclass{beamer}

\usepackage{chemfig}
\usepackage{tikz}

\newcommand{\ass}[1][]{\chemfig[][#1]{[:-30]O=([:30]-OH)-[:-90]*6(-=-=-([:30]-O-[:-30]([:-90]=O)-CH_3)=)}}
\newcommand{\lov}[1][]{\chemfig[][#1]{[:-30]H_3C-[:30]-(<:[:110]H)(<[:-90]H_3C)-[:30]([:90]=O)-O>:[:-90](<[:145]H)% left chain
    *6(--(<:[:210]H_3C)(<[:250]H)-=(*6(-=-(<:[:-20]H)(<[:40]CH_3)-(% double ring system part 1
    (<:[:30]H)<-[:30]-(<[:-30]H)*6(-O-(=O)--(<:[:-150]H)(<[:130]HO)--)% upper ring and linker
    )-))-(<[:90]H)-)% double ring system part 2
}}
\newcommand{\nel}[1][]{\chemfig[][#1]{[:150]*6(=-[,1.5]=-=-)-[:0]S*6(--% left ring and linker
    (<NH*6(-(=O)-*6(-=-=(-OH)-=)--))% lower ring and linker
    -(--[:60]N*6(-(<([:-120]=O)-[:0]\chemabove{N}{H}-([:-150]-)([:30]-)-)--*6(-----)(<:[:0]H)-(<:[:180]H)--))<:HO)% upper ring system, linker and chain
}}

\tikzstyle{compound} = [draw, rounded corners, text centered, node distance=.38\textwidth, minimum height=.4\textheight, minimum width=0.35\textwidth ]

\begin{document}

    \begin{frame}{Scaling using \textbackslash scalebox}
    \centerline{%
       \begin{tikzpicture}
            \node[compound] (cpd1) {\scalebox{.3}{\ass}};
            \node[compound, right of=cpd1] (cpd2) {\scalebox{.3}{\lov}};
            \node[compound, right of=cpd2] (cpd3) {\scalebox{.3}{\nel}};
        \end{tikzpicture}
    }
    \end{frame}

\end{document}

enter image description here

0

Using your answer, salim bou, here is what I found:

  • I can actually omit setatomsep if I use scalebox, as you suggested.
  • What messes up my molecules is that I used text width instead of minimum width.

The second point seems quite strange to me. In the code below, the first slide looks perfectly fine, while in the second one, the boxes overlap (which is probably just a consequence of inner separations and so on), and the molecule bonds are drawn incorrectly.

\documentclass{beamer}

\usepackage{chemfig}
\usepackage{tikz}

\let\Tiny\tiny

\newcommand{\ass}[1][]{\chemfig[][#1]{[:-30]O=([:30]-OH)-[:-90]*6(-=-=-([:30]-O-[:-30]([:-90]=O)-CH_3)=)}}
\newcommand{\lov}[1][]{\chemfig[][#1]{[:-30]H_3C-[:30]-(<:[:110]H)(<[:-90]H_3C)-[:30]([:90]=O)-O>:[:-90](<[:145]H)% left chain
    *6(--(<:[:210]H_3C)(<[:250]H)-=(*6(-=-(<:[:-20]H)(<[:40]CH_3)-(% double ring system part 1
    (<:[:30]H)<-[:30]-(<[:-30]H)*6(-O-(=O)--(<:[:-150]H)(<[:130]HO)--)% upper ring and linker
    )-))-(<[:90]H)-)% double ring system part 2
}}
\newcommand{\nel}[1][]{\chemfig[][#1]{[:150]*6(=-[,1.5]=-=-)-[:0]S*6(--% left ring and linker
    (<NH*6(-(=O)-*6(-=-=(-OH)-=)--))% lower ring and linker
    -(--[:60]N*6(-(<([:-120]=O)-[:0]\chemabove{N}{H}-([:-150]-)([:30]-)-)--*6(-----)(<:[:0]H)-(<:[:180]H)--))<:HO)% upper ring system, linker and chain
}}

\begin{document}

    \begin{frame}{Scaling using \textbackslash scalebox}
        \tikzstyle{compound} = [draw, rounded corners, text centered, node distance=.3\textwidth, minimum height=.3\textwidth, minimum width=.3\textwidth ]
        \begin{tikzpicture}
            \node[compound] (cpd1) {\scalebox{.25}{\ass}};
            \node[compound, right of=cpd1] (cpd2) {\scalebox{.25}{\lov}};
            \node[compound, right of=cpd2] (cpd3) {\scalebox{.25}{\nel}};
        \end{tikzpicture}
    \end{frame}

    \begin{frame}{Scaling using \textbackslash scalebox}
        \tikzstyle{compound} = [draw, rounded corners, text centered, node distance=.3\textwidth, minimum height=.3\textwidth, text width=.3\textwidth ]
        \begin{tikzpicture}
            \node[compound] (cpd1) {\scalebox{.25}{\ass}};
            \node[compound, right of=cpd1] (cpd2) {\scalebox{.25}{\lov}};
            \node[compound, right of=cpd2] (cpd3) {\scalebox{.25}{\nel}};
        \end{tikzpicture}
    \end{frame}

\end{document}

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.