如何将螺旋延伸至页面边缘

如何将螺旋延伸至页面边缘

如何使用引擎增加图像中的螺旋长度XeLaTeX

\documentclass[12pt,a4paper, openany, notoc]{report}
\usepackage{tikz}
\usepackage[contents={}]{background}
\usepackage{tikzpagenodes}
\usetikzlibrary{shadows,calc,backgrounds}
\usepackage{lipsum}

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

\makeatletter
\define@key{educnotebook}{spiralnumber}{\def\SpiralNumber{#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]current page text area.north west) rectangle
        ([xshift=30pt,yshift=-20pt]current page text area.south east);
    \draw[\MajorGridColor,opacity=0.3]
          ([xshift=30pt,yshift=-20pt]current page text area.south east) grid[step=20mm]
          ([xshift=-30pt,yshift=20pt]current page text area.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]current page text area.north west) rectangle
        ([xshift=30pt,yshift=-20pt]current page text area.south east);
    \draw[\MinorGridColor,opacity=0.3]
          ([xshift=30pt,yshift=-20pt]current page text area.south east) grid[step=1mm]
          ([xshift=-30pt,yshift=20pt]current page text area.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=3pt-\Valor*\textheight/(\SpiralNumber-1)]current page text area.north west)
    }
    \def\RotateAngle{0}
  \or
    \def\SpiralPosition{
      ([xshift=120pt,yshift=-5pt-\Valor*\textheight/(\SpiralNumber-1)]current page text area.north east)%the first number is to shift spirals to page edge
    }
    \def\RotateAngle{180}
    \def\ShadowXshift{-0.5ex}
    \def\ShadowYshift{-0.5ex}
  \or
    \def\SpiralPosition{
      ([yshift=-19pt,xshift=5pt+\Valor*\textwidth/(\SpiralNumber-1)]current page text area.north west)
      }
    \def\RotateAngle{270}
  \fi
}{}

\setkeys{educnotebook}{
  nbcolorbg=white,
  minorgrid=true,%grid
  majorgrid=false,
  minorgridcolor=black!20,
  majorgridcolor=black!60,
  spiralposition=right,
  spiralnumber=28%spiral number
  }
