Tables

Code snippets for tables:

 

Standard table
\begin{table}[htbp] % h:here; t:top; b:bottom; p:page; default:ht
	\caption{default}
	\centering
	\begin{tabular}{lccr}
		\hline
		- & - & - & - \\
		\hline
		- & - & - & - \\
		- & - & - & - \\
		\hline
	\end{tabular}
	\label{tab:def}
\end{table}%

 

Side-by-side table
%Preamble
\usepackage[lotdepth]{subfig}

%Document
\begin{table}[htbp] % h:here; t:top; b:bottom; p:page; default:ht
	\centering
	\subfloat[short for lot subtable1][long subtable1 caption]{
		\begin{tabular}{lccr}
			\hline
			- & - & - & - \\
			\hline
			- & - & - & - \\
			- & - & - & - \\
			\hline
		\end{tabular}
		\label{subtab:tab1}
	}
	\subfloat[short for lot subtable2][long subtable2 caption]{
		\begin{tabular}{lccr}
			\hline
			- & - & - & - \\
			\hline
			- & - & - & - \\
			- & - & - & - \\
			\hline
		\end{tabular}
		\label{subtab:tab2}
	}
	\caption[short for lot]{long table caption}
	\label{tab:tab1}
\end{table}
\ref{tab:tab1} and \subref{subtab:tab1}

 

Sideways-table
% Preamble
\usepackage{rotating}

% Document
\begin{sidewaystable}
	\caption{Sideways table.}
	\centering
	\begin{tabular}{lccr}
		\hline
		- & - & - & - \\
		\hline
		- & - & - & - \\
		- & - & - & - \\
		\hline
	\end{tabular}
	\label{tab:swtab}
\end{sidewaystable}

 

Multi-page table (longtable)
%Preamble
\usepackage{longtable}

% Document
\begin{center}
\begin{longtable}{|c|c|c|c|}
\caption{A simple longtable example}\\
\hline
\textbf{First entry} & \textbf{Second entry} & \textbf{Third entry} & \textbf{Fourth entry} \\
\hline
\endfirsthead
\multicolumn{4}{c}%
{\tablename\ \thetable\ -- \textit{Continued from previous page}} \\
\hline
\textbf{First entry} & \textbf{Second entry} & \textbf{Third entry} & \textbf{Fourth entry} \\
\hline
\endhead
\hline \multicolumn{4}{r}{\textit{Continued on next page}} \\
\endfoot
\hline \multicolumn{4}{r}{\textit{End of table}} \\
\endlastfoot
1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\
\end{longtable}
\end{center}