# simulating text on a ribbon

Imagine text on a thin strip of paper that is being wound around like a ribbon. I thought that this might be possible with tikz. What I want is something that satisfies three properties:

1. Highlights the background to the text in one colour (say yellow).
2. The background to each line is visible (so the background doesn't merge into one big coloured block).
3. A further coloured rectangle (say grey), behind the yellow, which would be at an angle joining the end of the line wrap to the beginning of the next line. In the MWE this rectangle of property 3 start at the A in the text and finish at B.

The following MWE only satisfies property 1.

\documentclass{article}

\usepackage{tikz}

\newcommand\ribbonText[1]{%
\tikz\node[rectangle, fill=yellow, text width=31mm]{#1};%
}%

\begin{document}

\ribbonText{hello world this is some dummy text}

\end{document}


EDIT The answer by Ignasi has some merit, but is it not possible to automatically find the line breaks in a tikz node?

## 2 Answers

I suspect this a bit of overkill. And the slanting of the characters doesn't always work.

\documentclass[tikz,border=0.125cm]{standalone}
\usetikzlibrary{decorations.text}
\begin{document}

\begin{tikzpicture}

\foreach \i in {1,...,2}
\path  [left color=gray, right color=gray!50!black, shift=(270:\i*2)]
(-2,0)
to [bend left, out=300, in=270, looseness=.5] (2,-2) -- (2,-1)
to [bend left, out=90,  in=120,  looseness=.5] (-2,1) -- cycle;
\foreach \i in {1,...,3}
\path [left color=yellow, right color=yellow!50!orange, shift=(270:\i*2)]
(2,0)
to [bend left, out=270, in=270, looseness=.5] (-2,0) -- (-2,1)
to [bend left, out=90,  in=90,  looseness=.5] ( 2,1) -- cycle;

\tikzset{%
banner text/.style={%
decoration={text effects along path,
text={#1}, text align=center,
text effects/.cd,
character count=\i, character total=\n,
characters={inner sep=0pt,
anchor=base,
font=\huge,
yslant=-(\i-\n/2)/20
},
}, decorate,
}
}

\foreach \t [count=\i] in {Hello world, this is some, dummy text}
\path [banner text/.expanded=\t, shift=(270:\i*2-.25)]
(-2,0)
to [bend left, out=90, in=90, looseness=.5] (2,0) ;
\end{tikzpicture}

\end{document}


• This looks fantastic but I can't get your code to compile (multiple pgfkeys errors). Any ideas? – Geoff Jan 28 '14 at 17:17
• @Geoff Ah yes, it requires pgf 3.0.0 for the text effects along path decoration. – Mark Wibrow Jan 28 '14 at 18:49
• Shouldn't it curl the other way? That is, don't you have to read this direction from the bottom up? Fantastic, even so! – cfr Feb 4 '14 at 4:28
• @cfr good point! Adding xscale=-1 to the first \path command should fix it. – Mark Wibrow Feb 5 '14 at 14:07
• @MarkWibrow: I am getting this instead of the displayed output with a recently updated TeXLive2014. – Peter Grill Jan 14 '15 at 20:52

I know how to do it if breaking lines by hand is permitted ;-)

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{positioning,backgrounds}
\begin{document}
\begin{tikzpicture}[ribbon/.style={rectangle, fill=yellow, text width=31mm, align=center}, back/.style={fill=gray}]

\node[ribbon](a){Hello, world};
\node[ribbon, below=5mm of a] (b){this is some};
\node[ribbon, below=5mm of b] (c){dummy text};

\begin{scope}[on background layer]
\foreach \i/\j in {a/b, b/c}
\fill[back] (\i.north east)--(\i.south east)--(\j.south west)--(\j.north west)--cycle;
\end{scope}
\end{tikzpicture}
\end{document}

• This looks great. Ideally though would have automatic line breaking though! – Geoff Jan 27 '14 at 18:15
• @Geoff: I was sure you wanted automatic line breaking, but I have no idea about how to do it. We'll have to wait for some more help. – Ignasi Jan 27 '14 at 18:20