TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to draw a diagram using Tikz that will show the crystalline lattice structure of diamond. It should look like the following illustration (reference).

enter image description here

I have managed to figure out the locations of each of the carbon atoms. I defined each of those locations as a coordinate (A, B, ... Q) and I managed to draw the atoms, but I don't like the look of the lines that show which atoms are connected.

My problem is that the lines are not distinct enough from one another. Instead of plain lines I would like to draw three dimensional cylinders that connect the atoms together as I think that would make the image look much better. I have no idea how to get Tikz to do this, however.

Here's what I've got so far. Anybody have an idea?

enter image description here


\begin{tikzpicture}[scale = 1]

%points on cube

\coordinate (A) at (0,0,0);
\coordinate (B) at (0,0,4);
\coordinate (D) at (0,4,0);
\coordinate (C) at (0,4,4);
\coordinate (E) at (4,0,0);
\coordinate (F) at (4,0,4);
\coordinate (H) at (4,4,0);
\coordinate (G) at (4,4,4);

%center of faces

\coordinate (I) at (0,2,2); %center of face ABCD
\coordinate (J) at (4,2,2); %center of face EFGH
\coordinate (K) at (2,4,2); %center of face DCGH
\coordinate (L) at (2,0,2); %center of face ABFE
\coordinate (M) at (2,2,4); %center of face CBGF
\coordinate (N) at (2,2,0); %center of face DAEH


\coordinate (O) at (1,1,3);
\coordinate (P) at (1,3,1);
\coordinate (Q) at (3,1,1);
\coordinate (R) at (3,3,3);
%place non-atom cube corners
\shadedraw [ball color= gray] (A) circle (0.1cm);
\shadedraw [ball color= gray] (C) circle (0.1cm);
\shadedraw [ball color= gray] (F) circle (0.1cm);
\shadedraw [ball color= gray] (H) circle (0.1cm);
\shadedraw [ball color= black] (B) circle (0.25cm);
\shadedraw [ball color= black] (D) circle (0.25cm);
\shadedraw [ball color= black] (E) circle (0.25cm);
\shadedraw [ball color= black] (G) circle (0.25cm);
%draw the center of each face
\shadedraw [ball color= red] (I) circle (0.25cm);
\shadedraw [ball color= red] (J) circle (0.25cm);
\shadedraw [ball color= red] (K) circle (0.25cm);
\shadedraw [ball color= red] (L) circle (0.25cm);
\shadedraw [ball color= red] (M) circle (0.25cm);
\shadedraw [ball color= red] (N) circle (0.25cm);
\shadedraw [ball color= blue] (O) circle (0.25cm);
\shadedraw [ball color= blue] (P) circle (0.25cm);
\shadedraw [ball color= blue] (Q) circle (0.25cm);
\shadedraw [ball color= blue] (R) circle (0.25cm);
%draw cube
\draw [dashed] (A) -- (B);
\draw [dashed] (B) -- (C);
\draw [dashed] (C) -- (D);
\draw [dashed] (D) -- (A);
\draw [dashed] (E) -- (F);
\draw [dashed] (F) -- (G);
\draw [dashed] (G) -- (H);
\draw [dashed] (H) -- (E);
\draw [dashed] (A) -- (E);
\draw [dashed] (B) -- (F);
\draw [dashed] (C) -- (G);
\draw [dashed] (D) -- (H);
%connections from faces to O
\draw [very thick] (B) -- (O);
\draw [very thick] (I) -- (O);
\draw [very thick] (M) -- (O);
\draw [very thick] (L) -- (O);
%connections from faces to P
\draw [very thick] (N) -- (P);
\draw [very thick] (I) -- (P);
\draw [very thick] (D) -- (P);
\draw [very thick] (K) -- (P);
%connections from faces to Q
\draw [very thick] (E) -- (Q);
\draw [very thick] (J) -- (Q);
\draw [very thick] (N) -- (Q);
\draw [very thick] (L) -- (Q);
%connections from faces to R
\draw [very thick] (G) -- (R);
\draw [very thick] (M) -- (R);
\draw [very thick] (J) -- (R);
\draw [very thick] (K) -- (R);
share|improve this question
Possible duplicate here. – kiss my armpit May 17 '13 at 17:00
Welcome to TeX.sx! Feel free to visit our TeX.SX starter guide to get the most out of our site. – Peter Jansson May 17 '13 at 17:22
The lines in the linked page do seem fairly two-dimensional, so maybe just a thicker line width or “tapered” lines like in Drawing Tapered Edges in Graph? – Qrrbrbirlbel May 17 '13 at 18:25
Here's another crystal lattice question tex.stackexchange.com/questions/97271/… – Alex May 17 '13 at 18:44
You might also be interested in a similar answer tex.stackexchange.com/questions/141363/… – strpeter Jan 21 '14 at 21:42
up vote 13 down vote accepted

