如何给niceframe花边盒子加段落底纹

发布于 2022-05-14 21:09:14

参考了行者老师翻译的文档https://www.latexstudio.net/index/details/index/mid/2387
又参考了雾月大佬的解答https://ask.latexstudio.net/ask/question/7437.html
现有如下代码

\documentclass{ctexart}
\usepackage{zhlipsum}
\usepackage{niceframe}
\usepackage{dingbat}
\usepackage{bbding}
\usepackage{tikz}
\makeatletter
\newlength\this@pgf@bop@width
\newlength\this@pgf@bop@height

\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\ht\csname this@pgf@box@pattern#1\endcsname}%
}
\tikzset{
  box as pattern/.code 2 args={%
    \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}]{\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}

\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}
 {\zhlipsum[1]
 }
\end{document}

我的问题是,在使用niceframe宏包实现花边的前提下,如何使用tikz给花边内的段落加上底纹?

查看更多

关注者
0
被浏览
1.1k
雾月
雾月 2022-05-14
这家伙很懒,什么也没写!

套一个 \tikz\node[]{\parbox{}{...}};。或者用 tcolorbox,可以设置 frame code 和 interior code。

image.png

\documentclass{ctexart}
\usepackage{zhlipsum}
\usepackage{niceframe}
\usepackage{dingbat}
\usepackage{bbding}
\usepackage{tikz}

\makeatletter
\newlength\this@pgf@bop@width
\newlength\this@pgf@bop@height
\def\this@pgf@bop@opacity{1}

\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\ht\csname this@pgf@box@pattern#1\endcsname}%
}
\tikzset{
  box pattern opacity/.code={\def\this@pgf@bop@opacity{#1}},
  box as pattern/.code 2 args={%
    \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={%
      \pgfsetfillopacity{\this@pgf@bop@opacity}%
      \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}]{\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}
\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]}};}

{\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,
     frame empty,nobeforeafter,
     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]
  \end{tcolorbox}}}

\end{document}
1 个回答

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览