LaTeX forum ⇒ Graphics, Figures & TablesTorn paper tearout example Topic is solved

Information and discussion about graphics, figures & tables in LaTeX documents.
Erik_Schiegg
Posts: 3
Joined: Sun Apr 01, 2018 12:03 pm
Location: Switzerland

Torn paper tearout example

Postby Erik_Schiegg » Sun Apr 01, 2018 12:22 pm

Hi folks, happy easter,

I found this beautiful example making a fractal paper tear out text box, but I can't get it to work, when I open it in overleaf
:D
http://www.texample.net/tikz/examples/torn-paper/
The code looks like this, please open the original from the link
  1. % Torn paper with matching torn edges
  2. % Author: Jose Luis Diaz
  3. \documentclass[a5paper]{article}
  4. \usepackage{lipsum} % To generate test text
  5. \usepackage{framed}
  6. \usepackage{ifthen}
  7. \usepackage{tikz}
  8. %%%<
  9. \usepackage{verbatim}
  10. \usepackage[active,tightpage]{preview}
  11. \PreviewEnvironment{center}
  12. \setlength\PreviewBorder{10pt}%
  13. %%%>
  14. \begin{comment}
  15. :Title: Torn paper with matching torn edges
  16. :Tags: Styles;Fractals;Decorative drawings;Fun
  17. :Author: Jose Luis Diaz
  18. :Slug: torn-paper
  19.  
  20. This example is similar to: <!-- m --><a class="postlink" href="http://texample.net/tikz/examples/framed-tikz/">http://texample.net/tikz/examples/framed-tikz/</a><!-- m -->
  21.  
  22. Fractal decorations are used to achieve a torn paper effect.
  23. The bottom of one piece matched the top of the next one.
  24. This is done by resetting the random seed before drawing each border.
  25. However, you get the "same" random border in all your fragments,
  26. which is not nice. You want randomness in each new bottom border,
  27. but exactly the same randomness in the next top border. In order to get this,
  28. you need a global counter which is increased in each "paper fragment",
  29. and which is used as seed for the bottom border.
  30.  
  31. It is neccesary to use \pgfextra to be able of setting the seed in the middle
  32. of the path (i.e: between top and bottom borders).
  33.  
  34. In addition, there is the problem that both paths (top and bottom) have to be
  35. drawn in the same direction in order to get the same contour.
  36.  
  37. In order to fill the piece of paper with a background, it is not possible
  38. to draw both top and bottom borders in the same direction (eg. left to right).
  39. So the solution involves drawing one piece of paper visiting its corners in
  40. clockwise direction, and the following one in counter-clockwise direction.
  41. I use the counter mathseed and draw in one direction or the other based
  42. on \isodd{mathseed}.
  43.  
  44. The algorithm that draws the fractal border tends to produce "spikes" towards
  45. its right (in the advance direction), and "cloud borders" towards its left. So,
  46. a box drawn in clockwise direction would have a "cloudy" aspect, while one
  47. drawn in counterclockwise direction would have a "spiky" aspect.
  48.  
  49. The assymetry can be make less apparent if the bottom border is drawn with
  50. a negative amplitude (which reverses the side towards the spikes appear).
  51. This is easy to achieve by defining two irregular border styles,
  52. which are used alternatively.
  53.  
  54. This code was written by Jose Luis Diaz and published on TeX.SE.
  55. \end{comment}
  56. \usepackage[margin=1cm]{geometry}% for screen preview
  57. \usetikzlibrary{decorations.pathmorphing,calc,shadows.blur,shadings}
  58.  
  59. \newcounter{mathseed}
  60. \setcounter{mathseed}{3}
  61. \pgfmathsetseed{\arabic{mathseed}} % To have predictable results
  62. % Define a background layer, in which the parchment shape is drawn
  63. \pgfdeclarelayer{background}
  64. \pgfsetlayers{background,main}
  65.  
  66. % This is the base for the fractal decoration. It takes a random point between the start and end, and
  67. % raises it a random amount, thus transforming a segment into two, connected at that raised point
  68. % This decoration can be applied again to each one of the resulting segments and so on, in a similar
  69. % way of a Koch snowflake.
  70. \pgfdeclaredecoration{irregular fractal line}{init}
  71. {
  72. \state{init}[width=\pgfdecoratedinputsegmentremainingdistance]
  73. {
  74. \pgfpathlineto{\pgfpoint{random*\pgfdecoratedinputsegmentremainingdistance}{(random*\pgfdecorationsegmentamplitude-0.02)*\pgfdecoratedinputsegmentremainingdistance}}
  75. \pgfpathlineto{\pgfpoint{\pgfdecoratedinputsegmentremainingdistance}{0pt}}
  76. }
  77. }
  78.  
  79.  
  80. % define some styles
  81. \tikzset{
  82. paper/.style={draw=black!10, blur shadow, every shadow/.style={opacity=1, black}, shade=bilinear interpolation,
  83. lower left=black!10, upper left=black!5, upper right=white, lower right=black!5, fill=none},
  84. irregular cloudy border/.style={decoration={irregular fractal line, amplitude=0.2},
  85. decorate,
  86. },
  87. irregular spiky border/.style={decoration={irregular fractal line, amplitude=-0.2},
  88. decorate,
  89. },
  90. ragged border/.style={ decoration={random steps, segment length=7mm, amplitude=2mm},
  91. decorate,
  92. }
  93. }
  94.  
  95. \def\tornpaper#1{%
  96. \ifthenelse{\isodd{\value{mathseed}}}{%
  97. \tikz{
  98. \node[inner sep=1em] (A) {#1}; % Draw the text of the node
  99. \begin{pgfonlayer}{background} % Draw the shape behind
  100. \fill[paper] % recursively decorate the bottom border
  101. \pgfextra{\pgfmathsetseed{\arabic{mathseed}}\addtocounter{mathseed}{1}}%
  102. {decorate[irregular cloudy border]{decorate{decorate{decorate{decorate[ragged border]{
  103. (A.north west) -- (A.north east)
  104. }}}}}}
  105. -- (A.south east)
  106. \pgfextra{\pgfmathsetseed{\arabic{mathseed}}}%
  107. {decorate[irregular spiky border]{decorate{decorate{decorate{decorate[ragged border]{
  108. -- (A.south west)
  109. }}}}}}
  110. -- (A.north west);
  111. \end{pgfonlayer}}
  112. }{%
  113. \tikz{
  114. \node[inner sep=1em] (A) {#1}; % Draw the text of the node
  115. \begin{pgfonlayer}{background} % Draw the shape behind
  116. \fill[paper] % recursively decorate the bottom border
  117. \pgfextra{\pgfmathsetseed{\arabic{mathseed}}\addtocounter{mathseed}{1}}%
  118. {decorate[irregular spiky border]{decorate{decorate{decorate{decorate[ragged border]{
  119. (A.north east) -- (A.north west)
  120. }}}}}}
  121. -- (A.south west)
  122. \pgfextra{\pgfmathsetseed{\arabic{mathseed}}}%
  123. {decorate[irregular cloudy border]{decorate{decorate{decorate{decorate[ragged border]{
  124. -- (A.south east)
  125. }}}}}}
  126. -- (A.north east);
  127. \end{pgfonlayer}}
  128. }}
  129.  
  130. \begin{document}
  131. \begin{center}
  132. \noindent
  133. \tornpaper{
  134. \parbox{.9\textwidth}{\lipsum[11]}
  135. }
  136.  
  137. \noindent
  138. \tornpaper{
  139. \parbox{.9\textwidth}{\lipsum[15]}
  140. }
  141.  
  142. \noindent
  143. \tornpaper{
  144. \parbox{.9\textwidth}{\lipsum[5]}
  145. }
  146. \end{center}
  147. \end{document}


:shock:
Overleaf throwing error:
  1. Package pgfkeys Error: Choice 'bilinear interpolation' unknown
  2. in choice key '/tikz/shade'. I am going to ignore this key.
  3.  
  4. See the pgfkeys package documentation for explanation.
  5. Type H <return> for immediate help.
  6. ...
  7.  
  8. l.146 }


