11

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?

Geoff
  • 2,637

2 Answers2

31

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}

enter image description here

Mark Wibrow
  • 70,437
11

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

enter image description here

\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}
Ignasi
  • 136,588
  • 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