3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

LaTexAdvent Calendar 2022

Day 25

Chemfigを用いたメタンの立体構造の描画

Last updated at Posted at 2022-11-14

プリアンブルに以下のものを追加する.
なお,\usepackage{miscchemsym}は不要であるかもしれません.

\usepackage{booktabs}
\usepackage{miscchemsym}
\usepackage{chemfig}
\usepackage{filecontents}
\usepackage{tikz}
\usepackage{catchfile}

% chemfigdo
\newcommand{\chemfigdo}[2]{\chemfig[#2]{#1}}%

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

% create new command for tikzpicture call
\newcommand\callchemfigsymbol[1]{%
  \chemfiginput[
      atom style={scale=\chemfigscale},
      atom sep=\chemfigatomsep,
      chemfig style={
        baseline=(current bounding box.center),
        color=\chemfigcolor,
        line width=\chemfiglinewidth
      }
    ]{#1}%
}

% define the atom sep
\newlength{\chemfigatomsep}%
\setlength{\chemfigatomsep}{2.75em}%

% define the line width
\newlength{\chemfiglinewidth}%
\setlength{\chemfiglinewidth}{1pt}%

% define the scale
\def\chemfigscale{1.8}
% define the color
\def\chemfigcolor{black!40!black}

% define separation length
\setlength{\defaultaddspace}{25pt}

ここではメタンの構造のソースコードを./source/sample.texにtexファイルとして作成する方法を示す.
基本的なコマンドの使用方法は通常のchemfigと同様である.

\begin{filecontents}{./source/sample.tex}
           H
     -[:270]C
              (
        -[:200]H
              )
              (
         <[:310]H
              )
    <:[:350]
\end{filecontents}

本文中で図を入れたい場所に埋め込む際は次のようなコードを用いればよい.

\begin{figure}[h]
	\centering
	\callchemfigsymbol{./source/sample.tex}
	\caption{sample}
	\label{fig:sample}
\end{figure}

実際に描画されたメタンの構造

スクリーンショット 2022-11-14 20.57.51.png

正式な立体的表記への適用

また,

\begin{filecontents}{./source/sample.tex}
           H
     -[:270]C
           (-[:200]H)
         (-[:310,,,,line width=3.5pt]H)
    -[:350,,,,line width=3.5pt,dash pattern=on 1pt off 2pt]H
\end{filecontents}

とすると,
スクリーンショット 2023-02-19 11.09.55.png
のように描ける.

参考文献

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?