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'd like to label my nodes with text that has a 'halo' around it of a different colour. Is this possible?

The reason is that my label text covers different parts of my diagram with different background colours, so no single colour will make the label legible. I'd ideally like the text to be black, with a white halo.

share|improve this question
up vote 48 down vote accepted

You can use the contour package with the outline option to create a thick outline around your text. Note that this won't work with things like fraction lines or the horizontal lines of root symbols (see How can I put a coloured outline around fraction lines?).

Andrey Vihoy mentioned the option of just filling the node background. I've added this approach for comparison.

Andrew Stacey suggests rounding the corners of the filled node, which does indeed look more elegant. This variation is shown here as well.



    \draw [fill=gray!10!white](0,0) rectangle (4.5,1) [step=0.1cm] (0,0) grid (4.5,1);
    \node at (0.75,0.5) {\contour{white}{\Large Text!}};
    \node [fill=white,inner sep=1pt] at (2.25,0.5) {\Large Text!};
    \node [fill=white,rounded corners=2pt,inner sep=1pt] at (3.75,0.5) {\Large Text!};

text with halo in tikz node

share|improve this answer
I didn't know the contour package. Thanks for mentioning it. – Gonzalo Medina May 17 '11 at 19:09
Thanks, just what I was looking for! – Jamie Vicary May 17 '11 at 19:22
How about rounded corners for a little extra elegance? – Loop Space May 17 '11 at 20:42

You can add the [fill] parameter to any text node. This doesn't get you a halo around each character, but it might be more readable, depending on what your needs are.

\draw[fill,red] (0,0) rectangle (11,2);
\draw[very thick] (1,1) -- node[outer sep=5pt,fill=white,above] {Label} (10,1);

output of code

share|improve this answer
Thanks Alan, it hadn't occurred to me that there was an easier way to solve the problem :) – Jamie Vicary May 17 '11 at 19:22

We can use \special{pdf: code ...} operator or \pdfliteral{} operator. Zdeněk Wagner, a Czech TeXist, mentions some technical details in the Zpravodaj journal 1/2013 of the Czechoslovak TeX Users Group.

I like a new toy named pdf-trans and those examples created by Paweł Jack­owski. I illustrate the use of the \boxgs command. I also like another preprepared commands, e.g. \boxshow and \boxmarkers, so I added them to that example even if they are not directly related to the Question.

The Tr operator is selecting the method of displaying a font (0, 1, or 2) with q operator which must be paired with Q operator to fit Adobe PDF specifications. It is not easy to describe these operators in detail. Then, we use w operator (dimension in big points) to set width of outline curves and the rest is easy. We set colors for font and its outline by rg&RG (rgb), k&K (cmyk) or g&G (gray). We usually use numbers before its operator, the PostScript users already know that.

I enclose an example where I set red font and sort of green outline, width is 3bp (it is very close to 3pt).

%! {pdf|lua}latex mal-outline.tex
\input pdf-trans
\def\maltext{An example.}
\node[align=center, draw]{%
  \boxgs{Q q 2 Tr 0.3 w 0.47 0.6157 0.38 RG 1 0 0 rg }{}%
  \copy\qbox \\
  \boxshow{0.3 w 0 0 1 RG}{[1 1]0 d}{}
  \copy\qbox \\
  \boxmarkers{-12pt}{3pt}{0.3 w 1 0 0 RG 1 J}
%\normalsize Text continues here.


share|improve this answer
The question is about tikz nodes. Does the code work in tikz? Otherwise, it isn't an option to the OP. – dustin Apr 4 '14 at 17:59
@dustin Good point, there could be a problem. I have updated the post. – Malipivo Apr 4 '14 at 18:13
Somebody asked a question, tex.stackexchange.com/questions/313115/draw-border-of-a-line, to which I think this answer might apply. But I don't quite know how to master your \pdfliteral technique. – Steven B. Segletes Jun 5 at 1:43

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.