文件結構簡介

文件框架

文件的組成架構中有個像寫C程式般的框架,然後處理程式根據框架來處理。 其實一份文件就是我們以前說的八股文, 要寫好八股文也不是簡單事,主要是有內容的八股文,通常要有起承轉合, 一份LaTeX或SGML文件,像這樣子

LaTeX框架
\documentclass{article} (\documentstyle是\LaTeX 2.09版的寫法)
\usepackage{CJK}
\begin{document}
......
\end{document}
	

SGML 框架
<!doctype book PUBLIC "-//OASIS//DTD DocBook V3.1//EN" []>
<book>
......
</book>
	
sgml很像HTML前後用<tag></tag>夾住,其中 -//OASIS//DTD DocBook V3.1//EN大小寫有差。 LaTeX很多是用\begin{xxx} \end{xxxx}夾住, 其中\usepackage{CJK}是拿來處理中文的, 如果文章中碰到中文時還要用\begin{CJK}{Bg5}{kai} \end{CJK}, 這樣的命令夾住中文。

文件屬性

一份文件的屬性是什麼 決定了這個輸出應該要有什麼樣的樣子, 例如最常見到的兩種型態book 與article, 一本書(book) 通常有目錄(table of content) 有章節 有索引(index), 相對的文章(article)可能就不需要目錄了。 其他的可能像信件(Letter)或備忘錄(MEMO)等等都算是一種文件屬性, 不同文章屬性有不同的格式需求,所以要寫作前,要先設定文章的屬性為何, 讓處理程式有辦法往下處理。

在LaTeX的例子裡 我們用
\documentclass{book}
\documentclass{article}
\documentclass{report}
	

在sgml裡 我們用
<!doctype book  xxxx>
<book>
  xxxxx
</book>

<!doctype article  xxxxx>
<article>
  xxxx
</article>
	
來宣告文件的屬性, 其中sgml裡這個第一個標籤叫root tag,一定是這個屬性的名字, 所以book屬性的root tag是<book>。

Metadata

通常一本書或一篇文章除了內容外還有其它資訊, 例如書名作者出版商等資訊還有像ISBN編號等, 這些資訊叫metadata,也就是說不屬於正式內容但是很重要的資訊, 所以緊跟著框架與文件屬性後通常就是metadata。

LaTeX
\title{Test Plan for Automation System}
  \author{
    Cyril Huang\\
    Veritas Software
  \and 
    HaiShan Chen\\
    Alcatel Systems}
\maketitle

也可以用
\beign{title}
  xxxx

\end{title}
	
\begin{title} \end{title}裡面的內容是任意的, 不過就是要自己控制字型字的大小與排版, 尤其是寫一本book時比較有用,一般report 或article, 可以用\title \maketile就好。

SGML
<author>
  <firstname>Cyril</firstname>      
  <surname>Huang</surname>
  <affiliation>
    <orgname>Veritas Software</orgname>
  </affiliation>
</author>
<author>
  <firstname>HaiShan</firstname>      
  <surname>Chen</surname>
  <affiliation>
    <orgname>Alcatel Systems</orgname>
  </affiliation>
</author>

<revhistory>
  <revision>
    <revnumber>0.1</revnumber>
    <date>13 Mar 2001</date>
    <authorinitials>C.H</authorinitials>
    <revremark>first draft</revremark>
  </revision>
  <revision>
    <revnumber>0.2</revnumber>
    <date>25 Apr 2001</date>
    <authorinitials>C.H</authorinitials>
    <revremark>Second draft</revremark>
  </revision>
</revhistory>
	

其中LaTeX是由\maketitle來完成,所以叫\maketitle前, 要先把\title \author寫好, \\在\LaTeX中代表newline換行, 日期會自己印出來, 在article中只會印成像論文般的header, 如果想另成一個page,要寫成 \documentclass[titlepage]{article}。

sgml的metadata如果是在book時要夾在<bookinfo></bookinfo>, article是在<artheader></artheader>, SGML裡不只這些還有更多的標籤可以用。

文章結構元素

正式文件裡有些元素是需要的, 例如論文中我們通常都要有個摘要(abstract)來貫穿整個文章, 另外文件裡其它的常聽到的元素就是章節段落了。

摘要(abstract)

LaTeX
\begin{abstract}
   xxxx
\end{abstract}
	  

SGML
<abstract>
   xxxx
</abstract>
	  
摘要不能出現在book型式的文件中

章(chapter)

LaTeX
\chapter{This is Chapter 1 Title}
	  

SGML
<chapter>
<title>This is Chapter 1 Title</title>

</chapter>
	  

節(section)

LaTeX
\section{The Section 1 title}
\subsection{The Section 1.1 title}
\subsubsection{The Section 1.1.1 title }
	  

SGML
<sect1>
<title> The Section 1 title </title>
<sect2>
<title> The Section 1.1 title </title>
<sect3>
<title> The Section 1.1.1 title </title>
	  
會有如下表現
1 The Section 1 title
1.1 The Section 1.1 title 
1.1.1 The Section 1.1.1 title 
	  
注意book要有chapter,但article/report要從section開始不能有chapter

段落(paragraph)

