0

I wanted to adapt the answer here to insert line numbers on the left side (inside the box) -- just like listings in the tcolorbox package.

I have also tried to put an optional number of lines argument in the newtcolorbox command, but as it didn't work, it ended up with the shoddy manual vspace instead.

\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{lmodern}
\usepackage{blindtext}
\usepackage{calc}

\newtcolorbox{notebook}{
    enhanced,
    breakable,
    colback=green!10,
    colframe=green!65!black,
    left=.7in,
    underlay={%
        \begin{tcbclipinterior}
        %\shade[inner color=green!80!yellow,outer color=yellow!10!white]
%(interior.north west) circle (2cm);
        \draw[help lines, ystep=\baselineskip, xstep=\linewidth, 
            shift={(interior.north west)}](interior.south west) grid (interior.north east);
        \draw[help lines] ([xshift=.5in]interior.north west)--
            ([xshift=.5in]interior.south west);
        \end{tcbclipinterior}}
    }

\usepackage{lineno}


\begin{document}
\blindtext[1]
\begin{notebook}
\blindtext[3]
\end{notebook}

\begin{notebook}
\vspace{20\baselineskip}
\linenumbers
\end{notebook}


\end{document}

enter image description here

1 Answers1

2

Probably I misunderstand your question, but you can just add an optional parameter that inserts the empty lines using before upper.

\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{lmodern}
\usepackage{blindtext}
\usepackage{calc}

\newtcolorbox{notebook}[1][0]{
    enhanced,
    breakable,
    colback=green!10,
    colframe=green!65!black,
    left=.7in,
    underlay={%
        \begin{tcbclipinterior}
        %\shade[inner color=green!80!yellow,outer color=yellow!10!white]
%(interior.north west) circle (2cm);
        \draw[help lines, ystep=\baselineskip, xstep=\linewidth, 
            shift={(interior.north west)}](interior.south west) grid (interior.north east);
        \draw[help lines] ([xshift=.5in]interior.north west)--
            ([xshift=.5in]interior.south west);
        \end{tcbclipinterior}},
    before upper=\vspace{#1\baselineskip}   
    }

\usepackage{lineno}


\begin{document}
\blindtext[1]
\begin{notebook}
\blindtext[3]
\end{notebook}

\begin{notebook}[20]

\end{notebook}
\end{document}

enter image description here

ADDENDUM: As for your additional request: here is something along those lines (partly inspired by this question).

\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{lmodern}
\usepackage{blindtext}
\usepackage{calc}

\newtcolorbox{notebook}[1][0]{
    enhanced,
    breakable,
    colback=green!10,
    colframe=green!65!black,
    left=.7in,
    underlay={%
        \begin{tcbclipinterior}
        %\shade[inner color=green!80!yellow,outer color=yellow!10!white]
%(interior.north west) circle (2cm);
        \draw[help lines, ystep=\baselineskip, xstep=\linewidth, 
            shift={(interior.north west)}](interior.south west) grid (interior.north east);
        \draw[help lines] ([xshift=.5in]interior.north west)--
            ([xshift=.5in]interior.south west);
        \end{tcbclipinterior}},
    before upper={\ifnum#1>0
    \begin{internallinenumbers}\setcounter{linenumber}{1}
    \foreach \X in {1,...,#1}
    {~\par}
    \end{internallinenumbers}
    \fi
    }}

\usepackage{lineno}


\begin{document}
\blindtext[1]
\begin{notebook}
\blindtext[3]
\end{notebook}

\begin{notebook}[20]
\end{notebook}

\begin{notebook}[20]
\end{notebook}

\end{document}

enter image description here

  • Yes, that's part of the question -- the other part is numbering each line of the box. –  Sep 26 '19 at 17:39
  • @Joseph I added something. (To be honest, the line numbering part is not too obvious to me from the question.) –  Sep 26 '19 at 17:54
  • That's great! But the weird thing is, if any text is added inside the box, it goes after the last number... (maybe because of before upper). But anyways, that's enough for me at the moment... –  Sep 26 '19 at 18:28