工作室https://www.latexstudio.net/index/details/index/mid/2629.html 给出了实现花边底纹的三种方法。其中,对于底纹,给出了box pattern opacity 用于设置透明度,我的问题是如何再完善一些,可以设置底纹的颜色和大小。
\documentclass{ctexart}
\usepackage{zhlipsum}
\usepackage{niceframe}
\usepackage{dingbat}
\usepackage{bbding}
\usepackage{tikz}
\usepackage[margin=2cm]{geometry}
\makeatletter
\newlength\this@pgf@bop@width
\newlength\this@pgf@bop@height
\def\this@pgf@bop@color{black}
\def\this@pgf@bop@opacity{1}
\def\this@pgf@bop@xscale{1}
\def\this@pgf@bop@yscale{1}
\ExplSyntaxOn
\cs_new_protected:Npn \this@pgf@bop@setscale #1
{
\box_scale:cnn { this@pgf@box@pattern #1 }
{ \this@pgf@bop@xscale } { \this@pgf@bop@yscale }
\tl_set:cx { this@pgf@bop@#1@width } { \box_wd:c { this@pgf@box@pattern#1 } }
\tl_set:cx { this@pgf@bop@#1@height } { \box_ht_plus_dp:c { this@pgf@box@pattern#1 } }
}
\ExplSyntaxOff
\def\setboxaspattern#1#2{\expandafter\newbox\csname this@pgf@box@pattern#1\endcsname
\expandafter\setbox\csname this@pgf@box@pattern#1\endcsname\hbox{#2}%
\expandafter\edef\csname this@pgf@bop@#1@width\endcsname{\the\wd\csname this@pgf@box@pattern#1\endcsname}%
\expandafter\edef\csname this@pgf@bop@#1@height\endcsname{\the\dimexpr\ht\csname this@pgf@box@pattern#1\endcsname+\dp\csname this@pgf@box@pattern#1\endcsname}%
}
\tikzset{
box pattern xscale/.code={\def\this@pgf@bop@xscale{#1}},
box pattern yscale/.code={\def\this@pgf@bop@yscale{#1}},
box pattern scale/.code={\def\this@pgf@bop@xscale{#1}\def\this@pgf@bop@yscale{#1}},
box pattern color/.code={\def\this@pgf@bop@color{#1}},
box pattern opacity/.code={\def\this@pgf@bop@opacity{#1}},
box as pattern/.code 2 args={%
\this@pgf@bop@setscale{#2}%
\expandafter\this@pgf@bop@width\csname this@pgf@bop@#2@width\endcsname
\expandafter\this@pgf@bop@height\csname this@pgf@bop@#2@height\endcsname
\pgfkeysalso{/tikz/path picture={%
\pgf@process{\pgfpointanchor{path picture bounding box}{north east}}%
\pgf@xa\pgf@x \pgf@ya\pgf@y
\pgf@process{\pgfpointanchor{path picture bounding box}{south west}}%
\pgf@xb\pgf@x \pgf@yb\pgf@y \pgf@yc\pgf@yb
\pgfutil@loop
{%
\pgfutil@loop
\expandafter\pgftext\expandafter[#1,at=\pgfqpoint{\pgf@xb}{\pgf@yb}]{%
\pgfsetfillcolor{\this@pgf@bop@color}%
\pgfsetfillopacity{\this@pgf@bop@opacity}%
\copy\csname this@pgf@box@pattern#2\endcsname}%
\ifdim\pgf@yb<\pgf@ya
\advance\pgf@yb\this@pgf@bop@height
\pgfutil@repeat
}%
\ifdim\pgf@xb<\pgf@xa
\advance\pgf@xb\this@pgf@bop@width
\pgf@yb\pgf@yc
\pgfutil@repeat
}}%
}
}
\makeatother
\setboxaspattern{hua}{\FourClowerOpen}
\usepackage[many]{tcolorbox}
\usetikzlibrary{decorations,decorations.markings}
\begin{document}
\font\border=karta15
\generalframe
{\border\char'307}{\border\char'324}{\border\char'322}
{\border\char'310} {\border\char'323}
{\border\char'174}{\border\char'325}{\border\char'175}
{\noindent\tikz\node[box pattern opacity=0.4, box as pattern={}{hua}]
{\parbox{\dimexpr\textwidth-40pt-4\fboxsep}{\parindent=2\ccwd \zhlipsum[1][name=zhufu]}};}
{\setlength\fboxsep{0pt}
\generalframe
{\border\char'307}{\border\char'324}{\border\char'322}
{\border\char'310} {\border\char'323}
{\border\char'174}{\border\char'325}{\border\char'175}
{\parindent=0pt
\begin{tcolorbox}[width=\textwidth-3.28em-4\fboxsep,left=2mm,right=2mm,enhanced,nobeforeafter,
frame empty,
interior code={\path[draw=white,fill=white,box pattern opacity=0.3, box as pattern={}{hua}]
(interior.south west) rectangle (interior.north east);},
]
\parindent=2\ccwd
\zhlipsum[1][name=zhufu]
\end{tcolorbox}}}
\makeatletter
\tcbset{arrow frame decoration/.style={
frame empty,
before skip=1em plus 5pt, after skip=1em plus 5pt,
overlay={%
\draw[decorate,decoration={
markings, mark=between positions 0.07 and 0.97 step 1.2em with
{\pgftext{\border\char'325}}}](frame.north west)--(frame.south west);
\draw[decorate,decoration={
markings, mark=between positions 0.07 and 0.97 step 1.2em with
{\pgftext{\border\char'324}}}](frame.north east)--(frame.south east);
\draw[decorate,decoration={
markings, mark=between positions 0.03 and 0.97 step {\dimexpr\kvtcb@width/(\numexpr\linewidth/\dimexpr1.5em\relax)} with
{\pgftext{\border\char'324}}}](frame.north west)--(frame.north east);
\draw[decorate,decoration={
markings, mark=between positions 0.03 and 0.97 step {\dimexpr\kvtcb@width/(\numexpr\linewidth/\dimexpr1.5em\relax)} with
{\pgftext{\border\char'325}}}](frame.south west)--(frame.south east);
\path node at([yshift=-.2ex]frame.south west) {\border\char'174}
node at([yshift=-.2ex]frame.south east) {\border\char'175}
node at([yshift=-.2ex]frame.north west) {\border\char'307}
node at([yshift=-.2ex]frame.north east) {\border\char'322};
},
},}
\makeatother
\newtcolorbox{arrowframe}[2][]{left=2mm,right=2mm,enhanced,arrow frame decoration,
interior code={\path[draw=white,fill=white,
box pattern opacity=.5,box pattern color=red,box pattern scale=1.5,
box as pattern={}{#2}]
([xshift=1ex,yshift=1ex]interior.south west) rectangle
([xshift=-1ex,yshift=-1ex]interior.north east);},#1}
\begin{arrowframe}{hua}
\parindent=2\ccwd
\zhlipsum[1]
\end{arrowframe}
\end{document}
我这边编译报错,是否与texlive2021的版本有关?
@u7483 我用2022没有报错。
报错原因是什么?
@u10307 Undefined control sequence. ...indent=2ccwd zhlipsum1}};}
Missing number, treated as zero. ...indent=2ccwd zhlipsum1}};}
Illegal unit of measure (pt inserted). ...indent=2ccwd zhlipsum1}};}
@u7483
\this@pgf@bop@setscale
改成这样试试@u10307 修改后没问题了,可能是版本的问题