enter image description here

This model uses cylinders for connection, rendered in Asymptote, cr.asy:

import solids;

currentprojection=orthographic (

// save predefined 2D orientation vectors
pair NN=N;
pair SS=S;
pair EE=E;
pair WW=W;

//%points on cube

triple A = (0,0,0);
triple B = (0,0,4);
triple D = (0,4,0);
triple C = (0,4,4);
triple E = (4,0,0);
triple F = (4,0,4);
triple H = (4,4,0);
triple G = (4,4,4);

triple[] cubicCornerA={  

triple[] cubicCornerB={  

//%center of faces

triple I = (A+B+C+D)/4; //%center of face ABCD
triple J = (E+F+G+H)/4; //%center of face EFGH
triple K = (D+C+G+H)/4; //%center of face DCGH
triple L = (A+B+F+E)/4; //%center of face ABFE
triple M = (C+B+G+F)/4; //%center of face CBGF
triple N = (D+A+E+H)/4; //%center of face DAEH

triple[] faceCenter={  

triple O = (1,1,3);
triple P = (1,3,1);
triple Q = (3,1,1);
triple R = (3,3,3);

triple[] connectors={  

//%place non-atom cube corners

real cornerAR=0.05;
real cornerBR=0.2;
real faceCR=0.2;
real connR=faceCR;


real cylR=0.062;

void Draw(guide3 g,pen p=currentpen){
               new pen(int i, real j){
                 return p;

//%connections from faces to O
pen connectPen=lightgray;

//%connections from faces to P

//%connections from faces to Q

//%connections from faces to R

void drawSpheres(triple[] C, real R, pen p=currentpen){
  for(int i=0;i<C.length;++i){
                        new pen(int i, real j){return p;}


Process with asy -f pdf cr.asy to get an interactive (Adobe Reader only) standalone cr.pdf, or with asy -f pdf -noprc -render=0 cr.asy to get an ordinary cr.pdf, or asy -f png -render=5 cr.asy to get a smaller raster image cr.png.

share|improve this answer
Brilliant! That is exactly what I'm looking for! – shane May 18 '13 at 18:25
The original image uses grey dashed lines for the edges of the cube that lie behind the cube, and I think that makes it a little easier for the eye to organize the image. – Benjamin McKay Jun 26 '13 at 14:03
But at the same time, the result is much clearer than the original, because of the colours of the nodes, and the shading of the cylinders, so hats off. – Benjamin McKay Jun 26 '13 at 14:04
@Benjamin McKay: The colors are easy to change, see the answer to Labels and angles in crystal structure using Asymptote. – g.kov Jun 26 '13 at 16:13
@g.kov That's very beautiful. I'm quite a fan of your asymptote solutions :). Unfortunately, I have a little bit of trouble reproducing this one in its full glory when I compile it with asy -f pdf -noprc -render=0 cr.asy. In this case, the lighting and the colors don't look so nice anymore, the spheres have some defects at their tops and the z-ordering gets confused, e.g. the backmost (red) sphere is in the front of the picture and most of the bond-atom-orderings are broken. Is this a general problem or is it only me who experiences this (I'm working with Windows 7 64bit, Asymptote 2.23)? – Philipp Jul 1 '13 at 23:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.