TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

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

The unique style of the diagrams at xkcd has an informative but nice hand-drawn touch. I guess they are actually drawn by hand but just recently on our partner site for Mathematica someone asked how to draw a similar diagram such as this one with Mathematica's plot functions (xkcd-style-graphs).

xkcd diagram

Now without Mathematica this should be possible as well but I have a hard time getting the details right. Can such a diagram be created in TeX with a similar design? My first attempt does not look particularly great but here it is (the font is from http://antiyawn.com/uploads/humorsans.html):


    \pgfplotsset{every axis/.append style={line width=1pt}}

        axis x line=bottom,
        axis y line=left,
        xtick={1.2, 2.9, 4.5},
        xticklabels={-3 days, -1 day, 5 minutes},
    % 1st plot
    \addplot [cyan!80!white, samples=200, domain=0:6] {0.05*rnd+3+(sin(deg(x))^2)/sqrt(x)*exp(-(x-2))};
    % white background for 2nd plot
    \addplot [white, samples=200, domain=0:6,line width=4pt] {0.05*rnd+0.4*x+2+x^2*sin(deg(x))^2*exp(-x)}; 
    % 2nd plot
    \addplot [red!80!white, samples=200, domain=0:6] {0.05*rnd+0.4*x+2+x^2*sin(deg(x))^2*exp(-x)}; 

    \node at (2.7,4.6) {downhill};
    \draw  plot[smooth, tension=.7,line width=2pt] coordinates {(1.2679,5.5206) (1.9454,5.493) (2.4017,4.9261)};



first attempt

share|improve this question
The reason why your plots seem to have too much noise in them is that you use the same number of samples for the random part. You could try creating a table with "clean" function values using pgfplotstable, then add random steps with a lower number of samples and plot the result. – Christoph Oct 1 '12 at 13:44
There is a variation of this using R to generate the graphic. With the intermediate use of knitr or sweave this can be integrated with LaTeX to import a very nice version of XKCD like graphics. See drunks-and-lampposts.com/2012/10/02/… I am going to use this technique to draw graphics for my statistics class to 'emulate' my handwriting. It will get a laugh. – R. Schumacher Oct 3 '12 at 0:12
Congratulations on the Great Question badge :) – cmhughes Oct 3 '12 at 15:23
I know I'm really late to the party, but xkcd is hand drawn. Source (check the title text). – Piccolo Mar 30 '13 at 22:35
This is also possible using matplotlib. – E.P. Aug 29 '14 at 9:51
up vote 255 down vote accepted

This has been a topic for a few questions on this site and you can find many examples of such human-like typesetting, the most famous being the great

How do I make my document look like it was written by a Cthulhu-worshipping madman?

and also slightly related ones

Simulating hand-drawn lines

TikZ two-blocks matrix

that I can remember (because I've posted some answers) but please add more if I'm missing the obvious ones.

Regarding the answer, you can use decorations instead of random perturbations to your plots such that they are handled by TikZ instead. Also you can use a double line to achieve that white overlay over the previous line.

I don't have the Humor Sans font but I've used another similar font for using PDFLaTeX directly. Guys at SO have a better replacement for the font: xkcd style graphs in R

(The updated example needs XeLaTeX or LuaLaTeX!!)



\begin{tikzpicture}[decoration={random steps,segment length=1mm,amplitude=0.2pt}]
\pgfplotsset{every axis/.append style={line width=1pt}}

axis x line=middle,
axis y line=middle,
xtick={1.2, 2.9, 4.5},
xticklabels={-3 days, -1 day, 5 minutes},
every inner x axis line/.append style={-},
every inner y axis line/.append style={-},
decoration={random steps,segment length=5pt,amplitude=0.3pt},decorate,
every tick/.style={thick,black,decorate}
\begin{scope}[decoration={random steps,segment length=3pt,amplitude=0.5pt},decorate]
\addplot [cyan!80!white, samples=30, domain=0:6] {3+(sin(deg(x))^2)/sqrt(x)*exp(-(x-2))};
\addplot [white,double=red!80!white, samples=30, domain=0:6,double distance=1.0pt] {0.4*x+2+x^2*sin(deg(x))^2*exp(-x)}; 
\draw (1.2679,5.5206) to[bend left] (2.7,4.6) node[below] {downhill};
\draw[line join=round,decorate] (0.6cm,-0.1cm) arc (45:275:0.4cm) arc (275:410:0.38cm);
\draw[decorate] (0.4cm,-0.9cm)coordinate (n) -- ++(0.1,-1cm) coordinate (a) -- +(-70:1.2cm) (a) --+(-110:1.2cm);
\draw[decorate] (n) -- ++(-5:0.4cm) --+(10:0.5cm);
\draw[decorate] (n) -- ++(-55:0.4cm) --+(2:0.5cm);
\node[align=left,scale=0.5] (c) at (0.5,2){I WON'T EVEN TRY \\TO BE FUNNY LIKE XKCD};
\draw[thin] (c) to[in=110,out=-90] ++(0,-0.5cm) node[below,align=left,scale=0.5] 
\draw[thin] (d) to[in=80,out=-90] ++(0,-1cm);



ba dum tss...

You can extend the effectiveness of the decoration to axes too if you remove the scope and supply the decoration options to the axis environment.

EDIT : added some clarification for the axes and some bonus stuff

EDIT2 : switched to a better font.

And finally I think it's not the wavy lines or the cartoonish display but the dry-humor of the author that makes them so funny so I don't think this would bring anything closer to those of xkcd.

share|improve this answer
Awesomeness has a name: percusse. :) – Paulo Cereda Oct 1 '12 at 13:51
I've been holding the mouse over the plot for ages now and I have yet to see the punchline displayed. – David Carlisle Oct 1 '12 at 14:07
the axes are still too straight IMO – heinrich5991 Oct 1 '12 at 14:10
I'm going to use this style in the thesis just to see my supervisor reaction... – Claudio Fiandrino Oct 1 '12 at 16:34
@ClaudioFiandrino Added a student for you :) – percusse Oct 1 '12 at 16:42

If creating plots using matplotlib (python) is an option, take a look at "XKCDify " (sorry, this isn't a "TeX answer", but inclusion of matplotlib-generated plots in TeX documents is common enough I think it's worth mentioning this here).

enter image description here

share|improve this answer

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.