2

I'm trying to create an environment that will frame text using pgfornament, the goal is to have one ornament in each corner, and a longer ornament on each side.

The catch is that some of this framed text will be long enough to span multiple pages. In addition I have added twocolumn option to the document class, but I want the framed box to stretch across the entire page.

I've found something that almost does what I want, Martin Scharrer's answer here puts a red box around text. If I combine his tikzborder with strip from the cuted package it works fine with the multicolumn environment. I was hoping someone could help me adapt tikzborder to let me use pgfornament instead of a simple line.

  • 1
    There are many more posts of this sort, e.g. this one. And it would be helpful if you provide an example with all the ornaments in it that show what you already have achieved. –  Sep 07 '18 at 23:06
  • Do you mean the breakable option of the [tag:tcolorbox] package? Because that package allows you to customize the style freely. – Symbol 1 Sep 09 '18 at 20:33

2 Answers2

1

I managed to get it working with this code. This probably isn't the best solution, but it worked.

\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&#1&\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
1

Reverse-engineered into an MWE, such as it is.

Some manual adjustment of the spacing could be required in places, in twocolumn mode anyway.

two-page frame

two

one-page frame

one

MWE

\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&#1&\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}

Cicada
  • 10,129