📄 338-340.html
字号:
<HTML>
<HEAD>
<TITLE>Linux Unleashed, Third Edition:geqn and gtbl</TITLE>
<SCRIPT>
<!--
function displayWindow(url, width, height) {
var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>
-->
<!--ISBN=0672313723//-->
<!--TITLE=Linux Unleashed, Third Edition//-->
<!--AUTHOR=Tim Parker//-->
<!--PUBLISHER=Macmillan Computer Publishing//-->
<!--IMPRINT=Sams//-->
<!--CHAPTER=18//-->
<!--PAGES=338-340//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="335-338.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="341-344.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H3><A NAME="Heading14"></A><FONT COLOR="#000077">gtbl</FONT></H3>
<P>The <TT>gtbl</TT> routine is designed to help in the preparation of charts, multicolumn lists, and any other material presented in a tabular format. The <TT>gtbl</TT> commands are not difficult to work with but can be awkward to learn, so studying examples is the best method.</P>
<P>To use <TT>gtbl</TT>, two special commands are used to indicate to <TT>groff</TT> that the area between the two commands is to be processed as <TT>gtbl</TT> instructions. These two key commands are <TT>.TS</TT> (table start) and <TT>.TE</TT> (table end). Commands between these two are processed by <TT>gtbl</TT> first, which converts the <TT>gtbl</TT> commands to <TT>groff</TT> commands; then, the source is passed to <TT>groff</TT>.</P>
<P>Tables are independent of each other with <TT>gtbl</TT>, meaning that each must contain all the information for formatting the data within the table and can’t rely on a previous format. Tables contain three types of information: text for the table itself, options that control the behavior of <TT>gtbl</TT>, and formatting commands to lay out the table itself. The general format of a <TT>gtbl</TT> source code section is as follows:</P>
<!-- CODE SNIP //-->
<PRE>
.TS
options;
format.
data
.TE
</PRE>
<!-- END CODE SNIP //-->
<P>Let’s look at the important parts of the <TT>gtbl</TT> layout first and then see how they are combined to produce finished tables.</P>
<H4 ALIGN="LEFT"><A NAME="Heading15"></A><FONT COLOR="#000077">Executing gtbl</FONT></H4>
<P>Because <TT>gtbl</TT> is a preprocessor, it is invoked on the source file, and then the results are passed to <TT>groff</TT>. The simplest way to do this is with the command</P>
<!-- CODE SNIP //-->
<PRE>
gtbl <I>filename</I> | groff
</PRE>
<!-- END CODE SNIP //-->
<P>in which the <TT>gtbl</TT> preprocessor runs against the source in <I>filename</I> and then sends the output to <TT>groff</TT>. If you are processing more than one file at a time, or you need to send the output of <TT>gtbl</TT> to another preprocessor, such as <TT>geqn</TT>, you use piping slightly differently. The command</P>
<!-- CODE SNIP //-->
<PRE>
gtbl <I>filename</I> | geqn | groff
</PRE>
<!-- END CODE SNIP //-->
<P>sends the output to <TT>geqn</TT> and then to <TT>groff</TT>.</P>
<H4 ALIGN="LEFT"><A NAME="Heading16"></A><FONT COLOR="#000077">Options</FONT></H4>
<P>There can be a single line of options after a <TT>.TS</TT> command that affects the entire table. Any options must follow the <TT>.TS</TT> command. If more than one option is specified, they must be separated by spaces, commas, or tabs, and terminate in a semicolon. <TT>gtbl</TT> accepts the following options:</P>
<CENTER>
<TABLE WIDTH="80%"><TR>
<TD WIDTH="30%"><TT>center</TT>
<TD WIDTH="70%">Centers the table (default is left-justified).
<TR>
<TD><TT>expand</TT>
<TD>Makes tables as wide as current line length.
<TR>
<TD><TT>box</TT>
<TD>Encloses the table in a box.
<TR>
<TD><TT>allbox</TT>
<TD>Encloses each element of the table in a box.
<TR>
<TD><TT>doublebox</TT>
<TD>Encloses the table in two boxes.
<TR>
<TD><TT>tab (<I>n</I>)</TT>
<TD>Uses <I>n</I> instead of a tab to separate data.
<TR>
<TD><TT>linesize (<I>n</I>)</TT>
<TD>Uses point size <I>n</I> for lines or rules.
<TR>
<TD><TT>delim (<I>mn</I>)</TT>
<TD>Uses <I>m</I> and <I>n</I> as equation delimiters.
</TABLE>
</CENTER>
<P>When <TT>gtbl</TT> attempts to lay out a table, it tries to keep the entire table on one page if possible, even if it has to eject the previous page only partially completed. This sometimes causes problems because <TT>gtbl</TT> can make mistakes estimating the size of the table prior to generating it, especially if there are embedded line commands that affect spacing or point size. To avoid this problem, some users surround the entire table with the display macros <TT>.DS</TT> (display start) and <TT>.DE</TT> (display end). You can ignore this for most tables, unless you start embedding commands within the data.</P>
<H4 ALIGN="LEFT"><A NAME="Heading17"></A><FONT COLOR="#000077">Format</FONT></H4>
<P>The format section of the table structure indicates how the columns are to be laid out. Each line in the format section corresponds to one line of data in the finished table. If not enough format lines are specified to match all the lines of data, the last format line specified is used for the remainder of the table. This lets you use a specific format for headers and a single format line for the rest of the table. The format section ends with a period.
</P>
<P>Each line in the format section contains a keyletter for each column in the table. Keyletters should be separated by spaces or tabs for each column to enhance readability. Keyletters are case-independent (so you can use upper- or lowercase for the keyletters or a mixture of the two, without affecting the layout). Supported <TT>gtbl</TT> keyletters are as follows:</P>
<CENTER>
<TABLE WIDTH="80%"><TR>
<TD WIDTH="20%"><TT>l</TT>
<TD WIDTH="80%">Left-justified entry
<TR>
<TD><TT>r</TT>
<TD>Right-justified entry
<TR>
<TD><TT>c</TT>
<TD>Centered entry
<TR>
<TD><TT>n</TT>
<TD>Numeric entries lined up by units
<TR>
<TD><TT>a</TT>
<TD>Aligned on left so that widest entry is centered
<TR>
<TD><TT>s</TT>
<TD>Previous column format applies across rest of column
</TABLE>
</CENTER>
<P>A sample format section consists of a letter for each column, unless the entry is repeated across the page. A sample format section looks like this:
</P>
<!-- CODE SNIP //-->
<PRE>
c s s
l n n .
</PRE>
<!-- END CODE SNIP //-->
<P>In this sample, the first line of the table is formatted with the first, second, and third columns centered (the <TT>s</TT> repeats the previous entry). The second and subsequent lines have the first entry left-justified and the next two lined up as numbers. The period ends the format section. If you like, you can put all these format keyletters on a single line, using a comma to separate the lines:</P>
<!-- CODE SNIP //-->
<PRE>
c s s, l n n .
</PRE>
<!-- END CODE SNIP //-->
<P>A table formatted by this set of commands looks like this (with random numbers inserted to show the lineup):
</P>
<!-- CODE SNIP //-->
<PRE>
Centered_Title
Entry1 12.23 231.23
Entry2 3.23 45.2
Entry3 45 123.2344
Entry4 3.2 2.3
</PRE>
<!-- END CODE SNIP //-->
<P>Numeric data is usually aligned so that the decimal places are in a vertical column. However, sometimes you want to override this format by forcing a movement. The special character <TT>\&</TT> is used to move the decimal point. The special characters disappear when the table is printed. To show the effect of this special character, the following sample shows normal formatting and entries with the special character embedded (the first column is the source input and the second is the generated output):</P>
<!-- CODE SNIP //-->
<PRE>
14.5 14.5
13 13
1.253 1.253
3\&1.21 31.21
53.2 53.2
6\&2.23 62.23
</PRE>
<!-- END CODE SNIP //-->
<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="335-338.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="341-344.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -