Tables

Code snippets for tables:

 

Standard figure
\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}

4 Comments

  1. S.Karim

    Hi Tom,,,,
    For drawing a table of any sort, style, etc. I am using Excel2LaTeX application, I have tried many dummy sorts of tables, all other things are correct except color of rows and/or columns as defined in excel, but after converting into LaTeX, colors become undefined (means as no any color is used,,, empty) . Although used color packages, so how can we get exact table drawn accordingly into excel?
    thanks…..

Leave a Reply