Monday, 18 June 2012

Latex Stuff - Tables and Numbering

Firstly to get line numbering sorted for the body and the appendix separately we can define a macro, so that sections get numbered in arabic numberals, and teh appendices are labeled as Appendix X, where X is a character.
% Macros to redefine numbering of appendix sections (and to


% reset numbering when not in per-chapter area appendix)
\newcommand\normalsecnums{%
\renewcommand\thesection{\thechapter.\arabic{section}}}
\let\origchapter\chapter
\renewcommand{\chapter}[1]{\normalsecnums
\origchapter{#1}}
\newcommand\appsecnums{% % execute this command before entering appendix area
\setcounter{section}{0}
\renewcommand\thesection{\appendixname~\Alph{section}}}
This seems to work and to number the appendix we write:

\appsecnums
just before starting the appendices, which are simply marked as normal sections:
e.g.

\appsecnums
\section{Terms}
 
 
Tables can be achieved using explicit tables - which can be referenced or just be making the environment "tabular".  By making the environment tabular one can introduce columns into the main part of the text, as illustrated with this term lookup example.

\begin{tabular}{ p{2cm}  p{10cm} }  % centered columns (2 columns)
\hline
Term & Explanation \\ [0.5ex]
\hline
MDE & asdfas \\
Metadata & Data that represents models, for example a UML model or a CORBA object expressed in IDL \\ [1ex]
\hline
\end{tabular}
The instruction "tabular" is enough to get latex into a tabular mode, for specific tables that can be referenced we need to use the "table" instruction. This will enable to the table to be automatically numbered and refered to from the text.
After the tabular instruction comes a specification of columns : {l c r} 
l : left centred column
c : centre centred column
r : right centred column
To make sure the column width doesn't exceed the page width we need to use the array package (at the start : \usepackage{array}, then we can use the following instructions:
p{Xcm} - top align
m{Xcm} - middle align
b{Xcm} - bottom align
- where X is the desired width of column, this will prevent text continuing endlessly on one line without wrapping.

If I add the instruction table at the top then we get a referenced table, so a simple example would be:
\begin{table}[t]

\caption{Bartley Reservoir} % title of Table
\centering
\begin{tabular}{|c| c|| c | }  % centered columns (2 columns)
\hline
07h & 10h & 13h \\ [0.5ex]
\hline
4 & 4 & 4 \\
5 & 5 & 6 \\
10 & 13 & 15 \\
\hline
\end{tabular}
\end{table}

No comments:

Post a Comment