I want to produce a page containing a single box which should be
physically centered in the page. I used the following:
\nopagenumbers%
\parindent=0pt%
\mathsurround=0pt%
\setbox0=\vbox{\hrule width 5truecm\hbox to 5truecm{%
\vrule height 10 truecm \hfill\vrule height 10 truecm}%
\hrule width 5truecm}%
%
\null\vfill%
$\vcenter{\hbox to \hsize{\hss\copy0\hss}}$%
\vfill%
\bye
What I obtain is somewhat centered in the page, but not perfectly.
I guess that there is some other surrounding space or margin: which? How
do I get rid of them?
Thanks in advance for any help.
Fabio
You use plain TeX without saying it. A much simpler solution with LaTeX
for the same result would be :
% ------------------------------------------------------
\documentclass[a4paper,french]{article}
\usepackage{xcolor}
\begin{document}
{\hfill\boxframe{5truecm}{10truecm}{0pt}\hfill\null
}
\end{document}\endinput
% ------------------------------------------------------
Now i don't know what you want to do exactly: if you box is like
a frame / a float which is inserted in the middle of your text, then
it is expected to be centered relatively to the margins, not to the
paper sheet... This is the case.
Conversely if your box is intended to be used as a "background", it
could be interesting to center it according to the paper sheet. In this
case, i would use atbegshi package:
\AtBeginShipoutNext{\AtBeginShipoutUpperLeft{....}}
and then the game consist in writting the { .... } stuff (which should
not be too difficult) or have a look at eso-pic or wallpaper packages,
which do the same with a higher level interface.
> Fabio
i could have been more precise if i had an example in LaTeX...
Yours sincerely.
I said it in the subject: I thought it was clear enough...
> Now i don't know what you want to do exactly:
What I want is to produce a single page with given dimensions
(I didn't specify this, restricting myself to the default dimensions)
containing a single (rectangular) box (saved in box0)
placed physically in the page so that the
intersection between the diagonals of the box coincides with the
intersection of the diagonals of the page.
> i could have been more precise if i had an example in LaTeX...
Well, I wanted to do it in plain... :-(
And in a way as simple as possible.
It shouldn't be very different in LaTeX.
The rows I provided are a working example (in plain) which produces
something close to what I want, but not exactly.
Thank you for your attention.
Fabio
It depends on the dimensions of the physical page; I assume
A4 paper.
===
\hoffset=-1truein
\voffset=-1truein
\setbox0=\vbox{\hrule width 5truecm\hbox to 5truecm{%
\vrule height 10 truecm \hfill\vrule height 10 truecm}%
\hrule width 5truecm}%
\shipout\vbox to 29.7cm{\hsize=21cm
\vglue 0pt plus 1fill
\centerline{\copy0}
\vglue 0pt plus 1fill}
\bye
===
Ciao
Enrico
I thought it could be done without specifying the dimensions but I see
that in your example you need them to set the vbox used in the shipout.
Then, ok: let's assume A4.
>
>===
> \hoffset=-1truein
> \voffset=-1truein
>
> \setbox0=\vbox{\hrule width 5truecm\hbox to 5truecm{%
> \vrule height 10 truecm \hfill\vrule height 10 truecm}%
> \hrule width 5truecm}%
>
> \shipout\vbox to 29.7cm{\hsize=21cm
> \vglue 0pt plus 1fill
> \centerline{\copy0}
> \vglue 0pt plus 1fill}
> \bye
>===
This seems to work. I mean: on the screen the output looks perfectly
centered. On the printed page it is orizontally centered but there is a
small vertical offset (about 4 mm). Maybe that this offset is due to my
inkjet printer.
I guess from the above that there is a default 1 inch vertical margin and
the same horizontally, isn't it?
Does this remain true even if I define different \hsize and \vsize for the
document?
Thanks a lot.
Ciao
Fabio
> > It depends on the dimensions of the physical page; I assume
> > A4 paper.
>
> I thought it could be done without specifying the dimensions but I see
> that in your example you need them to set the vbox used in the shipout.
> Then, ok: let's assume A4.
>
> >
> >===
> > \hoffset=-1truein
> > \voffset=-1truein
> >
> > \setbox0=\vbox{\hrule width 5truecm\hbox to 5truecm{%
> > \vrule height 10 truecm \hfill\vrule height 10 truecm}%
> > \hrule width 5truecm}%
> >
> > \shipout\vbox to 29.7cm{\hsize=21cm
> > \vglue 0pt plus 1fill
> > \centerline{\copy0}
> > \vglue 0pt plus 1fill}
> > \bye
> >===
>
> This seems to work. I mean: on the screen the output looks perfectly
> centered. On the printed page it is orizontally centered but there is a
> small vertical offset (about 4 mm). Maybe that this offset is due to my
> inkjet printer.
Small offsets due to printers are common, unfortunately. Since the
first and last items in your box are rules, I guess the box should be
centered.
> I guess from the above that there is a default 1 inch vertical margin and
> the same horizontally, isn't it?
> Does this remain true even if I define different \hsize and \vsize for the
> document?
Yes, that's a default defined by D. E. Knuth for the dvi output
that has been retained for compatibility also with pdf output.
Actually pdftex has a couple of primitives for this, \pdfhorigin
and \pdfvorigin, which are set to 1 (true) inch at format
generation.
Ciao
Enrico
There are two sources of space that you might not have taken
into account:
1. The standard \vsize in plain TeX is 8.9 inches. This amounts
to an extra 0.1 inch of space at the bottom of the page, assuming
usletter paper and the usual one-inch offset at the top.
2. The \null at the top of your page actually takes up \topskip of
space (default10pt).
So:
-- -if \vsize is 8.9in (usletter paper)
put \vskip.1in above the box OR put \vskip-.1in below the box.
-- put \vskip-\topskip above the box OR put \vskip\topskip below the
box.
Note: LaTeX has \topskip also, so it is no better at centering
material
than plain TeX.
Dan