5

my code save groups inside environment topr and topl to two sbox , the command \border draw a frame devided into two parts and put in them the two sbox , here is my MWE

\documentclass{article}
\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{calc}
\pagestyle{empty}
\newsavebox{\textone}
\newsavebox{\texttwo}

\newenvironment{topr}{%
  \begin{lrbox}{\textone}%
  \begin{minipage}{11cm}%
  \raggedleft 
}{%
  \end{minipage}%
  \end{lrbox}%
  % export box register setting outside the scope of the environment
  \global\setbox\textone=\copy\textone
}

\newenvironment{topl}{%
  \begin{lrbox}{\texttwo}%
  \begin{minipage}{5cm}%
  \raggedleft 
}{%
  \end{minipage}%
  \end{lrbox}%
  % export box register setting outside the scope of the environment
  \global\setbox\texttwo=\copy\texttwo
}

\newcommand{\border}{%

  \begin{tikzpicture}[remember picture, overlay]

    % Coordinates of the external frame
    \coordinate (top) at ($(current page.north)+(0,-1.5)$);
    \coordinate (bottom) at ($(current page.south)+(0,1.5)$);
    \coordinate (left) at ($(current page.west)+(1.5,0)$);
    \coordinate (right) at ($(current page.east)+(-1.5,0)$);

    % Coordinates of the horizontal parts
    \coordinate (left part) at ($(left)!.33!(right)$);

    % Frame around
    \draw[red] (bottom-|left) rectangle (top-|right);

    % Vertical lines
    \draw[red] (top-|left part) -- (bottom-|left part);

    \node at ($(top-|right)+(-0.3,-0.3)$)[anchor=north east]{\usebox{\textone}};
    \node at ($(top-|left part)+(-0.3,-0.3)$)[anchor=north east]{\usebox{\texttwo}};      

 \end{tikzpicture}}

\begin{document}

\begin{topr}
 \lipsum[1]
\end{topr}

\begin{topl}
 \lipsum[2]
\end{topl}

\border  

\newpage

\border 

\end{document} 

We get

enter image description here

I would like to ameliorate this macro So that can be implemented to every page of my document , and without saying \border for every page , Wipe text in the sbox At each transition from one page to another .

Salim Bou
  • 17,021
  • 2
  • 31
  • 76
  • You should be able to do this using the atbegshi package. –  Jul 19 '14 at 08:27
  • I don't know what you want to achieve, but there is a KOMA-Script package scrlayer which lets you have multiple columns of text. And also scrlayer-notecolumn might be what you want. – Manuel Jul 19 '14 at 11:57
  • i would like a document where all pages have the same frame Shown above Except the first page Illustrated in link , Where can I put the text in each of the two parts with distinct environment topr and topl – Salim Bou Jul 19 '14 at 13:16

1 Answers1

2

I suggest using eso-pic which allows you to add content at page shipout using a number of different macros:

enter image description here

\documentclass{article}
\usepackage{lipsum}
\usepackage{tikz,eso-pic}
\usetikzlibrary{calc}
\pagestyle{empty}
\newsavebox{\textone}
\newsavebox{\texttwo}

\newenvironment{topr}{%
  \begin{lrbox}{\textone}%
  \begin{minipage}{11cm}%
  \raggedleft 
}{%
  \end{minipage}%
  \end{lrbox}%
  % export box register setting outside the scope of the environment
  \global\setbox\textone=\copy\textone
}

\newenvironment{topl}{%
  \begin{lrbox}{\texttwo}%
  \begin{minipage}{5cm}%
  \raggedleft 
}{%
  \end{minipage}%
  \end{lrbox}%
  % export box register setting outside the scope of the environment
  \global\setbox\texttwo=\copy\texttwo%
  \mbox{}% Just set something on the page
}

\newcommand{\border}{%
  \begin{tikzpicture}[remember picture, overlay]
    % Coordinates of the external frame
    \coordinate (top) at ($(current page.north)+(0,-1.5)$);
    \coordinate (bottom) at ($(current page.south)+(0,1.5)$);
    \coordinate (left) at ($(current page.west)+(1.5,0)$);
    \coordinate (right) at ($(current page.east)+(-1.5,0)$);

    % Coordinates of the horizontal parts
    \coordinate (left part) at ($(left)!.33!(right)$);

    % Frame around
    \draw[red] (bottom-|left) rectangle (top-|right);

    % Vertical lines
    \draw[red] (top-|left part) -- (bottom-|left part);

    \node at ($(top-|right)+(-0.3,-0.3)$)[anchor=north east]{\usebox{\textone}};
    \node at ($(top-|left part)+(-0.3,-0.3)$)[anchor=north east]{\usebox{\texttwo}};      
  \end{tikzpicture}}

\begin{document}

{\Huge This is a different first page.}

\newpage

\makeatletter
\AddToShipoutPictureFG{%
  \ifdim\dimexpr\ht\textone+\ht\texttwo=0pt\else
    \border
    \global\setbox\textone=\copy\voidb@x
    \global\setbox\texttwo=\copy\voidb@x
  \fi}
\makeatother

\begin{topr}
 \lipsum[1]
\end{topr}

\begin{topl}
 \lipsum[2]
\end{topl}

\newpage

\begin{topr}
 \lipsum[2]
\end{topr}

\begin{topl}
 \lipsum[1]
\end{topl}

\end{document} 
Werner
  • 603,163