Edit II To fix the issues with row colours I have changed the environment to use gather
from the amsmath package
By default equation numbers can be put on the left or the right but not underneath. To do this you'll need to place them there "by hand". The code below defines a new environment that does this for you. What it really does is put the equation inside an array
with the equation in the first row and the equation number added as a second row to produce:
Edit I As the image shows, this is compatible with \label
and \ref
commands and with hyperref. The trick is that \refstepcounter
is used to increment the equation counter.
Here is the full code:
\documentclass{article}
\usepackage{multicol}
\usepackage{hyperref}
\usepackage{environ}
\usepackage{amsmath}% needed for gather
\usepackage[table]{xcolor}
\NewEnviron{Equation}{\refstepcounter{equation}%
\begin{gather*}\BODY\\(\theequation)\end{gather*}%
}
\begin{document}
\begin{multicols}{3}
\noindent
\begin{Equation}\label{one}
\left(\begin{array}{>{\columncolor{olive!20}}cc>{\columncolor{yellow!20}}cc}
\rowcolor{red!20}
0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 \\
\rowcolor{blue!20}
0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 \\
\end{array}\right)
\end{Equation}
\begin{Equation}\label{two}
\left(\begin{array}{>{\columncolor{olive!20}}cc>{\columncolor{yellow!20}}cc}
0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 \\
\end{array}\right)
\end{Equation}
\begin{Equation}
\left(\begin{array}{>{\columncolor{red!20}}cc>{\columncolor{olive!20}}cc}
0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 \\
\end{array}\right)
\end{Equation}
\end{multicols}
Look at \ref{one} and \ref{two}.
\end{document}
Edit III Here's a version that uses tikz to colour the rows and columns via a "helper environment" ColouredMatrix
. The output is similar:
The main advantage of this approach is that it is marginally easier to specify the row and column colours. The downsize is that you need to use \&
as the column separator. Here is the code:
\documentclass{article}
\usepackage{multicol}
\usepackage{hyperref}
\usepackage{environ}
\usepackage{amsmath}
\usepackage[table]{xcolor}
\NewEnviron{Equation}{\refstepcounter{equation}%
\begin{gather*}\BODY\\(\theequation)\end{gather*}%
}
\usepackage{tikz}
\usetikzlibrary{matrix}
\tikzset{
% short hands for colouring the rows and columns of the matrix
coloured row/.style args={#1,#2}{row #1/.style={nodes={fill=#2!20}}},
coloured col/.style args={#1,#2}{column #1/.style={nodes={fill=#2!20}}},
}
%usage: \begin{ColouredMatrix}[coloured row={row colour}, ...]\end{ColouredMatrix}
\NewEnviron{ColouredMatrix}[1][]{%
\tikzpicture[% adjust the size and placement of the delimiters as they are too big by default
every left delimiter/.style={xshift=0.65em,scale=0.9,yshift=0.4em},
every right delimiter/.style={xshift=-0.65em,scale=0.9,yshift=0.4em}]
\matrix [matrix of math nodes, left delimiter=(, right delimiter=),
ampersand replacement=\&, #1]
{ \BODY };
\endtikzpicture%
}
\begin{document}
\begin{multicols}{3}
\noindent
\begin{Equation}\label{one}
\begin{ColouredMatrix}[%
coloured row={1,red}, coloured row={3,blue},
coloured col={1,olive},coloured col={4,yellow}]
0 \& 0 \& 0 \& 0 \\
0 \& 0 \& 0 \& 0 \\
0 \& 0 \& 0 \& 0 \\
0 \& 0 \& 0 \& 0 \\
0 \& 0 \& 0 \& 0 \\
\end{ColouredMatrix}
\end{Equation}
\begin{Equation}\label{two}
\begin{ColouredMatrix}[%
coloured col={1,olive}, coloured col={4,yellow}]
0 \& 0 \& 0 \& 0 \\
0 \& 0 \& 0 \& 0 \\
0 \& 0 \& 0 \& 0 \\
0 \& 0 \& 0 \& 0 \\
0 \& 0 \& 0 \& 0 \\
\end{ColouredMatrix}
\end{Equation}
\begin{Equation}
\begin{ColouredMatrix}[%
coloured col={1,red}, coloured row={3,green}]
0 \& 0 \& 0 \& 0 \\
0 \& 0 \& 0 \& 0 \\
0 \& 0 \& 0 \& 0 \\
0 \& 0 \& 0 \& 0 \\
0 \& 0 \& 0 \& 0 \\
\end{ColouredMatrix}
\end{Equation}
\end{multicols}
Look at \ref{one} and \ref{two}.
\end{document}