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

I have to include small code snippets like method and class names within continuous text. I do not want to display those snippets as complete seperated listings, they should be displayed inline, similar to the option this site offers with backticks.

But let's face it, the options that are available out of the box are just plain ugly.

What I have in mind is the notation GitHub (and many other sites) use:

So, in particular:

  • rounded corners
  • contrastring border color
  • different background color
  • fixed width code font
  • pretty (vertical) alignment within the text

I found many options to draw boxes around text (fancybox, colorbox, mdframed and others) but none of those packages seemed to be capable to fulfill all of my requirements (then again, I'm not really a LaTeX expert).

So the question is: How can we make inline code pretty?

share|improve this question
up vote 7 down vote accepted

Is this what you're looking for?


enter image description here



    \node(s)[rounded corners,fill=orange!20,draw=gray]{\texttt{#1}};


Further, lists can be turned into \textcolor{blue}{Task Lists} 
by prefacing list items with \code{[ ]} or \code{[x]} (incomplete or complete,



A slight improvement of the \code macro, to ensure uniform height and depth of the box regardless of the height/depth of its content. Also, the improved macro \codex admits an optional argument.

            rounded corners,
            fill=blue!5,        % background color
            draw=gray,          % border of box
            text=gray!50!black, % text color
            inner xsep =3pt,    % horizontal space between text and border
            inner ysep =0pt,    % vertical space between text and border
            text height=2ex,    % height of box
            text depth =1ex,    % depth of box
            #1                  % other options

Compare the output of \code and the improved version \codex

\code{aaaa} \code{bbbb} \code{ffff} \code{gggg} \code{<code>\textbackslash code</code>}

\codex{aaaa} \codex{bbbb} \codex{ffff} \codex{gggg} \codex{<code>\textbackslash code</code>}

enter image description here

share|improve this answer
Looks very promising :) , what is missing is a (thin) border around the box – Leo Oct 22 '13 at 22:27
@Mef: see updated answer. The box can be drawn by adding draw=<color> option to the node operation. – Herr K. Oct 22 '13 at 22:30
Nice work! One more thing to make it perfect: Can the text color also be changed within this command (dark grey instead of black)? – Leo Oct 22 '13 at 22:32
@Mef Add text=gray!50!black into the option of the \node. – Paul Gaborit Oct 22 '13 at 23:07
@Mef: I've made a slight improvement of the macro to ensure uniform height and depth of the box despite its content. See update in the answer. – Herr K. Oct 23 '13 at 16:44

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.