tikz.dev / chemfig Manual

chemfig

Operation of chemfig

13 Rings

The preceding example shows how to draw a regular polygon, but the method used is tedious because the angles depend on the number of sides of the polygon.

13.1 Syntax

chemfig can easily draw regular polygons. The idea is to attach a ring to an ⟨atom⟩ outside the ring with this syntax:

⟨atom⟩*⟨n⟩(⟨code⟩)

⟨n⟩ is the number of sides of the polygon and the ⟨code⟩ describes the bonds and groups of atoms which make up its edges and vertices. This code must begin with a bond because the atom is outside the ring.

Here is a 5-ring, attached to the atom “A”:

Compiled output

5-ring
\chemfig{A*5(-B=C-D-E=)}

A ring can also be drawn with one, several, or all the groups of atoms empty, as is the case for diagrams outside rings:

Compiled output

5-ring with empty groups
\chemfig{*5(-=--=)}

A ring can be incomplete:

Compiled output

Incomplete 5-ring
\chemfig{*5(-B=C-D)}

If a ring has a code which contains too many bonds and atom groups for the given number of vertices, all the bonds and groups over the maximum allowed are ignored:

Compiled output

Truncated 5-ring
\chemfig{A*5(-B=C-D-E=F-G=H-I)}

It is possible to draw a circle or an arc in the inside of a ring. To do so, the following syntax is used:

⟨atom⟩**[⟨angle 1⟩,⟨angle 2⟩,⟨tikz⟩]⟨n⟩(⟨code⟩)

where each field of the optional argument takes its default value if it is empty:

  • ⟨angle 1⟩ and ⟨angle 2⟩ are the absolute angles of the start and finish of the arc. These default to 0° and 360° respectively so that a circle is drawn by default;

  • ⟨tikz⟩ is the code that will be passed to TikZ for drawing the arc.

Compiled output

Rings and arcs
\chemfig{**6(------)}\quad
\chemfig{**[30,330]5(-----)}\quad
\chemfig{**[0,270,dash pattern=on 2pt off 2pt]4(----)}
13.2 Angular position
13.2.1 At the start

As can be seen in the examples above, the rule is that the attachment atom “A” is always at the south-west of the ring. Furthermore, the ring is always constructed counterclockwise, and the last bond descends vertically onto the attachment atom:

Compiled output

Angular position of rings
\chemfig{A*4(-B-C-D-)}\qquad\chemfig{A*6(------)}

If this angular position is not convenient, it is possible to specify another angle using the optional argument at the beginning of the molecule. Here is a 6-cycle which has been rotated by \(+30\degres\), by \(-30\degres\), and lastly by \(+60\degres\):

Compiled output

Rotation of rings
\chemfig{[:30]A*6(------)}\qquad
\chemfig{[:-30]A*6(------)}\qquad
\chemfig{[:60]A*6(------)}
13.2.2 After a bond

When a ring does not begin a molecule and one or more bonds have already been drawn, the default angular position changes: the ring is drawn is such a way that the bond ending on the attachment atom bisects the angle formed by the first and last sides of the ring.

Here is a simple case:

Compiled output

Bond ending on a ring
\chemfig{A-B*5(-C-D-E-F-)}

The rule remains valid, whatever the angle of the preceding bond:

Compiled output

Bonds ending on a ring
\chemfig{A-[:25]B*4(----)}\vskip5pt
\chemfig{A=[:-30]*6(=-=-=-)}
13.3 Branches on a ring

To have branches attached to the vertices of a ring, we use the syntax we have already seen:

⟨atom⟩(⟨code⟩)

where the ⟨code⟩ is that of the sub-molecule and the ⟨atom⟩ is at the vertex. Unique to rings, the default angle of the sub-molecule is not 0° but is calculated so that it will bisect the sides leaving the vertex:

Compiled output

Branch on a ring
\chemfig{X*6(-=-(-A-B=C)=-=-)}

