One great feature of is its ability to use style (.STY
) files to change formatting features of the document or to extend the capabilities of . Most extensions to require more than the few lines of macro code that have been used in most of the examples in the previous chapters, and it generally takes considerable effort and skill to develop a new style file or macro set. Fortunately, the community is a sharing one, and collections of a great number of style files can be found in many Internet archives. Once you learn how to use the Internet to obtain style files from archives, you will have gained the ability to take far beyond its original capabilities.
In this chapter, a few style files are that are particularly useful or interesting are presented, primarily to illustrate the wide variety of formatting that can be achieved. But before showing these example styles, a brief word is appropriate about finding the style file that is most suitable for a particular application.
If you have a special formatting problem, chances are that someone has already written a style file that will take care of it and has contributed it to the growing collection of freely available styles macros. But how to find it? David Jones has, for the past few years, maintained an annotated summary of the many style files available from Internet archives. This summary can be obtained via anonymous ftp from theory.lcs.mit.edu
in directory ./pub/tex/TeX-index
. The file TeX-index
may also be found in other Internet archives (see the following Section).
Once you have determined the name of a style file that appears useful, you must obtain it from an archive site. Several sites around the world support the CTAN (Comprehensive TeX Archive Network). Each CTAN site has identical material and maintains authoritative copies of the many files. By far the best way to get files from these sites is via the Internet and to use anonymous ftp to download the desired file.
Some CTAN sites are ftp.uni-stuttgart.de [128.69.1.12]
with root directory .soft/tex; ftp.tex.ac.uk [134.151.44.19]
, root directory ./pub/archive;
and ftp.shsu.edu [192.92.115.10]
, root directory ./tex-archive
. CTAN is also mirrored in wuarchive.wustl.edu
. Other sites at which much material can be obtained include
Once you begin to use the Internet to explore these and many other archives, you will initially be overwhelmed by the amount of material available for your use. However, after a bit or exploring, you will find that the Internet is an invaluable resource.
If you do not have access to the Internet, then you may still be able to obtain style files by joining TUG1 or through your supplier.
1The User Group publishes an excellent newsletter which contains many useful hints, reviews, and news about . To become a member, contact Users Group, P.O. Box 869, Santa Barbara, CA 93102-0869, or e-mail them at tugtug.org
.
It is better to include lengthy verbatim
material into a document from an “external” file. If the material is placed in the .TEX
file, ’s internal memory is quickly consumed during compilation. If a verbatim extends more than two or three pages, you are likely to get an out of memory error
. The VERBFILE.STY
style, created by Tim Morgan, Adrian Clark, and Chris Bowley, offers a capability to read verbatim
material from an external file and bring it into the document without exhausting ’s memory. This style file defines two user-callable macros:
Here is an example of what is produced with verbatimfile{sub.lst}
:
DOUBLE PRECISION FUNCTION SVRT(ARG,ARG2,ERR)
IMPLICIT REAL*8(A-H, 0-Z)
EXTERNAL FUN
COMMON ARG1
ARG1=ARG2
CALL GAUS8(FUN,0.DO,ARG,ERR,ANS,IERR)
SVRT=ANS
RETURN
END
Here is the same file imported with verbatimlisting{sub.lst}
:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
In Section 5.3, it was seen that the default format that uses for table or figure captions is far from ideal. First it extends across the full width of the page (column) in a nonindented paragraph form. Second, it leaves no space after the caption, so space must be manually inserted. A typical result is shown in Table 8.1.
i Ei |
i Ei |
i Ei |
i Ei |
1 0.02 |
3 0.04 |
5 0.08 |
7 0.2 |
2 0.03 |
4 0.06 |
6 0.10 |
8 0.4 |
The HANGCAPTION.STY
style (of unknown parentage) defines a hangcaption
command that produces a hanging indent for the caption of a figure or table. Unlike ’s caption
command, hangcaption
will honor a font size change, a very useful feature when placing small tables or figures side-by-side. It also automatically puts a small vertical space between the caption and table. Finally, a new captionwidth
command can be used to restrict the width of the label. With hangcaption
, Table 8.1 becomes
i Ei |
i Ei |
i Ei |
i Ei |
1 0.02 |
3 0.04 |
5 0.08 |
7 0.2 |
2 0.03 |
4 0.06 |
6 0.10 |
8 0.4 |
This was produced with
egin{table}[htbp] captionwidth 4.0in
centering
hangcaption{The discrete energies $E_i$ (MeV) used for
deriving the approximate line-beam response
function. This is a long caption that extends
over several lines. } label{t8b}
egin{tabular}{|rc|rc|rc|rc|} hline
$i$ & $E_i$ & $i$ & $E_i$ & $i$ & $E_i$ & $i$ & $E_i$ \
hline
1 & 0.02 & 3 & 0.04 & 5 & 0.08 & 7 & 0.2 \
2 & 0.03 & 4 & 0.06 & 6 & 0.10 & 8 & 0.4 \ hline
end{tabular}
end{table}
In Section 9.3, other more flexible methods are presented for customizing the caption for figures and tables.
The EQUATION
style by Charles Karney extends the capabilities of to allow greater flexibility in labeling and numbering equations. To use this style, include the equation style in the documentstyle
statement, for example,
documentstyle[equation,12pt]{report}
In the following subsections, examples of the different equation environments provided by this style are given.
eqnarray
EnvironmentThe EQUATION.STY
modifies ’s eqnarray
and eqnarray
* environments to correct the spacing around the = sign. The command yesnumber
is used in eqnarray
* to generate an equation number, while
onumber
prevents an automatic equation number in the eqnarray environment. Here is an example.
eqalign
EnvironmentThe new eqalign
environment is like plain ’s eqalign
command. Note that this environment must be embedded in egin{equation}
… end{equation}
(or its equivalent).
eqalignno
EnvironmentEQUATION.STY
’s eqalignno
environment is just like ’s eqalignno
command. However, no egin{equation}
… end{equation}
is needed. The command
onumber
is used to suppress the equation number. The environment eqalignno
* is the same as eqalignno
except that automatic equation numbers are suppressed (unless a yesnumber
appears).
eqaligntwo
EnvironmentThe eqaligntwo
environment is a two-equation per line equivalent of the eqalignno
environment. The eqaligntwo
* environment is similar except that automatic equation numbering is suppressed.
The cases environment is just like plain ’s cases
command. Note that this environment must be embedded in egin{equation}
… end{equation}
(or its equivalent). The first column is treated as math and the second column as text.
subequations
EnvironmentThe EQUATION style also incorporates Stephen Gildea’s subequations environment. With this environment you can refer both to the overall set of equations and to individual subequations in it.
With this environment Eqs.˜(
ef{foo})
produces Eqs. (8.8) while the subequation reference Eq. ˜(
ef {foo-a})
produces Eq. (8.8a), Eq. ˜(
ef{foo-b})
produces Eq. (8.8b), and Eq.˜(
ef{foo-c})
produces Eq. (8.8c).
Wrapping text around figures in is difficult. However, the WRAPFIG.STY
style, written by Donald Arseneau, allows you to place a figure of a specified width on the left or right of thepage and have the text flow around it. WRAPFIG
will try to wrap text around the figure, leaving a gap of columsep
by producing a number of short lines of text. WRAPFIG
calculates the number of short lines needed based on the height of the figure plus the length intextsep
. You can override this guess by giving the optional argument specifying the number of shortened lines (counting each displayed equation as 3 lines). WRAPFIG
will not move a wrapped figure to the best place, so it is up to you to position it well. Any changes to the document can ruin your careful positioning, so wrapped figures should be positioned just before printing a final copy.
Here are some hints for good placement. (1) The wrapfigure
environment should be placed so as to not run over a page boundary. (2) Only ordinary text should have to flow past the figure (no section titles) although equations are acceptable if they fit. (3) Although it is convenient to give egin{wrapfigure}
just after a paragraph has ended, if you want to start in the middle of a paragraph, you must put the environment between two words where there is a natural line break (such as “… on the” and “left or right...” in the above example).
At the point in the text where you wish to place a wrapped figure, issue the following:
egin{wrapfigure}[no. narrow lines] {r or 1} {fig. width}
<figure specification>
[caption{…} label{...}]
end{wrapfigure}
Figure 8.1 was inserted in its paragraph with the following commands:
… to place a figure of a specified width on the
egin{wrapfigure}{r}{3.7in}
vspace{l.5in}
special{pcl: facload.pcl}
caption{An example load profile} label{f8a}
end{wrapfigure}
left or right of the page and have the text ...
There are a few restrictions on the use of WRAPFIG.STY
. First, the wrapfigure
environment should not be used inside another environment (for example, a list). There should be a only one wrapped figure per paragraph. Finally, wrapped figures do not float and hence they may get out of sequence with other floating figures.
Here is another way to wrap text around a figure, table, or any other object. The style WRAPFIG.STY
discussed in the previous section allows you to place a figure of a specified width on the left orright of a paragraph if the userselects the proper line break atwhich the “short lines” are tobegin. A more sophisticatedway to wrap text around figures Or tables is to USe the Style file PICINPAR.STY
created by Friedhelm Sowa. Here is a simple figure (created in the picture environment) that is placed to the right of the paragraph after the first two full lines. Notice that PICINPAR
calculates the number of short lines needed and wraps the text accordingly. Moreover, the user does not have to determine after what word the short lines begin!
The style PICINPAR
provides three environments: (1) figwindow
for embedding figures with a caption into a paragraph, (2) tabwindow
for placing tables with a caption into a paragraph, and (3) window
for putting anything into a display box without placing a table or figure caption beneath. Into these environments goes the text of the paragraph as well. The general syntax for figwindow
is (the others are similar)
figwindow [no. top long lines, |l, r, c|, {picture}, {caption}]
In this command l, r,
or c
refers to left, right, or center justification. For example, the first paragraph in this section was created with
egin{figwindow}[2, r,{ unitlength lin
egin{picture}(3, 1.2)
put(0.7, 0.7){circle*{0.2}} put(0.7, 0.7){circle{1.2}}
put(0.7, 0.7){vector(0, l){0.4}} put(2.5, 0.7){circle*{0.5}}
end{picture}
vspace{-.2in}},{Sample figure}] */,--move caption up a bit
Here is another way to wrap … the short lines begin!
end{figwindow}
1 |
ABC |
12:0 |
2 |
DEF |
11:1 |
3 |
HIJ |
10:2 |
4 |
KLM |
9:3 |
5 |
1. XYZ |
8:4 |
The command egin{tabwindow}
… end{tabwindow}
can be used to place a table either to the left or right or centered in a paragraph. In fact, several paragraphs can be placed between the egin{tabwindow}… end{tabwindow}
so that the table window spans multiple paragraphs as in this example.
The only problem that seems to be unusual with PICINPAR
is that the table caption is placed under the table in the European fashion. (Actually, this is not too surprising since Sowa is from Germany.) You might be tempted to leave the caption argument of the tabwindow environment empty to avoid any caption at all. However, this does not work since the “Table xx:” is still added below the table. To avoid any caption at all, simply use the plain window environment.
This table example was created by the following input:
egin{tabwindow} [2, 1, {egin{tabular} [t] {|r|l|r{ : }1|}
…
end{tabular}},{Example}]
The command … use the { t window} environment.
end{tabwindow}
A .PCL
file created externally by some graphics programs can also be embedded into a paragraph with PICINPAR
. This is an example done with ’s special
command. Here we are trying to place the figure in the center of the paragraph. However, with ment, there is no way the figure. We must cre-PCL file that is just the takes considerable trial most never would we try in the center of a para-cult for the eye to bridge ble. All in all, this capa-not seem to be very use-is when the graph or ta-width of the paragraph. the f igwindow environ-to specify the width of ate a the “space” for the right size. This often and error. However, alto place a figure or table graph since it is diffi-across the graphic or tability of PICINPAR
does ful. The one exception 30 ble occupies the whole A full-width graphic can be more easily inserted into a paragraph using the methods discussed in Chapter 6. This paragraph which contains an imbedded central figure was created with
egin{window}[3, c,{
vadjust{vskip 1.95in {hbox to 1.95in
{special{pcl:ptpair.pcl}hfill}}}},{}]
A { t .PCL} file created externally by some …
end{window}
This FANCYHDS.STY
style, created by Piet van Oostrum, allows you to customize page headers and footers in an easy way. The following description is taken almost verbatim from the documentation that comes with FANCYHDS
. This style combines features that were separately available in other page styles and allows you to create quite complex headers and footers for your document.
With FANCYHDS
you can define (1) three-part headers and footers, (2) rules in headers and footers, (3) headers and footers wider than extwidth
, (4) multiline headers and footers, (5) separate headers and footers for even and odd pages, and (6) separate headers and footers for chapter pages.
To use this page style, you must include f ancyhds as a style option in the documentstyle
declaration at the beginning of your file. You must also issue the pagestyle{fancy}
command in the preamble after you have made any changes you want to extwidth
. The page layout assumed by FANCYHDS
is as follows:
The L-fields will be left adjusted, the C-fields centered, and the R-fields right justified. Each of the six fields and the two rules can be defined separately.
The header and footer fields can be defined by commands lhead{LHEAD}
and so on for the other fields. If the field depends on something in the document (for example, section titles), you must in general use the markboth
and markright
commands; otherwise, a title may end on the wrong page. You can do this by redefining the commands chaptermark
, sectionmark
, and so on (see the examples in Section 8.7.8). The defaults for these marks are as in the standard page styles. The marks can be put into a header or footer field by referencing leftmark
and
ightmark
.
The thickness of the rules below the header and above the footer can be changed by redefining the length parameter headrulewidth
(default 0.4 point) and the length parameter footrulewidth
(default 0). These may be redefined by the setlength
command. A thickness of 0 point makes the rule invisible. If you want to make more complicated changes, you have to redefine the commands headrule
and/or footrule
.
For example, if you want a dotted line rather than a ruler, place the following command in the preamble:
enewcommand{headrule}{vbox to Opt{hbox toheadwidth
{dotfill}vss}}
The headers and footers are set in a box of width headwidth
. The default for this is the value of extwidth
. You can make it wider (or smaller) by redefining headwidth
with the setlength
or addtolength
command. The headers and footers will extend out of the page on the same side as the marginal notes. For example, to include the marginal notes, add both marginparsep
and marginparwidth
to headwidth
.
Each of the six fields is set in an appropriate parbox
, so you can put a multiline part in it with the \ command. It is also possible to put extra space in it with the vspace
command. Note that if you do this you will probably have to increase the headheight
or footskip
lengths.
If you want the headers and footers to be different on even- and odd-numbered pages in the twoside style, the field-defining macros can be given an optional argument, to be used on even-numbered pages, like lhead[EVEN-LHEAD]{ODD-LHEAD}
.
gives a hispagestyle{plain}
command for the first page of the document, the first page of each chapter and a couple of other pages. It might be incompatible with your page style. In this case you can use a slightly different version of the page style, called pagestyle{fancyplain}
. This page style redefines the page style “plain” to also use page style “fancy” with the following modifications:
• The thicknesses of the rules is defined by plainheadrulewidth
and plainfootrulewidth
(both default 0).
• The six fields may be defined separately for the plain pages by giving them the value fancyplain{PLAIN-VALUE}{NORMAL-VALUE}
. This construct may be used in both the optional argument and the normal argument.
Thus lhead[fancyplain{Fl}{F2}]{fancyplain{F3}{F4}} specifies the
LHEAD value in a two-sided document:
Fl on an even-numbered “plain” page
F2 on an even-numbered normal page
F3 on an odd-numbered “plain” page
F4 on an odd-numbered normal page
You can’t just change the header and/or footer fields in the middle of some text (for example, after a section header), because may have processed a bit more text before deciding to make up the page. It may have passed a section beginning, causing the wrong title on the page. has a mechanism called ‘marks’ to solve this problem. There is in a leftmark
and a
ightmark
. Usually, leftmark
is a chapter title and
ightmark
is a section title. To set the marks there are two commands: markboth{L}{R}
sets the leftmark
to L and the rightmark to R
, and
ightmark{R}
sets only the rightmark to R
. The default definitions of section
, and so on, do this already for you. Consider this example.
This header format can be easily achieved with FANCYHDS by putting the following in the document preamble.
pagestyle{fancy}
setlength{headrulewidth}{lpt}
lhead[
m hepage]{
m
ightmark}
head[slleftmark]{
m hepage}
The last two lines specify that, on even pages (the [ ] parts), the left header is the page number and right header is leftmark
, which is the chapter title because makes that the left argument of markboth
(see page 162 of Lamport’s book). On odd pages (the { } parts), the left header is
ightmark
, which is the last section title because makes that the argument to markright
, and the right header is the page number.
Now suppose you don’t want the section number and you want the section title in uppercase: You add the following to your preamble:
enewcommand{sectionmark} [1] {markright{uppercase{#l}}}
Or if you don’t want the chapter number, but only the chapter title (not in uppercase):
enewcommand{chaptermark} [1] {markboth{#l}{ }}
Note that the parameter in both cases is the section or chapter title.
Sec. 8.8. Frames and Boxes
The style file FANCYBOX. STY
, created by Timothy Van Zandt, allows you to use all kinds of boxes in a document. Besides creating special commands for boxes, many special macros are defined for handling verbatim text, using special list environments, placing frames around pages, and positioning text inside various boxes (including rotating text). The document that comes with FANCYBOX
is an excellent tutorial on how to write macros and special environments. In the following, only a few of the special features are demonstrated.
FANCYBOX
defines the following variants of the fbox
command: shadowbox
, doublebox
, ovalbox
(using hinlines
), and