[Tex/LaTex] Contour around multi-line tikz text

tikz-pgf

I am trying to produce a text inside a node which has a contour. Problem is: when using contour, text width seems to be ignored, so I can not use auto multi-line text.

I discovered contours in tikz halo around text, and I can use it correctly as in:

\draw (0, 0) node {\contour{white}{A very long title that we mean to split on multiple lines}};

but when adding text width it is not multi-lined:

\draw (0, 0) node[text width=5cm] {\contour{white}{A very long title that we mean to split on multiple lines}};

And without contour it works correctly:

\draw (0, 0) node[text width=5cm] {A very long title that we mean to split on multiple lines};

How can I fix this?

Best Answer

Judging from the output of the pdfrender package, it seems that it does the same as the following TikZ code (which is coded as the opposite of optimal) and as the contour package.

Code

\documentclass[tikz]{standalone}
\usetikzlibrary{shadows}
\tikzset{
    text shadow/.code args={[#1]#2at#3(#4)#5}{
        \pgfkeysalso{/tikz/.cd,#1}%
        \foreach \angle in {0,5,...,359}{
                \node[#1,text=white] at ([shift={(\angle:.5pt)}] #4){#5};
        }
    }
}
\begin{document}
    \begin{tikzpicture}
    \fill[gray, step=.5mm] (-1.6,-1) rectangle (1.6,1);
    \node[
        text shadow={[align=center,text width=3cm] at (0,0) {A very long title that we mean to split on multiple lines \ldots}}]
                                      at (0,0) {A very long title that we mean to split on multiple lines \ldots};
    \end{tikzpicture}
\end{document}

Output

enter image description here