vmargin.sty 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. %%----------------------------------------------------------------------
  2. %% vmargin.sty
  3. %
  4. % LaTeX package which introduces paper sizes and provides macros for
  5. % setting document margins.
  6. % This package supersedes package vpage.
  7. %
  8. % This file can be made part of a format by typing \input vmargin.sty
  9. % before dumping the format.
  10. %
  11. % Documentation & history after (last) \endinput.
  12. %
  13. % Still works with LaTeX 2.09.
  14. % Supported = yes.
  15. %
  16. %
  17. % Copyright (C) 1993, 1994, 1995, 1996, 1999 by:
  18. %
  19. % Volker Kuhlmann
  20. % c/o University of Canterbury
  21. % ELEC Dept
  22. % Creyke Road
  23. % Christchurch, New Zealand
  24. % E-Mail: v.kuhlmann@elec.canterbury.ac.nz
  25. %
  26. % This program can be redistributed and/or modified under the terms
  27. % of the LaTeX Project Public License, distributed from CTAN
  28. % archives as macros/latex/base/lppl.txt; either
  29. % version 1 of the License, or (at your option) any later version.
  30. %
  31. %%----------------------------------------------------------------------
  32. %\def\filename{Vmargin}
  33. \def\filename{vmargin}
  34. \def\fileversion{V2.2}
  35. \def\filedate{1999/06/01}
  36. \@ifundefined{Vmargin}{}{\endinput}
  37. \@ifundefined{documentclass}{
  38. \edef\Vmargin{Style `\filename', \fileversion, \filedate}
  39. \expandafter\everyjob\expandafter{\the\everyjob\typeout{\Vmargin}}
  40. \typeout{\Vmargin}
  41. }{
  42. \NeedsTeXFormat{LaTeX2e}[1994/06/01]
  43. \ProvidesPackage{\filename}[\filedate]
  44. \edef\Vmargin{Package `\filename', \fileversion, <\filedate>}
  45. \expandafter\everyjob\expandafter{\the\everyjob\typeout{\Vmargin}}
  46. \typeout{\Vmargin}
  47. }
  48. % new lengths: \PaperWidth, \PaperHeight
  49. % new if: \ifLandscape
  50. %
  51. \newdimen\PaperWidth
  52. \newdimen\PaperHeight
  53. %
  54. \newif\ifLandscape
  55. % \setpapersize
  56. %
  57. \def\setpapersize{\@ifnextchar[{\@@setps}{\@@setps[portrait]}}
  58. \def\@@setps[#1]{%
  59. \@ifundefined{po@#1}{\@name@err{#1}}{\@nameuse{po@#1}}%
  60. \@@@setps}
  61. \def\@@@setps#1{%
  62. \@ifundefined{paper@#1}{\@name@err{#1}}{}%
  63. \csname paper@#1\endcsname}
  64. % \usename{paper@#1} inside arg to \@ifundefined does not work
  65. % with papersize "custom".
  66. \def\po@portrait{\Landscapefalse}
  67. \def\po@landscape{\Landscapetrue}
  68. \def\@po@{\ifLandscape\dimen0\PaperWidth
  69. \PaperWidth\PaperHeight\PaperHeight\dimen0\fi
  70. \@ifundefined{paperwidth}{}{\paperwidth\PaperWidth}%
  71. \@ifundefined{paperheight}{}{\paperheight\PaperHeight}}
  72. \@ifundefined{PackageError}{
  73. \def\@name@err#1{%
  74. \typeout{*****> \string\setpapersize: illegal parameter: #1}}
  75. }{
  76. \def\@name@err#1{\PackageError{\filename}%
  77. {Paper size or orientation unknown: #1}{}}
  78. }
  79. % pre-defined paper/envelope sizes
  80. %
  81. % A0, A1, A2, ..., A9, B0, B1, ..., B9, C0, C1, ..., C9
  82. % USletter, USlegal, USexecutive
  83. % custom
  84. %
  85. \def\@defmetricpaper#1#2#3{%
  86. \begingroup
  87. \count0=0
  88. \def\w{\dimen1 }\def\h{\dimen2 }\def\s{\dimen3 }%
  89. \w#2\h#3
  90. \def\l{11}
  91. \loop
  92. \begingroup
  93. \def\t{\the\count0}
  94. \catcode`\t=11 % letter
  95. \expandafter\xdef\csname paper@#1\the\count0\endcsname{%
  96. \PaperWidth\the\w\PaperHeight\the\h\noexpand\@po@}
  97. \endgroup
  98. \s\w\w.5\h\h\s
  99. \ifnum\the\count0<9
  100. \advance\count0 by 1
  101. \repeat
  102. \endgroup
  103. }
  104. %
  105. \@defmetricpaper{A}{840.9mm}{1189.2mm}
  106. \@defmetricpaper{B}{1000mm}{1414mm}
  107. \@defmetricpaper{C}{917mm}{1297mm}
  108. %
  109. \let\@defmetricpaper=\relax % delete definition to save memory
  110. %
  111. \def\paper@USletter{\PaperWidth 8.5in \PaperHeight 11in \@po@}
  112. \def\paper@USlegal{\PaperWidth 8.5in \PaperHeight 14in \@po@}
  113. \def\paper@USexecutive{\PaperWidth 7.25in\PaperHeight 10.5in \@po@}
  114. %
  115. \def\paper@custom#1#2{\PaperWidth#1\PaperHeight#2\@po@}
  116. % margin@offset
  117. %
  118. % Compensates for the +1in/+1in top/left corner
  119. % by either reducing the margins or \hoffset, \voffset by 1in.
  120. % This macro is only defined here if it is not already defined!
  121. % (see documentation at the end)
  122. %
  123. \newif\if@shiftmargins
  124. \@shiftmarginsfalse % this MUST be default (pageframe.sty)
  125. %
  126. \@ifundefined{margin@offset}{
  127. \def\margin@offset{
  128. \if@shiftmargins
  129. \oddsidemargin -1in\evensidemargin -1in\topmargin -1in
  130. \hoffset 0in\voffset 0in\relax
  131. \else
  132. \oddsidemargin 0in\evensidemargin 0in\topmargin 0in
  133. \hoffset -1in\voffset -1in\relax
  134. \fi
  135. }}{}
  136. %
  137. \def\shiftmargins{\@shiftmarginstrue}
  138. % Setting margins
  139. %
  140. % \setmargins{leftmargin}{topmargin}{textwidth}{textheight}%
  141. % {headheight}{headsep}{footheight}{footskip}
  142. %
  143. \newcommand\setmargins[8]{%
  144. \margin@offset
  145. \advance\oddsidemargin #1
  146. \advance\evensidemargin \PaperWidth % = paperwidth - left
  147. \advance\evensidemargin -#1 % - width
  148. \advance\evensidemargin -#3
  149. \advance\topmargin #2
  150. \textwidth #3
  151. \textheight #4
  152. \headheight #5
  153. \headsep #6
  154. \@ifundefined{footheight}{}{\footheight=#7}%
  155. \footskip #8
  156. \chk@dimen{#1}{#2}{#3}{#4}%
  157. }
  158. %
  159. % \setmarginsrb{leftmargin}{topmargin}{rightmargin}{bottommargin}%
  160. % {headheight}{headsep}{footheight}{footskip}
  161. %
  162. \newcommand\setmarginsrb[8]{%
  163. \margin@offset
  164. \textwidth \PaperWidth % = paperwidth
  165. \advance\textwidth -#1 % - left - right
  166. \advance\textwidth -#3
  167. \textheight \PaperHeight % = paperheight - top
  168. \advance\textheight -#2 % - headheight
  169. \advance\textheight -#5 % - headsep
  170. \advance\textheight -#6 % - footskip - bottom
  171. \advance\textheight -#8
  172. \advance\textheight -#4
  173. \advance\oddsidemargin #1
  174. \advance\evensidemargin \PaperWidth % = paperwidth
  175. \advance\evensidemargin -#1 % - left - width
  176. \advance\evensidemargin -\textwidth
  177. \advance\topmargin #2
  178. \headheight #5
  179. \headsep #6
  180. \@ifundefined{footheight}{}{\footheight=#7}%
  181. \footskip #8
  182. \chk@dimen{#1}{#2}{#3}{#4}%
  183. }
  184. %
  185. % \setmargnohf{leftmargin}{topmargin}{textwidth}{textheight}
  186. % headheight, headsep, footheight, footskip set to 0pt
  187. \newcommand\setmargnohf[4]{%
  188. \setmargins{#1}{#2}{#3}{#4}\z@\z@\z@\z@
  189. \pagestyle{empty}}
  190. %
  191. % \setmargnohfrb{leftmargin}{topmargin}{rightmargin}{bottommargin}
  192. % headheight, headsep, footheight, footskip set to 0pt
  193. \newcommand\setmargnohfrb[4]{%
  194. \setmarginsrb{#1}{#2}{#3}{#4}\z@\z@\z@\z@
  195. \pagestyle{empty}}
  196. %
  197. % \setmarg{leftmargin}{topmargin}{textwidth}{textheight}
  198. % headheight, headsep, footheight, footskip unchanged
  199. \newcommand\setmarg[4]{%
  200. \setmargins{#1}{#2}{#3}{#4}%
  201. \headheight\headsep\footheight\footskip}
  202. %
  203. % \setmargrb{leftmargin}{topmargin}{rightmargin}{bottommargin}
  204. % headheight, headsep, footheight, footskip unchanged
  205. \newcommand\setmargrb[4]{%
  206. \setmarginsrb{#1}{#2}{#3}{#4}%
  207. \headheight\headsep\footheight\footskip}
  208. %
  209. % h-warning if [leftmarg + textwidth > paperwidth] resp.
  210. % if [leftmarg + rightmarg > paperwidth].
  211. % v-warning if [topmarg + textheight > paperheight] resp.
  212. % if [topmarg + bottommarg > paperheight].
  213. \def\chk@dimen#1#2#3#4{%
  214. \dimen0= #1
  215. \advance\dimen0 by#3
  216. \advance\dimen0 -\PaperWidth
  217. \dimen1= #2
  218. \advance\dimen1 by#4
  219. \advance\dimen1 \headheight
  220. \advance\dimen1 \headsep
  221. \advance\dimen1 \footskip
  222. \advance\dimen1 -\PaperHeight
  223. \chk@dimen@err
  224. }
  225. \@ifundefined{PackageError}{
  226. \def\chk@dimen@err{
  227. \ifnum\dimen0>\z@\typeout{vmargin Warning: Horizontal dimensions
  228. exceed paper width by \the\dimen0}\fi
  229. \ifnum\dimen1>\z@\typeout{vmargin Warning: Vertical dimensions
  230. exceed paper height by \the\dimen1}\fi
  231. }
  232. }{
  233. \def\chk@dimen@err{
  234. \ifnum\dimen0>\z@\PackageError{\filename}{%
  235. Horizontal dimensions exceed paper width by \the\dimen0}{}\fi
  236. \ifnum\dimen1>\z@\PackageError{\filename}{%
  237. Vertical dimensions exceed paper height by \the\dimen1}{}\fi
  238. }
  239. }
  240. %
  241. % DEFAULTS:
  242. %
  243. \setpapersize{A4}
  244. \def\@hf@dflt{}
  245. \@ifundefined{DeclareOption}{
  246. }{
  247. \DeclareOption{shiftmargins}{\shiftmargins}
  248. \DeclareOption{portrait}{\Landscapefalse}
  249. \DeclareOption{landscape}{\Landscapetrue}
  250. \DeclareOption{nohf}{\def\@hf@dflt{y}}
  251. \DeclareOption*{\@@@setps{\CurrentOption}}
  252. \ProcessOptions\relax % process options in order of declaration!
  253. }
  254. \if y\@hf@dflt
  255. \setmargnohfrb{35mm}{20mm}{25mm}{15mm}%
  256. \else
  257. \setmarginsrb{35mm}{20mm}{25mm}{15mm}{12pt}{11mm}{0pt}{11mm}%
  258. \fi
  259. \endinput
  260. %%----------------------------------------------------------------------
  261. Page Size and Margins
  262. =====================
  263. These macros make it easy to set page margins for a chosen paper size.
  264. Actual dimensions of the most common paper sizes are stored and need
  265. not be remembered.
  266. Two sided printing is supported, meaning that if on odd pages the left
  267. margin is, say, 30mm and the right margin is 20mm, it will be vice
  268. versa on even pages. This gives equal margins on the outer and equal
  269. margins on the inner edge of the paper, as expected e.g. for a book.
  270. vmargin is designed to be reasonably restricted in both memory usage
  271. and processing time, so that the common task of setting margins is not
  272. too distracting. If you are looking for something fancier try the
  273. geometry package.
  274. The basic procedure of using vmargin is to first set a paper size, and
  275. then to set the margins. The margin setting functions depend on the
  276. paper size. Setting the paper size and margins are two independent
  277. operations, i.e. setting the paper size does not directly affect the
  278. margins but will affect the next margin setting command.
  279. The size of the paper can be set with
  280. \setpapersize{<size>}
  281. <size> can be A0, A1, ..., A9, B0, B1, ..., B9, C0, ..., C9, USletter,
  282. USlegal, and USexecutive. The metric paper sizes are not stored but
  283. calculated. \setpapersize by default sets the orientation to portrait.
  284. Landscape format is selected by using the optional argument
  285. \setpapersize[landscape]{<size>}
  286. which swaps the width and height dimensions of the paper.
  287. \setpapersize[portrait]{<size>} is allowed but is the default.
  288. If you have a size which is not pre-defined use
  289. \setpapersize{custom}{<width>}{<height>}
  290. For <width> and <height> insert the respective dimensions of your
  291. paper.
  292. \setpapersize stores the actual dimensions of the paper in the length
  293. variables
  294. \PaperWidth
  295. \PaperHeight
  296. which can be used further, if desired.
  297. \ifLandscape
  298. yields true if a landscape format is selected. Do not write to
  299. \PaperWidth, \PaperHeight, or call \Landscapetrue or \Landscapefalse,
  300. it will not work!!
  301. The margins can be set with
  302. \setmargins{leftmargin}{topmargin}{textwidth}{textheight}%
  303. {headheight}{headsep}{footheight}{footskip}
  304. or with
  305. \setmarginsrb{leftmargin}{topmargin}{rightmargin}{bottommargin}%
  306. {headheight}{headsep}{footheight}{footskip}
  307. In the latter case \textwidth and \textheight are calculated using the
  308. width and height of the selected paper. The first four parameters of
  309. the above two commands are used to set \oddsidemargin, \evensidemargin,
  310. \textwidth, \topmargin, and \textheight.
  311. \setmargnohf, \setmargnohfrb
  312. Provide a page with no header and footer. They work the same as
  313. \setmargins, \setmarginsrb except that they only need the first 4
  314. parameters. The last 4 parameters are set to 0pt. These 2 commands set
  315. the pagestyle to empty (\pagestyle{empty}) as there is no space for
  316. headers or footers.
  317. \setmarg, \setmargrb
  318. are the same as \setmargnohf, \setmargnohfrb except that the last 4
  319. parameters to \setmargins, \setmarginsrb are unchanged.
  320. Example:
  321. A4 paper, left margin 30mm, top, right, and bottom margin 20mm
  322. each, no headers or footers:
  323. \setpapersize{A4}
  324. \setmarginsrb{30mm}{20mm}{20mm}{20mm}{0pt}{0mm}{0pt}{0mm}
  325. \pagestyle{empty}
  326. The same settings would result with:
  327. \setpapersize{A4}
  328. \setmargnohfrb{30mm}{20mm}{20mm}{20mm}
  329. For the default settings please see the part after "DEFAULTS:" (last
  330. part before \endinput).
  331. The default top and left margins of TeX are +1in. \setmargXXX call
  332. \margin@offset
  333. which initialises \hoffset, \voffset to -1in and \oddsidemargin,
  334. \evensidemargin, \topmargin to 0in. \setmargXXX then add the given
  335. dimensions to \topmargin, \oddsidemargin, \evensidemargin. In some
  336. cases it might be desired to use \XXXmargin instead of \Xoffset for
  337. compensation. This can be achieved by telling \margin@offset to
  338. initialise \Xoffset to 0in and \XXXmargin to -1in. This is done by
  339. %
  340. \shiftmargins.
  341. %
  342. If \margin@offset is already defined at the time vmargin is loaded it
  343. is NOT redefined! Therefore if \margin@offset is defined before vmargin
  344. is loaded the above mentioned compensation can be replaced by a
  345. different mechanism. In any case \setmargXXX call \margin@offset and
  346. then expect that \XXXmargin are set to useful values. \Xoffset are not
  347. touched by \setmargXXX. \margin@offset should be defined in a separate
  348. file which is included BEFORE vmargin, i.e. appears in the list of
  349. document-substyles of the \documentstyle command before vmargin.
  350. %
  351. Any better way of doing this? (grumble)
  352. Example: \documentstyle[...,margins,vmargin,...]{...}
  353. if \margin@offset is defined in a file called margins.sty.
  354. LaTeX2e: \documentclass[...]{...}
  355. \usepackage{...,margins,vmargin,...}
  356. LaTeX2e
  357. -------
  358. This package now uses some of the new LaTeX2e features for package
  359. programming. It will still work with LaTeX 2.09 (in which case the new
  360. features are not used, resp. are inaccessible).
  361. LaTeX2e (unless in compatibility mode) does not know \footheight any
  362. more. vmargin does not set this variable if it does not exist, and sets
  363. it if it does. As \footheight was not used by LaTeX 2.09 all this has
  364. little significance.
  365. LaTeX2e now has the dimensions \paperwidth, \paperheight which hold the
  366. size of the paper. \PaperWidth, \PaperHeight are copied into
  367. \paperwidth, \paperheight if the latter exist. This makes vmargin work
  368. correctly with anything that expects \paperwidth, \paperheight to be
  369. set properly. The names \PaperWidth, \PaperHeight had been chosen in
  370. the first place to avoid clashes with style files that also use these
  371. names (namely pageframe.sty).
  372. The following package options are available under LaTeX2e:
  373. shiftmargins same as \shiftmargins
  374. portrait
  375. landscape
  376. A4, etc. same as using \setpapersize[...]{...}
  377. Note: \setpapersize always sets the orientation to
  378. portrait unless landscape is given. Using \setpapersize
  379. after \usepackage causes package option landscape to be
  380. ignored.
  381. nohf do not make space for header and footer lines; this also
  382. sets the pagestyle to empty
  383. All unknown options are treated as a paper size, if necessary
  384. generating an error that the requested paper size is not defined.
  385. Inclusion in TeX formats
  386. ------------------------
  387. This file may be loaded in initex before dumping the format, by typing
  388. \makeatletter
  389. \input vmargin.sty
  390. \makeatother
  391. Note: this produces a non-standard format.
  392. Hints for using pageframe.sty
  393. -----------------------------
  394. vmargin.sty and pageframe.sty can be used together if the following
  395. points are considered:
  396. vmargin uses \hoffset and \voffset and writes negative values into it,
  397. pageframe expects them to be zero to give a 1in space on the left and
  398. the top where it prints additional information. Initially, set both to
  399. 0mm (in the pre-amble of your text) and adjust them later on.
  400. pageframe needs to know the trimmed height of the paper (= the height
  401. of the "page frame"). Unless the trimmed(!) size of the paper is
  402. equivalent to one of the standard paper sizes (unlikely...) the size
  403. should be specified with
  404. \setpapersize{custom}{<width>}{<height>}
  405. The correct height of the trimmed page can then be given to pageframe
  406. using
  407. \paperheight{\PaperHeight}
  408. and the margins of the final product (inside the page frame) can be
  409. specified using \setmargXXX.
  410. Warning: if \setmargXXXrb is used the 3rd parameter (right margin) is
  411. ignored. Instead, the dimension of the right margin has to be assigned
  412. to \evensidemargin. This is because pageframe.sty re-defines the meaning
  413. of \evensidemargin to be the right margin of your text, on all pages.
  414. Remember: all these assignments and macro calls have to be in the
  415. pre-amble of the document.
  416. Bugs:
  417. -----
  418. I have not tested this with older versions of LaTeX2e because I don't
  419. have any. If there are any problems pleease do let me know and I'll do
  420. something about it.
  421. To do:
  422. ------
  423. * The way the metric paper sizes are stored takes up a lot of space. A
  424. metric size could be computed by \setpapersize.
  425. SUMMARY:
  426. ========
  427. new lengths:
  428. \PaperWidth
  429. \PaperHeight
  430. new ifs:
  431. \ifLandscape
  432. new macros:
  433. \setpapersize[<orientation>]{<size>},
  434. \setpapersize[<orientation>]{custom}{<width>}{<height>}
  435. <orientation> (optional) = landscape or portrait (default)
  436. <size> = A4, B5, ...
  437. <width>, <height> = actual dimensions of the paper
  438. \setmargins{leftmargin}{topmargin}{textwidth}{textheight}%
  439. {headheight}{headsep}{footheight}{footskip}
  440. \setmarginsrb{leftmargin}{topmargin}{rightmargin}{bottommargin}%
  441. {headheight}{headsep}{footheight}{footskip}
  442. \setmargnohf{leftmargin}{topmargin}{textwidth}{textheight}
  443. \setmargnohfrb{leftmargin}{topmargin}{rightmargin}{bottommargin}
  444. \setmarg{leftmargin}{topmargin}{textwidth}{textheight}
  445. \setmargrb{leftmargin}{topmargin}{rightmargin}{bottommargin}
  446. %
  447. \margin@offset
  448. \shiftmargins
  449. LaTeX2e package options:
  450. shiftmargins
  451. portrait
  452. landscape
  453. nohf
  454. all other options are treated as paper sizes
  455. If you have any comments (positive or negative) please let me know!
  456. HISTORY:
  457. ========
  458. .
  459. . Created out of Vpage.sty.
  460. .
  461. V1.7 21 May 1994 Changed file header.
  462. V1.72 21 May 1994 Fixed bug in \setpapersize{custom}
  463. V1.8 28 May 94 Commented \chk@dimen; reduced load on TeX's
  464. parameter stack (changed \chk@dimen).
  465. Put a conditional around references
  466. to \footheight.
  467. V1.9 22 Jun 94 Corrected spelling in comment.
  468. V2.0 28 Jun 94 Added support for LaTeX2e \paperwidth,
  469. \paperheight.
  470. V2.1 20 Sep 94 \@defmetricpaper now defines \w, \h, \s locally.
  471. Thanks to branderhorst@fgg.eur.nl!
  472. V2.12 28 Mar 95 Fixed documentation for \setmargrb.
  473. V2.13 26 Jun 96 Fixed comment for \setmarginsrb.
  474. V2.2 31 May 99 Released under LPPL.
  475. Changed references to Vmargin to vmargin.
  476. LaTeX2e package options introduced.
  477. %
  478. %% EOF vmargin.sty
  479. %%----------------------------------------------------------------------