Tell me more ×
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.

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

2 Answers

up vote 20 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.

\documentclass{article}

\usepackage{tikz}
\usepackage[outline]{contour}
\contourlength{1.2pt}

\begin{document}
    \begin{tikzpicture}
    \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!};
    \end{tikzpicture}
\end{document}

text with halo in tikz node

share|improve this answer
6  
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
1  
How about rounded corners for a little extra elegance? – Andrew Stacey 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.

\documentclass[12pt]{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[fill,red] (0,0) rectangle (11,2);
\draw[very thick] (1,1) -- node[outer sep=5pt,fill=white,above] {Label} (10,1);
\end{tikzpicture}
\end{document}

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

Your Answer

 
discard

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.