LaTeX Tables Simplified
Tables in LaTeX is simple for smaller tables. A simple tabular environment can be created by using following code:
\begin{tabular}{ | l | r | } \hline Number of students & 15 \\ \hline Location & PG312 \\ \hline \end{tabular}
The tabular environment should be included in table environment to create a table.
\begin{table}
\begin{tabular}{ | l | r | } \hline Number of students & 15 \\ \hline Location & PG312 \\ \hline \end{tabular}
\caption{The schedule of session}
\label{tab:schedule}
\end{table}
The things gets complicated when the size in terms of rows and columns or text increases. The problem with l,c,r alignment is autowidth feature of columns. Increasing text increases the width of column which can become unmanageable for printable reports. The width of individual columns can be controlled with p{x cm}. However, the alignment of the column can not be controlled with p{x cm}. Following code helps in specifying the width and at the same time control the alignment of column.
% Following commands will help in aligning the columns of specific width. Add these lines in the preamble part of the document.
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
Use newly defined alignment specifiers L,C, R instead of p to specify the width alongwith left, center or right alignment.
\begin{table}
\centering \begin{tabular}{|L{2cm}|C{2cm}|R{3cm}|} \hline Number of students & Location & Description \\ \hline 150 & PG312 & The expert session on Latex to demonstrate creation of tables\\ \hline \end{tabular} \caption{The schedule of session} \label{tab:schedule} \end{table}
output: