错误地确定了化学无花果结构的边界,箭头位于外部区域

错误地确定了化学无花果结构的边界,箭头位于外部区域

看起来好像 Ti在确定结构\chemmove{…}的边界框(例如箭头推动机制)时,不考虑环境中设置的 Z 箭头。当箭头的控制点位于结构本身的“外部”时,这一点很明显,无论是在 还是文档中:chemfigstandalonearticle

  • standalone插图被错误裁剪:

    独立截图

\documentclass[tikz,border=5]{standalone}
\usepackage{chemfig}

\begin{document}

\schemestart
\chemfig{@{a1}A-@{b1}B}
\chemmove{
    \draw(a1)..controls +(60:5mm) and +(120:5mm)..(b1);
}
\schemestop

\end{document}
  • article课堂上,该图与一段文字重叠:

文章截图

\documentclass{article}
\usepackage{chemfig}

\begin{document}

Text text text  

\schemestart
\chemfig{@{a1}A-@{b1}B}
\chemmove{
    \draw(a1)..controls +(60:5mm) and +(120:5mm)..(b1);
}
\schemestop

Text text text  

\end{document}

有没有一种方法可以正确地确定边界,最好是自动的,而无需为每个结构手动设置边距?

答案1

这是一个原理证明(而不是全自动、超级优雅的解决方案)。问题是\chemmove使用overlay,根据定义,它会中断/丢弃边界框。但是,据我所知,没有办法注释预先存在的,tikzpicture而无需overlay

然而,我们可以做的是查看叠加图片中某些点超出边界框的程度。这些点必须由用户选择

\AddToBoundingBox{(<coordinate>)}

(是的,如果需要,可以让这个命令接受列表。)这个宏确定超调,如果有的话,会将超调报告给辅助文件,以便在下一次编译中边界框会相应增加。类似的技巧已经被使用过,例如这里这里。这是代码,里面有一些额外的注释。它可能有助于开发更优雅和自动化的解决方案。

\documentclass{article}
\usepackage{chemfig}
\usetikzlibrary{calc}
\newcounter{picid}
\makeatletter
\tikzset{every picture/.append style={execute at end picture={\stepcounter{picid}
\path (current bounding box.south west) coordinate (pic-\number\value{picid}-BL)
 (current bounding box.north east) coordinate (pic-\number\value{picid}-TR);
\ifcsname tikz@additional@bb@\romannumeral\value{picid}\endcsname
\edef\temp{\noexpand\path \csname tikz@additional@bb@\romannumeral\value{picid}\endcsname ;}%
\temp
\fi
}}}
\newcommand\AddToBoundingBox[1]{% measure the overshoot
\path let\p1=($#1-(pic-\number\value{picid}-TR)$),
\p2=($(pic-\number\value{picid}-BL)-#1$) in 
\pgfextra{%\typeout{\x1,\y1,\x2,\y2}
\edef\temp{% add coordinate outside the bounding box in case of an overshoot
\ifdim\x1>0pt
 ([xshift=\x1]current bounding box.north east)
\fi
\ifdim\y1>0pt
 ([yshift=\y1]current bounding box.north east)
\fi
\ifdim\x2>0pt
 ([xshift=-\x2]current bounding box.south west)
\fi
\ifdim\y2>0pt
 ([yshift=-\y2]current bounding box.south west)
\fi}
% test if bounding box got increased
\pgfmathtruncatemacro{\itest}{ifthenelse(\x1<=0&&\y1<=0&&\x2<=0&&\y2<=0,0,1)}
\ifnum\itest=1 % only do something if the bounding box got increased
% we need to make sure that we remember previous additions
 \ifcsname temp@tikz@additional@bb@\romannumeral\value{picid}\endcsname
 \expandafter\xdef\csname temp@tikz@additional@bb@\romannumeral\value{picid}\endcsname{\csname temp@tikz@additional@bb@\romannumeral\value{picid}\endcsname \temp}
 \else
 \expandafter\xdef\csname temp@tikz@additional@bb@\romannumeral\value{picid}\endcsname{\temp}
 \fi
 \immediate\write\@mainaux{\xdef\expandafter\string\csname tikz@additional@bb@\romannumeral\value{picid}\endcsname{\csname temp@tikz@additional@bb@\romannumeral\value{picid}\endcsname}}
\fi
};}
\makeatother
\begin{document}
\noindent
Example 1: add the point in the middle of the bounding box  

\schemestart
\chemfig{@{a1}A-@{b1}B}
\chemmove{
    \draw(a1)..controls +(60:5mm) and +(120:5mm)..(b1) coordinate[midway] (aux);
    \AddToBoundingBox{(aux)}
}
\schemestop

\noindent
Example 2: add some additional distance  (and test that adding several
coordinates works) 

\schemestart
\chemfig{@{a1}A-@{b1}B}
\chemmove{
    \draw(a1)..controls +(60:5mm) and +(120:5mm)..(b1) coordinate[midway] (aux);
    \AddToBoundingBox{([yshift=2pt]aux)}
    \AddToBoundingBox{(aux)}
}
\schemestop

\noindent
Example 3: do nothing 

\schemestart
\chemfig{@{a1}A-@{b1}B}
\chemmove{
    \draw(a1)..controls +(60:5mm) and +(120:5mm)..(b1) coordinate[midway] (aux);
    \AddToBoundingBox{(a1)}
}
\schemestop

Text text text  
\end{document}

在此处输入图片描述

相关内容