A sub-molecule can be attached to the first vertex of a ring, just like the other vertices:

Compiled output

Ring and branches
\chemfig{*5((-A=B-C)-(-D-E)-(=)-(-F)-(-G=)-)}

If one wants the bond leaving a vertex not to be the bisector of its sides, one can tinker with the optional global parameter or the optional bond parameter:

Compiled output

Branches at specified angles
\chemfig{*5(---([:90]-A-B)--)}\qquad
\chemfig{*5(---(-[:90]A-B)--)}\qquad
\chemfig{*5(---([::+0]-A-B)--)}

It is worth noting that in the third example, where a relative angle of 0° was given, the bonds of the branch are drawn in line with the preceding bond in the ring. This is the rule on section 5.3 which specified that the reference angle was that of the bond last drawn.

We can now connect together rings with bonds:

Compiled output

Connected rings
\chemfig{*6(--(-*5(----(-*4(----))-))----)}
13.4 Nested rings

To “glue” two rings together, the syntax is only slightly different: the vertex is specified where the other ring is going to start. Simply follow this vertex by the usual syntax for a ring. Here for example is a 5-ring which is attached to the second vertex of a 6-ring:

Compiled output

Nested rings
\chemfig{A*6(-B*5(----)=-=-=)}

Note that the ring which is going to be attached to the main ring has an angular position such that two of the rings’ sides coincide. In addition, the 5-ring has only four bonds “----”. In effect, the fifth will be useless because it is the second side of the 6-ring, which has already been drawn.

It is quite possible to glue multiple rings together:

Compiled output

Multiple nested rings
\chemfig{*5(--*6(-*4(-*5(----)--)----)---)}

There is a case where a trick must be used. It can be seen in this example that the fourth side of the second 5-ring just passes through the center of atom “E”.

Compiled output

Flawed drawing
\chemfig{A-B*5(-C-D*5(-X-Y-Z-)-E-F-)}

This is normal because the second 5-ring (which is attached to atom “D”) is drawn before chemfig knows about atom “E”. In this case, it is necessary to use two hooks to draw the bond Z-E:

Compiled output

Distant bond and ring
\chemfig{A-B*5(-C-D*5(-X-Y-Z?)-E?-F-)}

We could also use a \phantom{E} at the last vertex of the 5-ring:

Compiled output

Using \phantom
\chemfig{A-B*5(-C-D*5(-X-Y-Z-\phantom{E})-E-F-)}
13.5 Rings and groups of atoms

Some care must be taken with rings when one or more vertices are made up of groups of atoms:

Compiled output

Ring and groups of atoms
\chemfig{AB*5(-CDE-F-GH-I-)}

In order for the ring to have a regular shape, it is necessary to override the chemfig mechanism which automatically calculates the departure and arrival atoms of bonds. Here, C-F and F-G must be connected by using the optional argument of these bonds:

Compiled output

Forced departure and arrival atoms
\chemfig{AB*5(-CDE-[,,1]F-[,,,1]GH-I-)}
13.6 Center of rings

Each ring has at its center a node of zero dimension whose name is centrecycle⟨n⟩ where ⟨n⟩ is the number of the ring, (the rings are numbered in the order in which they are drawn). It is possible to display the number of each ring by setting the boolean show cntcycle to true.

The default true boolean autoreset cntcycle resets the ring counter at the beginning of each molecule to 0 (i.e., each time \chemfig is executed).

Compiled output

Centre of rings
\chemfig{*5(---(-*3(---))--)}
\chemmove{\draw[red](cyclecenter1)to[out=20,in=-45](cyclecenter2);}
\qquad
\chemfig{*6(-=-=-=)}
\chemmove{%
\node[at=(cyclecenter1)](){.+}
node [at=(cyclecenter1),shift=(120:1.75cm)](end){\printatom{R^1}};
\draw[-,shorten <=.5cm](cyclecenter1)--(end);
}