Math mode in tabular without having to use $...$ everywhere
\documentclass{article}
\usepackage{amstext} % for \text macro
\usepackage{array} % for \newcolumntype macro
\newcolumntype{L}{>{$}l<{$}} % math-mode version of "l" column type
\begin{document}
\begin{tabular}{| L | L |}
\hline
\text{Column A} & \text{Column B} \\
x & y \\
\end{tabular}
\end{document}
If most of the table consists of math-mode material, it's preferable to use an array
environment instead of a tabular
environment. Any text-mode material in the table can be handled by encasing it in \text
directives (requires the amsmath
or the amstext
package):
\documentclass{article}
\usepackage{amsmath} % for "\text" macro
\begin{document}
$\begin{array}{|c|c|}
\hline
\text{Column A} & \text{Column B} \\
x+y & x-y \\
\hline
\end{array}$
\end{document}
If you use tabu
, it automatically detects whether the table is in math mode, thus imitating this feature of array
.
\documentclass{article}
\usepackage{amsmath,tabu}
\begin{document}
$\begin{tabu}{|l|l|}\hline
\text{Column A} & \text{Column B} \\
x & y
\end{tabu}$
\end{document}