Although there is a special overleaf link...
As I am still quite a greenLaTeXhorn, I would be glad for a helping hand getting this example to work. Thank you.

User avatar
Stefan Kottwitz
Site Admin
Posts: 8733
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Sun Apr 01, 2018 4:21 pm

Hi Erik,

welcome to the forum!

It seems that TikZ key has been renamed: use shading=bilinear interpolation instead of shade=bilinear interpolation.

Stefan
Site admin

Erik_Schiegg
Posts: 3
Joined: Sun Apr 01, 2018 12:03 pm
Location: Switzerland

Postby Erik_Schiegg » Sun Apr 01, 2018 8:50 pm

Thank you Stefan,

so I have to change this passage:

  1. % define some styles
  2. \tikzset{
  3. paper/.style={draw=black!10, blur shadow, every shadow/.style={opacity=1, black}
  4.  
  5. shade=bilinear interpolation,
  6.  
  7.  
  8. lower left=black!10, upper left=black!5, upper right=white, lower right=black!5, fill=none},
  9. irregular cloudy border/.style={decoration={irregular fractal line, amplitude=0.2},
  10. decorate,
  11. },
  12. irregular spiky border/.style={decoration={irregular fractal line, amplitude=-0.2},
  13. decorate,
  14. },
  15. ragged border/.style={ decoration={random steps, segment length=7mm, amplitude=2mm},
  16. decorate,
  17. }
  18. }


I will try it out in overleaf and will report if it works

Next error:
  1. Package pgfkeys Error: I do not know the key '/tikz/paper' and
  2. I am going to ignore it. Perhaps you misspelled it.
  3.  
  4. See the pgfkeys package documentation for explanation.
  5. Type H <return> for immediate help.
  6. ...
  7.  
  8. l.146 }


And where can I look up the actual keys of packages on my own?

User avatar
Stefan Kottwitz
Site Admin
Posts: 8733
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Sun Apr 01, 2018 9:50 pm

Yes, indeed you just need to change the single word.

I tested also on Overleaf, the code then works for me. The second error was just a consequence: since the first error was in the paper style, it could not be created, and the compiler continued, so later it was not able to find a paper style. Just fix this single word. :-)

Stefan
Site admin

Erik_Schiegg
Posts: 3
Joined: Sun Apr 01, 2018 12:03 pm
Location: Switzerland

Postby Erik_Schiegg » Mon Apr 02, 2018 5:25 am

Thank you Stefan, I got it to work :D in the VerbTeX editor,
overleaf is not working well from a tablet, no copy paste for example! I have to work the overleaf handling out, connecting a keyboard... or repair my regular laptop, broken DC connecter, no big deal...

You helped me like a Boss!


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: Bing [Bot] and 13 guests