1

Given the following mwe (kindly provided by a contributor in this post), how would one go about implementing scaling functionality to control the size of the chemfig object?

Passing the option chemfig style={scale=0.5} does not seem to scale the chemfig object.

I suppose one decision which must be made is whether one is comfortable with scaling the entire object including characters (e.g. H, O, ...).

My guess is that a rather limited scaling which impacts the bond lengths and not the characters may be more elegant?

Of course, if one chooses to provide the \chemfiginput{} command with a representation of the compound or molecule which excludes explicit representation of C and H, the scaling may be more flexible.

% representation without comments
\begin{filecontents}{methane.tex}
H
    -[:210]
              (
        -[:210]H
              )
              (
        -[:300]H
              )
    -[:120]H
\end{filecontents}

\documentclass{article}
\usepackage{booktabs}
\usepackage{chemfig}
\usepackage[scaled]{helvet}
\usepackage{catchfile}


% sans serif font
\renewcommand\familydefault{\sfdefault} 

% define formulae
\newcommand\methane{\ensuremath{\mathrm{CH_{4}}}}

\newcommand{\chemfiginput}[2][]{%
  \CatchFileDef{\chemfiginputtemp}{#2}{\csname CF_sanitizecatcode\endcsname}%
  \expandafter\chemfigdo\expandafter{\chemfiginputtemp}{#1}%
}
\newcommand{\chemfigdo}[2]{\chemfig[#2]{#1}}

\begin{document}

\begin{tabular}[]{ll}
\toprule
\textbf{Formula} & \textbf{Structure}\\
\midrule
\methane & \chemfiginput{methane} \\
\methane & \chemfiginput[chemfig style={color=red!40!black, line width=1.5pt}]{methane} \\
\methane & \chemfig{H-[:210](-[:210]H)(-[:300]H)-[:120]H} \\
\bottomrule
\end{tabular}

\end{document}

1 Answers1

2

You can just add atom style={scale=2}, i.e. use

\chemfiginput[atom style={scale=2}]{methane}

Full example:

\begin{filecontents}{methane.tex}
H
    -[:210]
              (
        -[:210]H
              )
              (
        -[:300]H
              )
    -[:120]H
\end{filecontents}

\documentclass{article}
\usepackage{booktabs}
\usepackage{chemfig}
\usepackage[scaled]{helvet}
\usepackage{catchfile}


% sans serif font
\renewcommand\familydefault{\sfdefault} 

% define formulae
\newcommand\methane{\ensuremath{\mathrm{CH_{4}}}}

\newcommand{\chemfiginput}[2][]{%
  \CatchFileDef{\chemfiginputtemp}{#2}{\csname CF_sanitizecatcode\endcsname}%
  \expandafter\chemfigdo\expandafter{\chemfiginputtemp}{#1}%
}
\newcommand{\chemfigdo}[2]{\chemfig[#2]{#1}}

\begin{document}

\begin{tabular}[]{ll}
\toprule
\textbf{Formula} & \textbf{Structure}\\
\midrule
\methane & \chemfiginput[atom style={scale=2}]{methane} \\
\methane & \chemfiginput[chemfig style={color=red!40!black, line width=1.5pt}]{methane} \\
\methane & \chemfig{H-[:210](-[:210]H)(-[:300]H)-[:120]H} \\
\bottomrule
\end{tabular}

\end{document}

enter image description here

Or

\begin{tabular}[]{ll}
\toprule
\textbf{Formula} & \textbf{Structure}\\
\midrule
\methane & \chemfiginput[atom sep=5em,chemfig style={thick}]{methane} \\
\methane & \chemfiginput[chemfig style={color=red!40!black, line width=1.5pt}]{methane} \\
\methane & \chemfig{H-[:210](-[:210]H)(-[:300]H)-[:120]H} \\
\bottomrule
\end{tabular}

enter image description here

cgnieder
  • 66,645