From: tvz@zandtwerk.Princeton.EDU (Timothy Van Zandt)
Newsgroups: comp.text.tex
Subject: Re: want TeX macro for landscape printing
Date: 6 Oct 92 10:48:08 GMT
Distribution: na
Organization: Princeton University

In article <6407@dciem.dciem.dnd.ca> robbie@dciem.dciem.dnd.ca (G.Robert Arrabito) writes:
>
>Does anyone have a TeX macro to 
>facilitate switching between
>    portrait and landscape printing.
>
>Robert Arrabito
>e-mail: robbie@dretor.dciem.dnd.ca

Here is an explanation from the User's Guide for PSTricks (v0.92,
now available in .tar.Z format from the /pub directory at Princeton.EDU).
It should work with any PostScript rotation macros, not just those
in PSTricks.

-- Tim


 \faq{How do I rotate a \LaTeX" \t{table} or \t{figure} environment by 90
degrees?\label{rottable}}

 The common mistake is to put the whole |table| or |figure| environment inside
a \N{Rotateleft} or \N{Rotateright} environment (or \N\rotateleft" or
\N\rotateright" command). Instead, what you want to do is put everything that
is {\em inside} the environment (including the |\caption|, if you want that
rotated too) inside a |minipage| of the desired width, and then put the
minipage inside the \N\rotateleft" command.

 Remember that the width of the minipage is the height of the rotated table or
figure. You also have to decided how you want to horizontally position the
rotated |table| or |figure| on the page; typically you want to center it.

For example,
\begin{verbatim}
\begin{table}
  \begin{center}
    \begin{Rotateleft}
      \begin{minipage}{7in}
        \begin{center}
          \begin{tabular}{rcl}
            Blah & Blah & Blah
          \end{tabular}
        \end{center}
        \caption{This is a table of blah}
      \end{minipage}
    \end{Rotateleft}
  \end{center}
\end{table}
\end{verbatim}
 It is the outer |center| environment that centers the rotated |table|
horizontally.

If you do this a lot, you might want to define an environment like:
\begin{verbatim}
\newenvironment{tableleft}%
  {\begin{table}\begin{center}\begin{Rotateleft}\begin{minipage}}%
  {\end{minipage}\end{Rotateleft}\end{center}\end{table}}
\end{verbatim}
(Don't forget the |%| signs.) Then the preceding example becomes:
\begin{verbatim}
\begin{tableleft}{7in}
  \begin{center}
    \begin{tabular}{rcl}
      Blah & Blah & Blah
    \end{tabular}
  \end{center}
  \caption{This is a table of blah}
\end{tableleft}
\end{verbatim}

Most commonly, you want to put a table on a page by itself in landscape mode,
 centered both horizontally and vertically. Then the width of the minipage
should be |\textheight|. You might define an environment like:
\begin{verbatim}
\newenvironment{landtable}%
  {\begin{table}[p]\begin{center}\begin{Rotateleft}%
    \begin{minipage}{\textwidth}\begin{center}}%
  {\end{center}\end{minipage}\end{Rotateleft}\end{center}\end{table}}
\end{verbatim}
Then the preceding example becomes:
\begin{verbatim}
\begin{landtable}
  \begin{tabular}{rcl}
    Blah & Blah & Blah
  \end{tabular}
  \caption{This is a table of blah}
\end{landtable}
\end{verbatim}
 If the document is originally in landscape mode, then |landtable| creates a
portrait-mode table environment.

\faq{How do I switch temporarily into landscape mode?}

 If you just want to rotate the contents of a single page, without rotating
the headers and footers, then look to the answer to Question \ref{rottable}
for inspiration.

 Here is a hack that switches into landscape mode, assuming that (i) you want
to rotate the pages by 90 degrees so that they face to the right, (ii) you are
using 8.5x11 inch paper, and (iii) that you are using \LaTeX" with the
standard output routines. This example can be modified for other
circumstances.\footnote{If you don't want to retype this, look for this
example in the file {\tt pst-user.tex}.}

\begin{verbatim}
\makeatletter             % Omit this if this goes in a style file.
\let\NormalShipout\shipout
\newbox\OutputBox
\def\LandscapeMode{%
  \long\def\shipout##1##2{%
    \setbox\OutputBox=\hbox{\rput[tl]{90}{\vbox{##2}}}%
    \NormalShipout\box\OutputBox}%
  \voffset 9in}
\def\Landscape{%
  \clearpage
  \begingroup
  % Begin page parameter changes
  \advance\textwidth 2.5in
  \advance\textheight -2.5in
  % End page parameter chages
  \global\@colht\textheight    % These two lines are necessary
  \onecolumn                   % for changes to take effect.
  \LandscapeMode}
\def\endLandscape{%
  \clearpage
  \endgroup
  \global\@colht\textheight\onecolumn}
\makeatother              % Omit this if this goes in a style file.
\end{verbatim}

Now |Landscape| is a \LaTeX" environment for landscape material.

 Here is an explanation of what is going in: |\LandscapeMode| redefines
|\shipout| so that, using \N\rput, the current page is rotate and put in a
zero-dimensional box with the reference point in the upper-left hand corner of
the page. Now we position this corner 1 inch from the left and 10 inches from
the top of the portrait page (i.e., 1 inch from the top and left of the
landscape mode page, which are \TeX's standard margins) by changing |\voffset|
from 0 to 9 inches.

 The only other job is to change the page parameters. This is done by
|\Landscape|. In the definition of |\Landscape| given above, all the margins
and so forth are left unchanged, but |\textwidth| and |\textheight| are
changed to reflect the rotate dimensions of the paper. You may want to use
other page parameter changes instead.



-- 
Timothy Van Zandt   (609)258-4050  tvz@Princeton.EDU (NeXTMail)
Dept. of Economics,  Princeton University,  Princeton, NJ 08544