有时化学家想表示某物附着在 C 环上,但不指定其附着的确切位置,例如因为它是随机的。相反,他们会表示类似
(参见 R^1)。这也可以附着在环的中心或左下角的“芳香环”上。这可以在 中完成吗chemfig
?
答案1
(自chemfig
v1.56 以来,环的中心可以轻松地引用为节点名称。请参阅本答案末尾附近的更新。)
是的,chemfig
可以做到这一点,但需要一些技巧(或高级用法?)。
\documentclass{article}
\usepackage{chemfig}
\begin{document}
\chemfig{*6(-=-=-=)} \qquad
\chemfig{*6(-=(-[:150])-=-=)} \qquad
\chemfig{*6(-=(-[:150]-[:120]-[:120]R^1)-=-=)} \qquad
\chemfig{*6(-=(-[:150]-[:120,.5]-[:120]R^1)-=-=)} \qquad
\chemfig{*6(-=(-[:150,,,,white]-[:120,.5,,,draw=none]-[:120]R^1)-=-=)}
\begin{enumerate}
\item Start.
\item Draw a bond to center with syntax \verb|-[<angle>]|.
\item Draw two more bonds to get to the right angle, and add desired atom.
\item Adjust bond length using syntax \verb|-[<angle>,<length scale>]|.
\item Hide intermediate bonds by specifying a white drawing color,
using syntax \verb|-[<angle>,<length scale>,,,<tikz code>]|.
\end{enumerate}
\end{document}
更新
在下面的例子中,环内的弧被命名为A
,因此环的中心是(A.center)
。我不知道如何chemfig
从任意坐标开始绘制键,所以我使用insert path
。
限制:需要明确指定角度,就像36
中的一样(36:5pt)
。
\documentclass{article}
\usepackage{chemfig}
\usetikzlibrary{calc}
\begin{document}
\chemfig{%
**[,,draw=none, local bounding box=A]%
5(-----%
[,,,,{insert path={
([shift={(36:5pt)}]A.center) -- +(36:1cm) node[anchor=center, right] {X}
}}]%
)%
}
\end{document}
更新 2
使用chemfig
v1.56 (或更新版本),可以通过节点名称引用环的中心centrecycle<n>
,请参阅chemfig
手动的,第 12.6 节了解更多详情。感谢 的作者 Christian Tellechea chemfig
。
下面的示例包含两幅\chemfig
图。
- 在第一个中,以下添加了循环中心之间的绘图命令
\chemmove
,它不会扩展前一个的边界框\chemfig
并且可能会与周围的文本重叠。 - 第二个将循环中心之间的绘图命令移动到
tikz
选项execute at end picture
,以扩展边界框。
\documentclass{article}
\usepackage{chemfig}
\usepackage{lipsum}
\tikzset{
% helper style
show bounding box/.style={
execute at end picture={
\draw[blue, #1] (current bounding box.north west) rectangle (current bounding box.south east);
}
}
}
\begin{document}
\lipsum[23]
Example from \verb|chemfig| manual, sec.\@ 12.6. Note \verb|\chemmove| won't extend the bounding box.
text
\chemfig[chemfig style={show bounding box}]{*6(-=-=-=)}%
\chemmove{
\node[at=(cyclecenter1)] {.+}
node[at=(cyclecenter1), shift=(120:1.75cm)] (end) {\printatom{R^1}};
\draw[-, shorten <=.5cm] (cyclecenter1) -- (end);
}
text
Using \verb|execute at end picture|, the bounding box is correctly extended.
\tikzset{
cycle center staff/.style={
execute at end picture={
\path (cyclecenter1) node[anchor=center] {.+}
+(120:1.75cm) node[inner sep=2pt] (end) {\printatom{R^1}};
\draw (cyclecenter1) +(120:.5cm) -- (end);
}
}
}
text \chemfig[chemfig style={
cycle center staff,
show bounding box
}]{*6(-=-=-=)}
text
\lipsum[23]
\end{document}
更新 3
为了简化用户输入,\chempremove
定义了一个新命令。使用此新命令,
\chempremove{<tikz drawing code>}
\chemfig{...}
相当于
\chemfige[chemfig style={execute at end picture={<tikz drawing code>}}]{...}
全面实施:
\documentclass{article}
\usepackage{chemfig}
\usepackage{lipsum}
\usepackage{xpatch}
\tikzset{
% helper style
show bounding box/.style={
execute at end picture={
\draw[blue, #1] (current bounding box.north west) rectangle (current bounding box.south east);
}
}
}
% new command \chempremove{<tikz code executed at end picture>}
\catcode`\_=11\relax
\defKV[chemfig]{%
at end picture = \def\CF_atendpic_once{#1},
at end picture append = \CF_addtomacro\CF_atendpic_once{#1}
}
\setKVdefault[chemfig]{%
at end picture = {}
}
\newcommand{\chempremove}[1]{%
\setKV[chemfig]{at end picture append={#1}}%
\ignorespaces
}
\xpatchcmd\CF_chemfigb
{baseline,}
{baseline,%
execute at end picture={\unexpanded\expandafter{\CF_atendpic_once}},}
{}{\fail}
\xpatchcmd\CF_chemfigb
{\let\CF_flipstate\CF_zero}
{\let\CF_flipstate\CF_zero\let\CF_atendpic_once\empty}
{}{\fail}
\catcode`\_=8\relax
\begin{document}
\lipsum[23]
Example from \verb|chemfig| manual, sec.\@ 12.6. Note \verb|\chemmove| won't extend the bounding box.
\chempremove{
% show bounding box
\draw[blue] (current bounding box.north west) rectangle (current bounding box.south east);
}
text
\chemfig[chemfig style={show bounding box}]{*6(-=-=-=)}%
\chemmove{
\node[at=(cyclecenter1)] {.+}
node[at=(cyclecenter1), shift=(120:1.75cm)] (end) {\printatom{R^1}};
\draw[-, shorten <=.5cm] (cyclecenter1) -- (end);
}
text
Using \verb|\chempremove|, the bounding box is correctly extended.
\chempremove{
\path (cyclecenter1) node[anchor=center] {.+}
+(120:1.75cm) node[inner sep=2pt] (end) {\printatom{R^1}};
\draw (cyclecenter1) +(120:.5cm) -- (end);
% show bounding box
\draw[blue] (current bounding box.north west) rectangle (current bounding box.south east);
}
text \chemfig{*6(-=-=-=)} text
\lipsum[23]
\end{document}