Math inside tables and formatting
I would rather forget about stripes, they are really meant to be left to zebras and not mathematical books and they do not enhance readability as is sometimes claimed (see link in comments). If you want to have a bit more of a modern look and similar to what you want, use the excellent tcolorbox
package by Prof. Thomas F. Sturm, author of
LATEX – Einführung in das Textsatzsystem who also now kindly provided documentation in English.
Here is a MWE:
\documentclass[twocolumn]{article}
\usepackage[listings,theorems]{tcolorbox}
\tcbset{before={\par\medskip\pagebreak[0]\noindent},after={\par\medskip}}%
\begin{document}
\section{Table of Equations}
\newcounter{texercise}[section]
\begin{tcolorbox}[colback=blue!5,colframe=blue!50!black,arc=0mm,
theorem={Equation}{texercise}{Summation}{myMarker}]{Summation of Numbers}{summation}
For all natural number $n$ it holds:\\[2mm]
\[\displaystyle\sum\limits_{i=1}^n i = \frac{n(n+1)}{2}\]
\end{tcolorbox}
\begin{tcolorbox}[colback=blue!5,colframe=blue!50!black,arc=0mm,
theorem={Equations}{texercise}{More on summation}{myMarker}]{Summation of Numbers}{summation}
For all natural number $n$ it holds:\\[2mm]
\[\displaystyle\sum\limits_{i=1}^n i = \frac{n(n+1)}{2}\]
\[\displaystyle\sum\limits_{i=1}^n i = \frac{n(n+1)}{2}+ \frac{n(n+1)}{2}\]
\end{tcolorbox}
\end{document}
You can include any material in the boxes, provided by tcolorbox
, including tabulars.
\begin{tcolorbox}[colback=blue!5,colframe=blue!50!black,arc=0mm,
theorem={Equations}{texercise}{More on summation}{myMarker}]{Summation of Numbers}{summation}
\medskip
\begin{tabular}{lr@{~}c@{~}l@{\qquad}r}
\multicolumn{5}{l}{\hspace{-2ex}\textbf{Line Values.}} \\
\multicolumn{5}{r}{}\\
\multicolumn{4}{l}{Altitude of triangle on side $a$,} \\
& $h$ &=& \( \displaystyle \frac{2}{a}
\sqrt{s(s-a)(s-b)(s-c)} \) & \\
%
\multicolumn{4}{l}{Median of triangle on side $a$,} \\
& $m$ &=& \( \frac{1}{2} \sqrt{2(b^2+c^2) - a^2} \) & \ \\
\multicolumn{5}{l}{\hspace{-2ex}\textbf{Areas.}} \\
%
Rectangle, & $S$ &=& $b\times h$ & \\
Square, & $S$ &=& $b^2$ & \\
\end{tabular}
\end{tcolorbox}
The package has many options and one needs to study the documentation carefully. The English documentation has only been recently added, so you might need to update your distribution.
There are perhaps many ways of doing this. However, requiring a table structure with alternating row colours limits your possibilities. Here is a mock-up of your current document with some alterations:
\documentclass[a4paper]{article}
\usepackage[margin=1in]{geometry}% http://ctan.org/pkg/geometry
\usepackage{multicol}% http://ctan.org/pkg/multicol
\usepackage{array}% http://ctan.org/pkg/array
\usepackage[table]{xcolor}% http://ctan.org/pkg/xcolor
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\usepackage{amsfonts}% http://ctan.org/pkg/amsfonts
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\renewcommand{\arraystretch}{1.5}% Increase the row height of tabular/array
\newcolumntype{C}{>{\centering\arraybackslash$}p{\linewidth}<{$}}
\begin{document}
\begin{multicols}{2}
\lipsum[1-5] \par \medskip
% Row color alternating
\rowcolors{1}{gray!25}{white}%
\setlength{\tabcolsep}{0pt}%
\noindent\begin{tabular}{C}
\hline
f : \mathbb{R} \to \mathbb{Q} \\
g : \mathbb{Z} \to \mathbb{C} \\
h : \mathbb{R} \to \mathbb{Q} \\
f(g(x)) = \frac{\pi}{2}\phantom{\ \forall x > 0} \\
f(g(x)) = \frac{\pi}{2}\ \forall x > 0 \\
\hline
\end{tabular} \par \medskip
\lipsum[6-8]
\end{multicols}
\end{document}
Here are some comments pertaining to the adjusted example:
- I've used
geometry
to adjust the margins, since the default margin setup in two-column mode I find too narrow; - The table is set apart from the flowing text using
\par\medskip
to introduce a medium vertical skip as a separation; - Since the
tabular
is an element (in horizontal mode) on its own, it starts a paragraph and is therefore indented by\parindent
. Using\noindent
removes this indentation, setting is flush left with the column margin; - A single column of width
\linewidth
makes thetabular
stretch the entire width of the column (\columnwidth
would have worked just as well); - Left- and right-column padding is removed via
\setlength{\tabcolsep}{0pt}
; tabular
row height is increased by a factor of 50% via\renewcommand{\arraystretch}{1.5}
;Although the single
tabular
is set in paragraph style (p{\linewidth}
), thearray
package column specification allows for inserting<stuff>
before each column entry using>{<stuff>}
and appending afterwards using<{<stuff>}
. Therefore,\newcolumntype{C}{>{\centering\arraybackslash$}p{\linewidth}<{$}}
defines a new column type
C
that centres its contents (\centering
) in math mode$
...$
.- Horizontal alignment with other row elements is possible via ample use of
\phantom{...}
, since usingalign
environments do not work across thetabular
rows.