2

@gonzalo-medina 's answer to this post: Background notebook template with spiral looks exactly like what I am looking for, but instead of a full background for every page I need to create an environment which resizes the background according to the content. I mean: I might have only one paragraph in the whole page with this bakground, and then a few pages later it might happen again, but perhaps this new one is a bit longer and the drawing should adapt itself.

What should I change in the code in order to get what I want?

0

2 Answers 2

4

You can adapt the spirals and use them as overay for a tcolorbox. Following code draws an unbreakable tcolorbox with spirals in north edge. I didn't know what solution was desired in case of breakable boxes.

\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}

\newtcolorbox{notebook}[1][]{
    notitle,
    enhanced,
    colframe=gray!70,
    colback=blue!2,
    boxrule=1pt,
    top=7mm,
    sharp corners=north,
    enlarge top initially by= 5mm,
    underlay={\begin{tcbclipinterior}\draw[help lines, step=5mm, gray!15, shift={(interior.north west)}] (interior.south west) grid (interior.north east);\end{tcbclipinterior}},
    overlay={
        \foreach \i in {1,2,...,13}{
            \draw[draw=black, left color = black!60, right color = black!50, middle color = gray!20] ([yshift=-5 mm, xshift=5mm+(\i-1)*8.75mm]frame.north west) rectangle ++(10pt,10pt);
            \draw[double=gray!80, double distance=1pt] ([xshift=6.5mm+(\i-1)*8.75mm]frame.north west) arc (30:360:2pt and 8pt);
            \draw[double=gray!80, double distance=1pt] ([xshift=8mm+(\i-1)*8.75mm]frame.north west) arc (30:360:2pt and 8pt);
            }
    },
    #1,
    }
\begin{document}
\lipsum[1]

\begin{notebook}
\lipsum[1]
\end{notebook}

\begin{notebook}
\lipsum[1-3]
\end{notebook}

\end{document}

enter image description here

1

I kept most of the functionality of the original solution, except I use a constant spacing (spiralspace) and compute the number to fit the space.

\documentclass{article}
\usepackage{xkeyval}
\usepackage{tikzpagenodes}
\usetikzlibrary{shadows,calc,backgrounds}
\usepackage{lipsum}

\def\ShadowXshift{0.5ex}
\def\ShadowYshift{-0.5ex}

\newsavebox{\NotebookBox}

\makeatletter
\define@key{educnotebook}{spiralspace}{\def\SpiralSpace{#1}}
\define@key{educnotebook}{nbcolorbg}{\def\NbColorBg{#1}}
\define@key{educnotebook}{minorgridcolor}{\def\MinorGridColor{#1}}
\define@key{educnotebook}{majorgridcolor}{\def\MajorGridColor{#1}}
\define@boolkey{educnotebook}{majorgrid}[false]{
\ifKV@educnotebook@majorgrid 
  \def\DrawMajorGrid{
    \path[clip,rounded corners=10pt]
        ([xshift=-30pt,yshift=20pt]Notebook.north west) rectangle
        ([xshift=30pt,yshift=-20pt]Notebook.south east);
    \draw[\MajorGridColor,opacity=0.3]
          ([xshift=30pt,yshift=-20pt]Notebook.south east) grid[step=10mm]
          ([xshift=-30pt,yshift=20pt]Notebook.north west);
  }
\else
  \def\DrawMajorGrid{\relax}
\fi
}
\define@boolkey{educnotebook}{minorgrid}[false]{
\ifKV@educnotebook@minorgrid 
  \def\DrawMinorGrid{
    \path[clip,rounded corners=10pt]
        ([xshift=-30pt,yshift=20pt]Notebook.north west) rectangle
        ([xshift=30pt,yshift=-20pt]Notebook.south east);
    \draw[\MinorGridColor,opacity=0.3]
          ([xshift=30pt,yshift=-20pt]Notebook.south east) grid[step=1mm]
          ([xshift=-30pt,yshift=20pt]Notebook.north west);
  }
\else
  \def\DrawMinorGrid{\relax}
\fi
}
\define@choicekey+{educnotebook}{spiralposition}[\val\nr]{left,right,top}[left]{%
  \ifcase\nr\relax
    \def\SpiralPosition{
      ([xshift=9pt,yshift=7pt-\SpiralOffset-\Valor*\SpiralSpace]Notebook.north west)
    }
    \def\RotateAngle{0}
  \or
    \def\SpiralPosition{
      ([xshift=-9pt,yshift=-3pt-\SpiralOffset-\Valor*\SpiralSpace]Notebook.north east)
    }
    \def\RotateAngle{180}
    \def\ShadowXshift{-0.5ex}
    \def\ShadowYshift{-0.5ex}
  \or
    \def\SpiralPosition{
      ([yshift=-19pt,xshift=4pt+\SpiralOffset+\Valor*\SpiralSpace]Notebook.north west)
      }
    \def\RotateAngle{270}
  \fi
}{}

\setkeys{educnotebook}{
  nbcolorbg=white,
  minorgrid=false,
  majorgrid=false,
  minorgridcolor=black!20,
  majorgridcolor=black!60,
  spiralposition=left,
  spiralspace=0.5in
  }
\def\RotateAngle{0}
\def\ShadowXshift{0.5ex}
\def\ShadowYshift{-0.5ex}

\makeatother

\tikzset{
spiral/.pic={
  \draw[rotate=\RotateAngle,
    draw=black,
    left color=black!70,
    right color=black!60,
    middle color=gray!40
    ] 
    (-1.1,-0.35) rectangle ++(10pt,10pt);
  \draw[
    rotate=\RotateAngle,
    double=gray!80,
    double distance=1pt,
    ]
    (-1,-0.2) arc (40:-250:10pt and 2pt);
  \draw[
    rotate=\RotateAngle,
    double=gray!80,
    double distance=1pt,
    ]
    (-1,-0.05) arc (40:-250:10pt and 2pt);
  }
}

\newcommand{\EducNotebook}[2][]% #1 = options (optional), #2 = contents, preferably in the form of a \parbox
{\bgroup
  \savebox{\NotebookBox}{#2}%
  \setkeys{educnotebook}{#1}%
  \ifnum\RotateAngle=270\relax
    \dimen0=\dimexpr \wd\NotebookBox\relax
  \else
    \dimen0=\dimexpr \ht\NotebookBox+\dp\NotebookBox\relax
  \fi
  \dimen1=\SpiralSpace\relax
  \def\SpiralNumber{\the\numexpr \dimen0/\dimen1 - 1\relax}%
  \dimen2=\dimexpr \dimen0 - \SpiralNumber\dimen1\relax
  \def\SpiralOffset{\the\dimexpr 0.5\dimen2\relax}%
  \par\noindent\tikz{
    \node (Notebook) [inner sep=0pt] {\usebox\NotebookBox};
    \begin{scope}[on background layer]
      \draw[rounded corners=10pt,fill=\NbColorBg,drop shadow={shadow xshift=\ShadowXshift, shadow yshift=\ShadowYshift}]
        ([xshift=-30pt,yshift=20pt]Notebook.north west) rectangle
        ([xshift=30pt,yshift=-20pt]Notebook.south east);
      \begin{scope}%clipping
        \DrawMajorGrid
        \DrawMinorGrid
      \end{scope}
      \foreach \Valor in {0,1,...,\SpiralNumber}
        \pic at \SpiralPosition {spiral};
    \end{scope}
  }\par
\egroup}

\begin{document}
Text above.
\EducNotebook[spiralposition=top]{\parbox{\dimexpr\textwidth-60pt}{\lipsum[1]}}
Text below.
\end{document}

demo

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .