3

I would like to avoid TikZ or another package. I would like the frame surrounds the page with a rule on all sides and I would like to have a page number below the frame in the middle. I have some difficulties to understand how to use \output and shipout

Alain Matthes
  • 95,075

2 Answers2

6

Plain TeX solution:

\def\frameit#1#2{%
 \vbox{\hrule
  \hbox{%
    \vrule \kern#2pt
      \vbox{\kern#2pt #1
         \kern#2pt}%
      \kern#2pt\vrule}
\hrule}}

\output={%
   \shipout\vbox{%
    \frameit{\box255}9
      \medskip
      \centerline{Test Framed Page}}
  \advancepageno}

\frameit{1}{1}
\bye

For any chance to understand output routines start from plain TeX and the TeXBook. See also this post, where I posted some links to TUGBoat articles about the OTR.

yannisl
  • 117,160
4

You could draw the rules by yourself inside the header and footer. See e.g. the layout package to learn about the exact offsets you have to use.

Here my try which is pretty accurate:

\documentclass{article}

\usepackage{lipsum}
\usepackage{fancyhdr}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}

\pagestyle{fancy}

\lhead{%
    \raisebox{\dimexpr-\headsep-\dp\strutbox\relax}[0pt][0pt]{\rlap{\hbox to \textwidth{\hrulefill}}}%
    \raisebox{\dimexpr-\headsep-\textheight-\dp\strutbox\relax}[0pt][0pt]{\vrule height \textheight}%
}
\rhead{%
    \raisebox{\dimexpr-\headsep-\textheight-\dp\strutbox\relax}[0pt][0pt]{\vrule height \textheight}%
}
\lfoot{%
    \raisebox{\footskip}[0pt][0pt]{\rlap{\hbox to \textwidth{\hrulefill}}}%
}

\begin{document}
\lipsum[1-40]
\end{document}

Result:

Result

Martin Scharrer
  • 262,582
  • Interesting and more clear to understand for me but I prefer to avoid the use of a package. This solution can be useful ! thanks now I need to understand the code from Yiannis – Alain Matthes Apr 10 '11 at 22:22