\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[1][]{%
\begingroup
\AddEverypageHook{%
%  \setkeys{educnotebook}{#1}%
%  \backgroundsetup{
%    scale=1,
%    opacity=1,
%    color=black,
%    angle=0,
%    contents={
      \tikz[remember picture,overlay]
      {
      \draw[rounded corners=10pt,fill=white!12,drop shadow={shadow xshift=\ShadowXshift, shadow yshift=\ShadowYshift}]
        ([xshift=-80pt,yshift=120pt]current page text area.north west) rectangle%Xshift = left line and Yshift = top line
        ([xshift=84pt,yshift=-120pt]current page text area.south east);%Xshift = right line and Yshift = botton line
      \foreach \Valor in {0,1,...,\numexpr\SpiralNumber-1\relax}
        \pic at \SpiralPosition {spiral};
      \DrawMajorGrid
      \DrawMinorGrid
      }  
%      }%
%    }
%  \BgMaterial
  }
\endgroup
}

\EducNotebook
\usepackage{xepersian}%-----------for RTL language
\settextfont[Scale=1.3]{Times New Roman}
\setlatintextfont[Scale=1.2]{Times New Roman}
\defpersianfont\Sayeh[Scale=1.3]{Times New Roman} 
\usepackage{ptext}
\begin{document}

在此处输入图片描述

答案1

这是为了让你开心的尝试。大部分内容都是无耻地从Gonzalo 的精彩回答。但是,由于我对这些东西并不熟悉,所以我将所有内容都更改为 pgf 键,因此这仍然是一项重大手术\setkeys(我也不认为它们像 pgf 键一样强大,但这可能是一个不合格的意见)。我测试了它是否可以与 XeLaTeX 和所有软件包一起编译,xepersian但无法判断输出是否正确。一开始有一个表格向您解释了这些键的用途。可以预见,用户希望添加其他选项,但 pgf 键在这方面很棒,因为它们允许我们轻松升级。

\documentclass[12pt,a4paper]{report}
\usepackage{array}
\usepackage{eso-pic}
\usepackage{tikzpagenodes}
\usetikzlibrary{shadows}
\usepackage{lipsum}
\newif\iftikznotebookmajorgrid
\newif\iftikznotebookminorgrid
\tikzset{notebook background/.cd,
left/.initial=30pt,right/.initial=30pt,top/.initial=20pt,bottom/.initial=20pt,
grid left/.initial=10pt,grid right/.initial=10pt,
grid top/.initial=10pt,grid bottom/.initial=10pt,
show major grid/.is if=tikznotebookmajorgrid,
show major grid/.default=true,
major grid/.style={draw=black!60,xstep=20mm,ystep=20mm},
show minor grid/.is if=tikznotebookminorgrid,
show minor grid/.default=true,
minor grid/.style={help lines,xstep=2mm,ystep=2mm},
angle/.initial=0,
spiral number/.initial=20,
spiral position/.is choice,
spiral position/left/.code={\edef\spiralpositioncase{0}},
spiral position/right/.code={\edef\spiralpositioncase{1}},
spiral position/top/.code={\edef\spiralpositioncase{2}},
spiral position=right,
spiral fill ratio/.is choice,
spiral fill ratio/text/.code={\edef\spiralfillratiocase{0}},
spiral fill ratio/paper/.code={\edef\spiralfillratiocase{1}},
spiral fill ratio/fraction of paperheight/.code={\edef\spiralfillratiocase{2}},
spiral fill fraction/.code={\edef\spiralfillratiocase{2}%
\edef\spiralfillratio{#1}},
spiral fill fraction=1,
spiral fill ratio=text,
}
\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\AddNotebookBG[1][]{\AddToShipoutPictureBG{%
\begin{tikzpicture}[overlay,remember picture]
\tikzset{notebook background/.cd,#1}%
\def\pv##1{\pgfkeysvalueof{/tikz/notebook background/##1}}%
\edef\ShadowXshift{0.5ex}
\edef\ShadowYshift{-0.5ex}
\ifcase\spiralfillratiocase
 \def\fillheight{\textheight}
\or
 \def\fillheight{\paperheight}
\or 
 \def\fillheight{\spiralfillratio*\paperheight}
\fi
\ifcase\spiralpositioncase\relax % left,right,top
  \def\SpiralPosition{
    ([xshift=9pt,yshift={3pt-\Valor*\fillheight/(\pv{spiral number}-1)%
    +0.5*\fillheight}]current page text area.west)
  }
  \edef\RotateAngle{0}
\or
  \def\SpiralPosition{
    ([xshift=-9pt,yshift={-5pt-\Valor*\fillheight/(\pv{spiral number}-1)
    +0.5*\fillheight}]current page text area.east)%the first number is to shift spirals to page edge
  }
  \edef\RotateAngle{180}
  \edef\ShadowXshift{-0.5ex}
  \edef\ShadowYshift{-0.5ex}
\or
  \def\SpiralPosition{
    ([yshift=-19pt,xshift={5pt+\Valor*\fillheight/(\pv{spiral number}-1)
    +0.5*\fillheight}]current page text area.north)
    }
  \edef\RotateAngle{270}
\fi
\draw[rounded corners=10pt,fill=white!12,drop shadow={shadow xshift=\ShadowXshift, shadow yshift=\ShadowYshift}]
  ([xshift=-\pv{left},yshift=\pv{top}]current page text area.north west) rectangle%Xshift = left line and Yshift = top line
  ([xshift=\pv{right},yshift=-\pv{bottom}]current page text area.south east);%Xshift = right line and Yshift = botton line
\begin{scope}
\path[clip,rounded corners=10pt]
        ([xshift=-\pv{left}+\pv{grid left},yshift=\pv{top}-\pv{grid top}]current page text area.north west) rectangle
        ([xshift=\pv{right}-\pv{grid right},yshift=-\pv{bottom}+\pv{grid bottom}]current page text area.south east);
\iftikznotebookmajorgrid
 \draw[/tikz/notebook background/major grid]
       ([xshift=\pv{right}-\pv{grid right},yshift=-\pv{bottom}+\pv{grid bottom}]current page text area.south east) 
        grid
       ([xshift=-\pv{left}+\pv{grid left},yshift=\pv{top}-\pv{grid top}]current page text area.north west);
\fi
\iftikznotebookminorgrid
 \draw[/tikz/notebook background/minor grid]
       ([xshift=\pv{right}-\pv{grid right},yshift=-\pv{bottom}+\pv{grid bottom}]current page text area.south east) 
       grid
       ([xshift=-\pv{left}+\pv{grid left},yshift=\pv{top}-\pv{grid top}]current page text area.north west);
\fi
\end{scope}  
\foreach \Valor in {0,1,...,\numexpr\pv{spiral number}-1\relax}
  {\pic at \SpiralPosition {spiral};}
\end{tikzpicture}}}
%
% I have tested this, and it compiles witout error under
% xelatex. Whether the output makes sense I am not able to judge.
% \usepackage{xepersian}%-----------for RTL language
% \settextfont[Scale=1.3]{Times New Roman}
% \setlatintextfont[Scale=1.2]{Times New Roman}
% \defpersianfont\Sayeh[Scale=1.3]{Times New Roman} 
% \usepackage{ptext}

\AddNotebookBG[show minor grid,
show major grid,
spiral position=right,
right=2.2em,
top=2cm,
bottom=2cm,
spiral fill fraction=0.78]

\begin{document}
\begin{center}
\begin{tabular}{>{\ttfamily}lp{0.6\textwidth}}
left & distance between left border of the text area and left border of the
notebook\\
right & distance between rightborder of the text area and left border of the
notebook\\
top & distance between top border of the text area and top border of the
notebook\\
bottom & distance between bottom border of the text area and bottom border of the
notebook\\
grid left & distance between left border of the text area and left border of the
grid\\
grid right & distance between rightborder of the text area and left border of the
grid\\
grid top & distance between top border of the text area and top border of the
grid\\
grid bottom & distance between bottom border of the text area and bottom border of the
grid\\
show major grid & Boolean, if \texttt{true} the major grid will be shown\\
major grid & style of the major grid, initially equal to
\texttt{draw=black!60,xstep=20mm,ystep=20mm}\\
show minor grid & Boolean, if \texttt{true} the major grid will be shown\\
minor grid & style of the minor grid,  initially equal to 
\texttt{help lines,xstep=2mm,ystep=2mm}\\
spiral number & integer number of spirals\\
spiral position & one of \texttt{left}, \texttt{right} or \texttt{top}\\
spiral fill ratio &  one of \texttt{text}, \texttt{paper} or \texttt{fraction}.
if it is \texttt{fraction} then you can choose a fraction of the paper height.\\
spiral fill fraction & fraction of the paper height\\
\end{tabular}
\end{center}

\lipsum[1-20]
\end{document}

在此处输入图片描述

这类代码怪物介于小型软件包和快速答案之间,这种情况经常发生,从长远来看,这确实很难维护,但我试图解决您的问题。这很可能是错误的方法,而且,基于的某些方法更好,但即使tcolorbox如此,人们也必须处理大量的选项。

相关内容