3

In ChemFig, the "bond join=true" option does not work with "cram" bonds (see A, it is zoomed at join).

It is possible to increase the length of the bond with the "shorten" option, but the joint still has a difference in height (see B)

Is there any option/command in tikz that can be used in the bond options to shift up a bond at a height "H" (see B)?

\documentclass[12pt,border=2mm]{standalone}
\usepackage{chemfig}
\renewcommand*\printatom[1]{\ensuremath{\mathsf{#1}}}
\begin{document}
\setchemfig{bond offset =1pt,bond join=true,atom sep =2em,cram width =3pt,cram dash width =0.4pt,cram dash sep =0.4pt}
    \chemfig{<[:300]-[0,,,,line width = 3pt]>[:60]}
\end{document}

enter image description here

5
  • 1
    What about line cap=round? Not a "shift" solution though ... Nov 29, 2023 at 18:08
  • It wasn't bad, after adjusting the bond length with "shorten". Thanks
    – CrocoDuck
    Nov 29, 2023 at 18:16
  • Another idea: use a decoration =D It seems that the line is not a to-path, so you can't easily shift it by replacement. Nov 29, 2023 at 18:28
  • Is it possible to change the size of the round?
    – CrocoDuck
    Nov 29, 2023 at 18:34
  • I think you can't change the roundness of line cap=round. But maybe go with arrow heads? You could probably use Triangle[] from the arrows.meta library. Nov 29, 2023 at 18:46

3 Answers 3

3

I think, shifting the path is not that simple. It seems that the path drawn by chemfig is not a to-path, so replacement is not feasable using the to path key for example.

But what about these two ideas:

  1. Use line cap=round.
  2. Use Triangle Cap as arrow tip (via arrows.meta).

Another, probably somewhat too complicated solution could be to use a decoration to draw a shifted path.

\documentclass[border=10pt]{standalone}
\usepackage{chemfig}

\usetikzlibrary{arrows.meta}
\tikzset{
    sharp caps/.style={
        {Triangle Cap[length=0.8pt]}-{Triangle Cap[length=0.8pt]}, 
        shorten >=-1.9pt, 
        shorten <=-1.9pt
    }
}

\begin{document}
\setchemfig{
    bond offset=1pt,
    bond join=true,
    atom sep=2em,
    cram width=3pt,
    cram dash width=0.4pt,
    cram dash sep=0.4pt
}
    \chemfig{<[:300]-[0,,,,line width=3pt, line cap=round]>[:60]}
    \chemfig{<[:300]-[0,,,,line width=3pt, sharp caps]>[:60]}
\end{document}

enter image description here

Zoomed in:

enter image description here

Well, almost ...

1
  • The solution using "caps" works well for angles of 60 degrees, but you need to adjust the parameters to use other angles. This gets complicated for drawing large molecules
    – CrocoDuck
    Nov 29, 2023 at 19:33
3

With a little geometry we can fill the gap ...(complicated)

\documentclass[12pt,border=2mm]{standalone}
\usepackage{chemfig}
\begin{document}
    \setchemfig{atom sep=2em,cram width=3pt} % 2em=24pt
    \chemfig{<[@{A1,1}:300]-[0,,,,line width=3pt]>[@{A2,0}:60]}
    \chemmove{
        \pgfmathsetmacro{\tang}{\fpeval{atand(1.5/24)}} % \tang is the half angle of the sides of the cram bond
        \path (A1) ++(-90:1.5pt) coordinate (B1);
        \path (A1) ++(210:1.7pt) coordinate (C1);
        \path (C1) ++(300-\tang:\fpeval{0.65/cosd(300-\tang-270)}pt) coordinate (D1);
        \fill[red] (A1) -- (C1) -- (D1) -- ([xshift=1pt]B1) -- cycle; % xshift eliminates the artefact
        \path (A2) ++(-90:1.5pt) coordinate (B2);
        \path (A2) ++(-30:1.7pt) coordinate (C2);
        \path (C2) ++(-120+\tang:\fpeval{0.65/cosd(300-\tang-270)}pt) coordinate (D2);
        \fill[red] (A2) -- (C2) -- (D2) -- ([xshift=-1pt]B2) -- cycle;
    }
\end{document}

enter image description here

Edit

Filling the gap with a pic...

cramgap={cram width/pt}{length of the cram bond/pt}{bonds angle}

\documentclass[12pt,border=2mm]{standalone}
\usepackage{tikz}
\tikzset{pics/cramgap/.style n args={3}{code={%
    \pgfmathsetmacro{\tang}{\fpeval{atand((#1/2)/#2)}}
    \path (0,0) coordinate (cgO);
    \path (cgO) ++(-90:\fpeval{(0.4+#1)/2}pt) coordinate (cgA);
    \path (cgO) ++(\fpeval{90+#3}:\fpeval{(0.4+#1)/2}pt) coordinate (cgB);
    \path (cgB) ++(\fpeval{180+#3-\tang}:\fpeval{(0.2+#1/2)*(1-cosd(180-#3))/cosd(-90+#3-\tang)}pt) coordinate (cgX);
    \fill[red] (cgO) -- (cgB) -- (cgX) -- ([xshift=\fpeval{#3>0?1:-1}pt]cgA) -- cycle;
}}}
\usepackage{chemfig}
\begin{document}
    \setchemfig{atom sep=24pt,cram width=2.6pt} % 2em=24pt
    \chemfig{<[@{A1,1}:310]-[:0,,,,line width=3pt]>[@{A2,0}:40]} % line width=0.4pt + cram width
    \chemmove{\path (A1) pic{cramgap={2.6}{24}{130}};
        \path (A2) pic{cramgap={2.6}{24}{-140}};}
    
    \chemfig{<[@{A1,1}:330]-[:20,,,,line width=3pt]>[@{A2,0}:60]}
    \chemmove{\path (A1) pic[rotate=20]{cramgap={2.6}{24}{130}};
        \path (A2) pic[rotate=20]{cramgap={2.6}{24}{-140}};}
\end{document}

enter image description here

4
  • yes, it is possible, but complicated... This whole code could be avoided if it were possible to move the horizontal bond bar a little upwards. From what I understand, this is not possible because we do not have the starting and ending points of the bond.
    – CrocoDuck
    Nov 29, 2023 at 23:19
  • Would it be possible to create a key which would allow to use this as option to the \chemfig command? Nov 30, 2023 at 10:00
  • @Jasper Habicht It probably is possible but I can't do it.
    – polyn
    Nov 30, 2023 at 10:17
  • I managed to get it working for the first point, but it is difficult for the second, as the coordinate is defined only later. Nov 30, 2023 at 10:25
2

I created a way to shift up the link, but many may find it a bad solution.

One problem was not knowing the starting and ending points of the bond. Then I marked these points with "@{x}", a ChemFig feature to mark positions in molecules.

I made the bond invisible using [,,,,draw=none]

Then, using \chemmove, I shifted up the start and end points using "\node", and created a straight line to replace the bond using "\draw".

Well, technically this isn't a "chemfig bond" (-[,<length.,,,,,,]), but it uses a lot of what ChemFig already uses to build molecules and is easy to tweak the parameters.

\documentclass[12pt,border=2mm]{standalone}
\usepackage{chemfig}
\begin{document}
\setchemfig{bond offset =0.5pt,bond join=true,atom sep =2em,cram width =3pt,cram dash width =0.2pt,cram dash sep =0.4pt}
\schemestart
    \chemfig{<[:300]@{a}-[0,,,,draw=none]@{b}>[:60]}
\chemmove{
    \node[at=(a),yshift=.57pt](a){};
    \node[at=(b),yshift=.57pt](b){};
    \draw[-,line width=3pt,shorten <=-1.2pt,shorten >=-1.2pt](a)--(b);}
\schemestop
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .