chemfig 中的括号高度发生了变化

chemfig 中的括号高度发生了变化

我正在尝试使用 chemfig 绘制具有重复单元的聚合物。但是,我的左括号和右括号在垂直方向上移动。这是我的最小工作示例:

\documentclass[a4paper]{scrbook} \nonstopmode
\input{header}
\begin{document}
\setpolymerdelim()
\chemfig{
    H_3C-[1](-[7]-[1]O-[@{opa,.5}7]-[1]-[7]O-[@{cla,.5}1](=[2]O)(-[7]=[1]CH_2))
}
\makebraces[0pt,45pt]{\!\!\!n}{opa}{cla}
\end{document}

使用 header.tex:

\usepackage[utf8]{inputenc}
\usepackage{chemfig}

% Chemfig brackets
\newcommand\setpolymerdelim[2]{\def\delimleft{#1}\def\delimright{#2}}

\def\makebraces[#1,#2]#3#4#5{%
\edef\delimhalfdim{\the\dimexpr(#1+#2)/2}%
\edef\delimvshift{\the\dimexpr(#1-#2)/2}%
\chemmove{%
\node[at=(#4),yshift=(\delimvshift)]
{$\left\delimleft\vrule height\delimhalfdim depth\delimhalfdim
width0pt\right.$};%
\node[at=(#5),yshift=(\delimvshift)]
{$\left.\vrule height\delimhalfdim depth\delimhalfdim
width0pt\right\delimright_{\rlap{$\scriptstyle#3$}}$};}}

makebraces 和 setpolymerdelim 部分只是 chemfig 手册的复制粘贴。下面是输出的屏幕截图:

我的示例的输出。之后我添加了一条黑色基线。

答案1

您需要调整调用中的第一个参数以\makebraces将其向上移动。总括号高度是两个可选参数的总和(MWE 中为 45 pt)。保持相同的整体高度:

\documentclass[a4paper]{scrbook} \nonstopmode
\usepackage[utf8]{inputenc}
\usepackage{chemfig}

% Chemfig brackets
\newcommand\setpolymerdelim[2]{\def\delimleft{#1}\def\delimright{#2}}

\def\makebraces[#1,#2]#3#4#5{%
\edef\delimhalfdim{\the\dimexpr(#1+#2)/2}%
\edef\delimvshift{\the\dimexpr(#1-#2)/2}%
\chemmove{%
\node[at=(#4),yshift=(\delimvshift)]
{$\left\delimleft\vrule height\delimhalfdim depth\delimhalfdim
width0pt\right.$};%
\node[at=(#5),yshift=(\delimvshift)]
{$\left.\vrule height\delimhalfdim depth\delimhalfdim
width0pt\right\delimright_{\rlap{$\scriptstyle#3$}}$};}}

\begin{document}
\setpolymerdelim()
\chemfig{
    H_3C-[1](-[7]-[1]O-[@{opa,.5}7]-[1]-[7]O-[@{cla,.5}1](=[2]O)(-[7]=[1]CH_2))
}
\makebraces[20pt,25pt]{\!\!\!n}{opa}{cla}
\end{document}

产量:

移位的括号

编辑:

各个支架的位置基于传递的节点(opacla沿着键定位。由于键不对称,左支架低于右支架。如果希望支架处于相同的高度,则需要修改命令\makebraces。以下将两个支架设置为y两个点的平均值:

\documentclass[a4paper]{scrbook} \nonstopmode
\usepackage[utf8]{inputenc}
\usepackage{chemfig}
\usetikzlibrary{calc}

% Chemfig brackets
\newcommand\setpolymerdelim[2]{\def\delimleft{#1}\def\delimright{#2}}

\def\makebraces[#1,#2]#3#4#5{%
\edef\delimhalfdim{\the\dimexpr(#1+#2)/2}%
\edef\delimvshift{\the\dimexpr(#1-#2)/2}%
\chemmove{%
\path let \p1=(#4), \p2=(#5) in node[yshift=(\delimvshift)] at (\x1,0.5*\y1+0.5*\y2)
{$\left\delimleft\vrule height\delimhalfdim depth\delimhalfdim
width0pt\right.$};%
\path let \p1=(#4), \p2=(#5) in node[yshift=(\delimvshift)] at (\x2,0.5*\y1+0.5*\y2)
{$\left.\vrule height\delimhalfdim depth\delimhalfdim
width0pt\right\delimright_{\rlap{$\scriptstyle#3$}}$};}}

\begin{document}
\setpolymerdelim()
\chemfig{
    H_3C-[1](-[7]-[1]O-[@{opa,.5}7]-[1]-[7]O-[@{cla,.5}1](=[2]O)(-[7]=[1]CH_2))
}
\makebraces[20pt,25pt]{\!\!\!n}{opa}{cla}
\end{document}

在此处输入图片描述

相关内容