LaTeX
\\\\
\par
	  

SGML
<para>
xxxx
</para>
	  
\\在LaTeX中代表換行,所以其實用\\\\就可以有段落的效果了, 不過如果在tex原始檔中多一個空白行,就會有段落並造成縮排效果。 跟用\par一樣

SGML比較囉唆一點的是很多文字部份有時一定要para這個標籤, 不過如果少了也沒關係,有時還是可以轉成我們想要的格式檔出來。

其他文字常用元素

加強注意(emphasize)

LaTeX
\emph{注意文字}
	  

SGML
<emphasis>
注意文字
</emphasis>
	  

列舉文字(list)

LaTeX
\begin{itemize}
  \item item1
  \item item2
\end{itemize}
	  

SGML
<itemizedlist>
  <listitem>
  <para>
    item1
  </para>
  </listitem>
  <listitem>
  <para>
    item2
  </para>
  </listitem>
</itemizedlist>
	  
常用list除了前面有圓點的外還有1 2 3 4....

LaTeX
\begin{enumerate}
  \item item1
  \item item2
\end{enumerate}
	  

SGML
<orderedlist>
  <listitem>
  <para>
    item1
  </para>
  </listitem>
  <listitem>
  <para>
    item2
  </para>
  </listitem>
</orderedlist>
	  
其它還有縮排的list等等

表格(table)

表格是比較複雜的元素之一

LaTeX
\begin{table}
  \caption{Test Cases}
  \begin{tabular}{r|p{6cm}|l|c}\hline
  Test Case ID & Test Case Descriptions & (pass/fail) & Comment \\ \hline
  1            & 
  Installation Test: This test is for the Solaris pkgtools
  test, give the command pkgadd -d /pkg/dir to test if the installation
  is correct                            &             &         \\ \hline\hline
  2            & Another test           & \multicolumn{2}{|c|}{}\\ \cline{1-2}
  \multicolumn{2}{|c|}{}                & \multicolumn{2}{|c|}{}\\ \hline
  \multicolumn{4}{|c||}{This is foot of Table}                  \\ \hline
  \end{tabular}
\end{table}
	  
LaTeX的表格由\begin{table}開始表示是一個浮動的表格, 就是說它自己會根據表格大小找到最適當的位置然後才放到適當位置, 如果希望照自己想要的順序出現表格, 則可以把\begin{table} \caption{}拿掉, \caption{Test Cases}caption是表格的標題。

\begin{tabular}開始做表格
	  
{r|p{6cm}|l|c}
	  
表示有4個欄位(column)其中
第一欄內文字向右對齊
第二欄位寬6公分,不這樣定會一欄只有一個很長的行的文字
第三欄向左對齊
第四欄向中對齊
|表示要畫垂直格線||表示畫兩道
	  

\hline表示要畫橫格線 
\hline\hline就會畫兩條橫線
	  
每一橫列(row)不同欄的內容用 & 分開 最後用\\代表結束換行
\cline{1-2}表示從第一欄畫橫線到第二欄,
\multicolumn{4}{|c||}{This is foot of Table}
表示接下來的4個欄位看成一欄,裡面文字(This is foot of Table)置中對齊
三個中括號是這個命令的參數,一定要有
	  

SGML
<table frame='all'>
     <title>Test Cases</title>
	<tgroup cols='4'>
	<colspec colname=c1 colwidth="1*">
	<colspec colname=c2 colwidth="7*">
	<colspec colname=c3 colwidth="2*">
	<colspec colname=c4 colwidth="2*">
	<spanspec spanname=hspan0 namest=c1 nameend=c4 align=left>
	<spanspec spanname=hspan1 namest=c1 nameend=c2 align=left>
	<spanspec spanname=hspan2 namest=c3 nameend=c4 align=center>

	<thead>
	  <row>
	    <entry>TC ID</entry>
	    <entry>Test Case Description</entry>
	    <entry>(pass/fail)</entry>
	    <entry>Comment</entry>
	  </row>
	</thead>

	<tfoot>
	  <row>
	    <entry spanname=hspan0>This is foot of Table</entry>
	  </row>
	</tfoot>
        <tbody>
	      <row>
		<entry>1</entry>
		<entry>
		  Installation Test
		  This test try to check if the installation of pkg. 
		  give the command pkgadd -d /pkg/dir to test if 
		  the installation is  correct
		</entry>
		<entry> </entry>
		<entry> </entry>
	      </row>

	      <row>
		<entry>2</entry>
		<entry>Another Test</entry>
		<entry spanname=hspan2 morerows=1> </entry>
	      </row>
	</tbody>
     </tgroup>
</table>
	  
<table>    frame=all表示要格線
<tgroup>
<colspec>  欄位名字定義,欄位寬度,1*表示一個單位,所以第一欄佔了1/12總寬度
<spanspec> 把多欄看成一欄的定義 名字 起始與結束欄位名
<thead>    表格的頭
<tfoot>    腳
<tbody>    身體
	  
一定要這個順序thead tfoot tbody,不過可以不要某個元素如tfoot。

還有很多命令與標籤 可以隨心所欲的製作出想要的表格來, 不過基本上這已經很好用了。