# Change font color of a column in a matrix

I have this code:

\documentclass[a4paper,11pt]{article}

\usepackage{amsmath}

\begin{document}

$A = \begin{bmatrix} a & b & c & d \\ a & b & c & d \\ a & b & c & d \\ a & b & c & d \\ \end{bmatrix}$

\end{document}


What I want to do is change the color of the first and third column to red.

If you want to automate this process for an entire column, then you need to have access to the column specification. This is not possible via amsmath's *matrix environments. Instead, use array and insert \color{red} in front of every entry using the >{<prefix>} specification:

\documentclass{article}

\usepackage{amsmath,array,xcolor}

\begin{document}

$A = \begin{bmatrix} a & b & c & d \\ a & b & c & d \\ a & b & c & d \\ a & b & c & d \end{bmatrix} \qquad \left[\begin{array}{@{} >{\color{red}}c c >{\color{red}}c c @{}} a & b & c & d \\ a & b & c & d \\ a & b & c & d \\ a & b & c & d \end{array}\right] = A$

\end{document}


A Little bit easier!

\documentclass[a4paper,11pt]{article}

\usepackage{amsmath}
\usepackage{color}

\begin{document}

$A = \def\b{b} \def\d{d} \def\a{\color{red}a} \def\c{\color{red}c} \begin{bmatrix} \a & \b & \c & \d \\ \a & \b & \c & \d \\ \a & \b & \c & \d \\ \a & \b & \c & \d \\ \end{bmatrix}$

\end{document}


• I'm sure the OP made the matrix A have similar rows out of ease for a minimal example. In general, how would your suggestion be "easier" if the columns had arbitrary content in them? – Werner Jan 26 '17 at 20:06
• @Werner: I don't claim to offer something generic. My assumption was this is what the OP needs, inherently. Actually, I was not as sure as you are! :D – Roboticist Jan 26 '17 at 20:10
• Werner is right. However, thank you for your answer @Roboticist. It can be useful for another purpose ! – Thanasis1101 Jan 26 '17 at 20:18

Based on How to color math symbols? or Simpler way to add color to equations in math mode? (I googled "math color latex").

\documentclass[a4paper,11pt]{article}

\usepackage{amsmath}

\usepackage{xcolor}

\begin{document}

$$A = \begin{bmatrix} \textcolor{red}{a} & b & \textcolor{red}{c} & d \\ \textcolor{red}{a} & b & \textcolor{red}{c} & d \\ \textcolor{red}{a} & b & \textcolor{red}{c} & d \\ \textcolor{red}{a} & b & \textcolor{red}{c} & d \\ \end{bmatrix}$$

\end{document}


• I wanted an automatic way to change the color of the columns (like the accepted answer), but thank you for your answer ! – Thanasis1101 Jan 26 '17 at 20:15