我正在尝试创建一个使用 pgfornament 来构建文本的环境,目标是在每个角落都有一个装饰物,并且在每侧都有一个较长的装饰物。
问题是,部分带框文本的长度足以跨越多页。此外,我已将 twocolumn 选项添加到文档类,但我希望带框的文本框能够延伸到整个页面。
我找到了一些几乎可以满足我要求的东西,Martin Scharrer 的回答在文本周围放置一个红色框。如果我将它tikzborder
与strip
cuted 包中的代码结合起来,它可以在多列环境中正常工作。我希望有人能帮助我适应tikzborder
,让我使用 pgfornament 而不是简单的线条。
答案1
我设法用此代码让它工作。这可能不是最好的解决方案,但它确实有效。
\makeatletter
\newcommand{\currentsidemargin}{%
\ifodd\zref@extract{textarea-\thetextarea}{abspage}%
\oddsidemargin%
\else%
\evensidemargin%
\fi%
}
\newcounter{textarea}
\newcommand{\settextarea}{%
\stepcounter{textarea}%
\zlabel{textarea-\thetextarea}%
\begin{tikzpicture}[overlay,remember picture]
% Helper nodes
\path (current page.north west) ++(\hoffset, -\voffset)
node[anchor=north west, shape=rectangle, inner sep=0, minimum width=\paperwidth, minimum height=\paperheight]
(pagearea) {};
\path (pagearea.north west) ++(1in+\currentsidemargin,-1in-\topmargin-\headheight-\headsep)
node[anchor=north west, shape=rectangle, inner sep=0, minimum width=\textwidth, minimum height=\textheight]
(textarea) {};
\end{tikzpicture}%
}
\tikzset{tikzborder/.style={line width=1mm,red,double=blue}}
\newcounter{tikzborder}
\newcounter{tikzborderpages}
\newenvironment{tikzborder}[1][]{%
\medskip\par
% Allow user to overwrite the used style locally
\ifx&\else
\tikzset{tikzborder/.style={#1}}%
\fi
\settextarea
\stepcounter{tikzborder}%
\tikz[overlay,remember picture] \coordinate (tikzborder-\thetikzborder);% Modified \tikzmark macro
\zlabel{tikzborder-begin-\thetikzborder}%
% Test if end-label is at the same page and draw first half of border if not
\ifnum\zref@extract{tikzborder-begin-\thetikzborder}{abspage}=\zref@extract{tikzborder-end-\thetikzborder}{abspage} \else
\begin{tikzpicture}[overlay,remember picture]
\draw [tikzborder]
let \p0 = (textarea.north west), \p1 = (tikzborder-\thetikzborder), \p2 = (textarea.south east) in
node at (\x0-\fboxsep-.5\pgflinewidth,\y2-\fboxsep-.5\pgflinewidth) (SW) {}
node at (\x0-\fboxsep-.5\pgflinewidth,\ht\strutbox+\fboxsep+.5\pgflinewidth) (NW) {}
node at (\x2+\fboxsep+.5\pgflinewidth,\ht\strutbox+\fboxsep+.5\pgflinewidth) (NE) {}
node at (\x2+\fboxsep+.5\pgflinewidth,\y2-\fboxsep-.5\pgflinewidth) (SE) {}
;
\node (CNW) at (NW) {\pgfornament[width=2cm]{61}};
\node (CNE) at (NE) {\pgfornament[width=2cm,symmetry=v]{61}};
\node (CSW) at (SW) {\pgfornament[width=2cm,symmetry=h,opacity=0,color=white]{61}};
\node (CSE) at (SE) {\pgfornament[width=2cm,symmetry=c,opacity=0,color=white]{61}};
\node [shift={(-3.75mm,0mm)}](NELineAnchor) at (CNE.south east){};
\node [shift={(-3.75mm,0mm)}](SELineAnchor) at (CSE.east){};
\node [shift={(4mm,0mm)}](NWLineAnchor) at (CNW.south west){};
\node [shift={(4mm,0mm)}](SWLineAnchor) at (CSW.west){};
\node [shift={(0mm,6mm)}] (NEHeadAnchor) at (CNE.west){};
\node [shift={(0mm,6mm)}] (NWHeadAnchor) at (CNW.east){};
\pgfornamenthline{NWHeadAnchor}{NEHeadAnchor}{north}{46}
\pgfornamentvline{NWLineAnchor}{SWLineAnchor}{west}{88}
\pgfornamentvline{NELineAnchor}{SELineAnchor}{east}{88}
\end{tikzpicture}%
% If it spreads over more than two pages:
\setcounter{tikzborderpages}{\numexpr-\zref@extract{tikzborder-begin-\thetikzborder}{abspage}+\zref@extract{tikzborder-end-\thetikzborder}{abspage}}
\ifnum\value{tikzborderpages}>1
\AtBeginShipoutNext{\tikzborderpage}%
\fi
\fi
}{%
\zlabel{tikzborder-end-\thetikzborder}%
% Test if begin-label is at the same page and draw while border if so
\ifnum\zref@extract{tikzborder-begin-\thetikzborder}{abspage}=\zref@extract{tikzborder-end-\thetikzborder}{abspage}
\begin{tikzpicture}[overlay,remember picture]
\draw [tikzborder]
let \p0 = (textarea.north west), \p1 = (tikzborder-\thetikzborder), \p2 = (textarea.south east) in
node at (\x0-\fboxsep-.5\pgflinewidth,\y1+\ht\strutbox+\fboxsep+.5\pgflinewidth) (NW) {}
node at (\x0-\fboxsep-.5\pgflinewidth,-\dp\strutbox-\fboxsep-.5\pgflinewidth) (SW) {}
node at (\x2+\fboxsep+.5\pgflinewidth,-\dp\strutbox-\fboxsep-.5\pgflinewidth) (SE) {}
node at (\x2+\fboxsep+.5\pgflinewidth,\y1+\ht\strutbox+\fboxsep+.5\pgflinewidth) (NE) {}
;
\node (CNW) at (NW) {\pgfornament[width=2cm]{61}};
\node (CNE) at (NE) {\pgfornament[width=2cm,symmetry=v]{61}};
\node (CSW) at (SW) {\pgfornament[width=2cm,symmetry=h]{61}};
\node (CSE) at (SE) {\pgfornament[width=2cm,symmetry=c]{61}};
\node [shift={(-3.75mm,0mm)}](NELineAnchor) at (CNE.south east){};
\node [shift={(-3.75mm,0mm)}](SELineAnchor) at (CSE.north east){};
\node [shift={(4mm,0mm)}](NWLineAnchor) at (CNW.south west){};
\node [shift={(4mm,0mm)}](SWLineAnchor) at (CSW.north west){};
\node[shift={(-12mm,-9.5mm)}] (SEFootAnchor) at (CSE){};
\node[shift={(12mm,-9.5mm)}] (SWFootAnchor) at (CSW){};
\node[shift={(-12mm,17mm)}] (NEHeadAnchor) at (CNE){};
\node[shift={(12mm,17mm)}] (NWHeadAnchor) at (CNW){};
\pgfornamenthline{NWHeadAnchor}{NEHeadAnchor}{north}{46}
\pgfornamenthline{SWFootAnchor}{SEFootAnchor}{north}{88}
\pgfornamentvline{NWLineAnchor}{SWLineAnchor}{west}{88}
\pgfornamentvline{NELineAnchor}{SELineAnchor}{east}{88}
\end{tikzpicture}%
% Otherwise draw second half of border
\else
\settextarea
\begin{tikzpicture}[overlay,remember picture]
\draw [tikzborder]
let \p0 = (textarea.north west), \p1 = (tikzborder-\thetikzborder), \p2 = (textarea.south east) in
node at (\x0-\fboxsep-.5\pgflinewidth,\y0+\fboxsep+.5\pgflinewidth) (NW) {}
node at (\x0-\fboxsep-.5\pgflinewidth,-\dp\strutbox-\fboxsep-.5\pgflinewidth) (SW) {}
node at (\x2+\fboxsep+.5\pgflinewidth,-\dp\strutbox-\fboxsep-.5\pgflinewidth) (SE) {}
node at (\x2+\fboxsep+.5\pgflinewidth,\y0+\fboxsep+.5\pgflinewidth) (NE) {}
;
\node (CNW) at (NW) {\pgfornament[width=2cm,opacity=0,color=white]{61}};
\node (CNE) at (NE) {\pgfornament[width=2cm,symmetry=v,opacity=0,color=white]{61}};
\node (CSW) at (SW) {\pgfornament[width=2cm,symmetry=h]{61}};
\node (CSE) at (SE) {\pgfornament[width=2cm,symmetry=c]{61}}; %Keeping these for anchorage
\node [shift={(-3.75mm,0mm)}](NELineAnchor) at (CNE.east){};
\node [shift={(-3.75mm,0mm)}](SELineAnchor) at (CSE.north east){};
\node [shift={(4mm,0mm)}](NWLineAnchor) at (CNW.west){};
\node [shift={(4mm,0mm)}](SWLineAnchor) at (CSW.north west){};
\node[shift={(-12mm,-9.5mm)}] (SEFootAnchor) at (CSE){};
\node[shift={(12mm,-9.5mm)}] (SWFootAnchor) at (CSW){};
\pgfornamenthline{SWFootAnchor}{SEFootAnchor}{north}{88}
\pgfornamentvline{NWLineAnchor}{SWLineAnchor}{west}{88}
\pgfornamentvline{NELineAnchor}{SELineAnchor}{east}{88}
\end{tikzpicture}%
\fi
\par\medskip
}
\newcommand{\tikzborderpage}{%
\settextarea
\begin{tikzpicture}[overlay,remember picture]
\draw [tikzborder]
([shift={(-\fboxsep-.5\pgflinewidth, \fboxsep+.5\pgflinewidth)}]textarea.north west)
--
([shift={(-\fboxsep-.5\pgflinewidth,-\fboxsep-.5\pgflinewidth)}]textarea.south west)
;
\draw [tikzborder]
([shift={( \fboxsep+.5\pgflinewidth, \fboxsep+.5\pgflinewidth)}]textarea.north east)
--
([shift={( \fboxsep+.5\pgflinewidth,-\fboxsep-.5\pgflinewidth)}]textarea.south east)
;
\end{tikzpicture}%
\addtocounter{tikzborderpages}{-1}%
\ifnum\value{tikzborderpages}>1
\AtBeginShipoutNext{\tikzborderpage}%
\fi
\vspace{-\baselineskip}% Compensate for the generated extra line at begin of the page. No idea why exactly this happens. Also \baselineskip seems not to be 100% right.
}
\newenvironment{fancyframedtext}{\begin{strip}\\\\\\\begin{tikzborder}}{\end{tikzborder} \hfill\break\hfill\break\hfill\break\hfill\break \end{strip}}
\makeatother
答案2
逆向工程成 MWE,就是这样的。
twocolumn
无论如何,在模式下,某些地方可能需要手动调整间距。
双页框架
单页框架
平均能量损失
\documentclass{article}
\usepackage{refcount}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing,calc}
\usepackage{pgfornament}
\usepackage{kantlipsum}
\usepackage{cuted}
\usepackage{zref-abspos}
\usepackage{zref-user}
\makeatletter
\newcommand{\currentsidemargin}{%
\ifodd\zref@extract{textarea-\thetextarea}{abspage}%
\oddsidemargin%
\else%
\evensidemargin%
\fi%
}
\newcounter{textarea}
\newcommand{\settextarea}{%
\stepcounter{textarea}%
\zlabel{textarea-\thetextarea}%
\begin{tikzpicture}[overlay,remember picture]
% Helper nodes
\path (current page.north west) ++(\hoffset, -\voffset)
node[anchor=north west, shape=rectangle, inner sep=0, minimum width=\paperwidth, minimum height=\paperheight]
(pagearea) {};
\path (pagearea.north west) ++(1in+\currentsidemargin,-1in-\topmargin-\headheight-\headsep)
node[anchor=north west, shape=rectangle, inner sep=0, minimum width=\textwidth, minimum height=\textheight]
(textarea) {};
\end{tikzpicture}%
}
\tikzset{tikzborder/.style={line width=1mm,red,double=blue}}
\newcounter{tikzborder}
\newcounter{tikzborderpages}
\newenvironment{tikzborder}[1][]{%
\medskip\par
% Allow user to overwrite the used style locally
\ifx&\else
\tikzset{tikzborder/.style={#1}}%
\fi
\settextarea
\stepcounter{tikzborder}%
\tikz[overlay,remember picture] \coordinate (tikzborder-\thetikzborder);% Modified \tikzmark macro
\zlabel{tikzborder-begin-\thetikzborder}%
% Test if end-label is at the same page and draw first half of border if not
\ifnum\zref@extract{tikzborder-begin-\thetikzborder}{abspage}=\zref@extract{tikzborder-end-\thetikzborder}{abspage} \else
\begin{tikzpicture}[overlay,remember picture]
\draw [tikzborder]
let \p0 = (textarea.north west), \p1 = (tikzborder-\thetikzborder), \p2 = (textarea.south east) in
node at (\x0-\fboxsep-.5\pgflinewidth,\y2-\fboxsep-.5\pgflinewidth) (SW) {}
node at (\x0-\fboxsep-.5\pgflinewidth,\ht\strutbox+\fboxsep+.5\pgflinewidth) (NW) {}
node at (\x2+\fboxsep+.5\pgflinewidth,\ht\strutbox+\fboxsep+.5\pgflinewidth) (NE) {}
node at (\x2+\fboxsep+.5\pgflinewidth,\y2-\fboxsep-.5\pgflinewidth) (SE) {}
;
\node (CNW) at (NW) {\pgfornament[width=2cm]{61}};
\node (CNE) at (NE) {\pgfornament[width=2cm,symmetry=v]{61}};
\node (CSW) at (SW) {\pgfornament[width=2cm,symmetry=h,opacity=0,color=white]{61}};
\node (CSE) at (SE) {\pgfornament[width=2cm,symmetry=c,opacity=0,color=white]{61}};
\node [shift={(-3.75mm,0mm)}](NELineAnchor) at (CNE.south east){};
\node [shift={(-3.75mm,0mm)}](SELineAnchor) at (CSE.east){};
\node [shift={(4mm,0mm)}](NWLineAnchor) at (CNW.south west){};
\node [shift={(4mm,0mm)}](SWLineAnchor) at (CSW.west){};
\node [shift={(0mm,6mm)}] (NEHeadAnchor) at (CNE.west){};
\node [shift={(0mm,6mm)}] (NWHeadAnchor) at (CNW.east){};
\pgfornamenthline{NWHeadAnchor}{NEHeadAnchor}{north}{46}
\pgfornamentvline{NWLineAnchor}{SWLineAnchor}{west}{88}
\pgfornamentvline{NELineAnchor}{SELineAnchor}{east}{88}
\end{tikzpicture}%
% If it spreads over more than two pages:
\setcounter{tikzborderpages}{\numexpr-\zref@extract{tikzborder-begin-\thetikzborder}{abspage}+\zref@extract{tikzborder-end-\thetikzborder}{abspage}}
\ifnum\value{tikzborderpages}>1
\AtBeginShipoutNext{\tikzborderpage}%
\fi
\fi
}{%
\zlabel{tikzborder-end-\thetikzborder}%
% Test if begin-label is at the same page and draw while border if so
\ifnum\zref@extract{tikzborder-begin-\thetikzborder}{abspage}=\zref@extract{tikzborder-end-\thetikzborder}{abspage}
\begin{tikzpicture}[overlay,remember picture]
\draw [tikzborder]
let \p0 = (textarea.north west), \p1 = (tikzborder-\thetikzborder), \p2 = (textarea.south east) in
node at (\x0-\fboxsep-.5\pgflinewidth,\y1+\ht\strutbox+\fboxsep+.5\pgflinewidth) (NW) {}
node at (\x0-\fboxsep-.5\pgflinewidth,-\dp\strutbox-\fboxsep-.5\pgflinewidth) (SW) {}
node at (\x2+\fboxsep+.5\pgflinewidth,-\dp\strutbox-\fboxsep-.5\pgflinewidth) (SE) {}
node at (\x2+\fboxsep+.5\pgflinewidth,\y1+\ht\strutbox+\fboxsep+.5\pgflinewidth) (NE) {}
;
\node (CNW) at (NW) {\pgfornament[width=2cm]{61}};
\node (CNE) at (NE) {\pgfornament[width=2cm,symmetry=v]{61}};
\node (CSW) at (SW) {\pgfornament[width=2cm,symmetry=h]{61}};
\node (CSE) at (SE) {\pgfornament[width=2cm,symmetry=c]{61}};
\node [shift={(-3.75mm,0mm)}](NELineAnchor) at (CNE.south east){};
\node [shift={(-3.75mm,0mm)}](SELineAnchor) at (CSE.north east){};
\node [shift={(4mm,0mm)}](NWLineAnchor) at (CNW.south west){};
\node [shift={(4mm,0mm)}](SWLineAnchor) at (CSW.north west){};
\node[shift={(-12mm,-9.5mm)}] (SEFootAnchor) at (CSE){};
\node[shift={(12mm,-9.5mm)}] (SWFootAnchor) at (CSW){};
\node[shift={(-12mm,17mm)}] (NEHeadAnchor) at (CNE){};
\node[shift={(12mm,17mm)}] (NWHeadAnchor) at (CNW){};
\pgfornamenthline{NWHeadAnchor}{NEHeadAnchor}{north}{46}
\pgfornamenthline{SWFootAnchor}{SEFootAnchor}{north}{88}
\pgfornamentvline{NWLineAnchor}{SWLineAnchor}{west}{88}
\pgfornamentvline{NELineAnchor}{SELineAnchor}{east}{88}
\end{tikzpicture}%
% Otherwise draw second half of border
\else
\settextarea
\begin{tikzpicture}[overlay,remember picture]
\draw [tikzborder]
let \p0 = (textarea.north west), \p1 = (tikzborder-\thetikzborder), \p2 = (textarea.south east) in
node at (\x0-\fboxsep-.5\pgflinewidth,\y0+\fboxsep+.5\pgflinewidth) (NW) {}
node at (\x0-\fboxsep-.5\pgflinewidth,-\dp\strutbox-\fboxsep-.5\pgflinewidth) (SW) {}
node at (\x2+\fboxsep+.5\pgflinewidth,-\dp\strutbox-\fboxsep-.5\pgflinewidth) (SE) {}
node at (\x2+\fboxsep+.5\pgflinewidth,\y0+\fboxsep+.5\pgflinewidth) (NE) {}
;
\node (CNW) at (NW) {\pgfornament[width=2cm,opacity=0,color=white]{61}};
\node (CNE) at (NE) {\pgfornament[width=2cm,symmetry=v,opacity=0,color=white]{61}};
\node (CSW) at (SW) {\pgfornament[width=2cm,symmetry=h]{61}};
\node (CSE) at (SE) {\pgfornament[width=2cm,symmetry=c]{61}}; %Keeping these for anchorage
\node [shift={(-3.75mm,0mm)}](NELineAnchor) at (CNE.east){};
\node [shift={(-3.75mm,0mm)}](SELineAnchor) at (CSE.north east){};
\node [shift={(4mm,0mm)}](NWLineAnchor) at (CNW.west){};
\node [shift={(4mm,0mm)}](SWLineAnchor) at (CSW.north west){};
\node[shift={(-12mm,-9.5mm)}] (SEFootAnchor) at (CSE){};
\node[shift={(12mm,-9.5mm)}] (SWFootAnchor) at (CSW){};
\pgfornamenthline{SWFootAnchor}{SEFootAnchor}{north}{88}
\pgfornamentvline{NWLineAnchor}{SWLineAnchor}{west}{88}
\pgfornamentvline{NELineAnchor}{SELineAnchor}{east}{88}
\end{tikzpicture}%
\fi
\par\medskip
}
\newcommand{\tikzborderpage}{%
\settextarea
\begin{tikzpicture}[overlay,remember picture]
\draw [tikzborder]
([shift={(-\fboxsep-.5\pgflinewidth, \fboxsep+.5\pgflinewidth)}]textarea.north west)
--
([shift={(-\fboxsep-.5\pgflinewidth,-\fboxsep-.5\pgflinewidth)}]textarea.south west)
;
\draw [tikzborder]
([shift={( \fboxsep+.5\pgflinewidth, \fboxsep+.5\pgflinewidth)}]textarea.north east)
--
([shift={( \fboxsep+.5\pgflinewidth,-\fboxsep-.5\pgflinewidth)}]textarea.south east)
;
\end{tikzpicture}%
\addtocounter{tikzborderpages}{-1}%
\ifnum\value{tikzborderpages}>1
\AtBeginShipoutNext{\tikzborderpage}%
\fi
\vspace{-\baselineskip}% Compensate for the generated extra line at begin of the page. No idea why exactly this happens. Also \baselineskip seems not to be 100% right.
}
\newenvironment{fancyframedtext}{\begin{strip}\\\\\\\begin{tikzborder}}{\end{tikzborder} \hfill\break\hfill\break\hfill\break\hfill\break \end{strip}}
\makeatother
\twocolumn
\begin{document}
\kant[1-5]
\begin{fancyframedtext}
\ \par\kant[1-3]
\end{fancyframedtext}
\kant[1]\kant[1]\kant[1]\kant[1]\kant[1]\kant[1]
\begin{fancyframedtext}
\kant[1]
\end{fancyframedtext}
\kant[1-3]
\end{document}