# Coloring the diagonal of a matrix

I try to color the diagonal of a matrix.

$$C= \begin{bmatrix} 1 & 1 & 0\\ 0 & 1 & 1\\ 1 & 0 & 1\\ \end{bmatrix}$$


All I found was related to rows and columns (see. https://tex.stackexchange.com/a/69714/74926 and http://www.alecjacobson.com/weblog/?p=1289) Could someone may help.

I already found this. Sadly the line overlay the text and the brackets. Some further help would be great.

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}

\newcommand{\tikzmark}[2]{
\tikz[overlay,remember picture,baseline]
\node[anchor=base] (#1) {$#2$};
}

\begin{document}
$\begin{pmatrix} \tikzmark{top}{1} & \tikzmark{top2}{1} & 0 \\ 0 & 1 & \tikzmark{bottom2}{1} \\ \tikzmark{end}{1} & 0 & \tikzmark{bottom}{1}\\ \end{pmatrix}$

\begin{tikzpicture}[overlay,remember picture]
\draw[red,line width=1mm,line cap=round] (top.north west) -- (bottom.south east);
\draw[red,line width=1mm,line cap=round] (top2.north west) -- (bottom2.south east);
\draw[red,line width=1mm,line cap=round] (end.north west) -- (end.south east);
\end{tikzpicture}
\end{document}


\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}

\newcommand{\tikzmark}[2]{
\tikz[overlay,remember picture,baseline]
\node[anchor=base] (#1) {$#2$};
}

\begin{document}
$$\begin{pmatrix} \tikzmark{top}{1} & \tikzmark{top2}{1} & 0 \\ 0 & 1 & \tikzmark{bottom2}{1} \\ \tikzmark{end}{1} & 0 & \tikzmark{bottom}{1}\\ \end{pmatrix}$$

\begin{tikzpicture}[overlay,remember picture]
\draw[opacity=.4,line width=3mm,line cap=round] (top.center) -- (bottom.center);
\draw[opacity=.4,line width=3mm,line cap=round] (top2.center) -- (bottom2.center);
\draw[opacity=.4,line width=3mm,line cap=round] (end.center) -- (end.center);
\end{tikzpicture}
\end{document}


Welcome, you can use something like this:

\documentclass[a4paper]{article}
\usepackage{amsmath,amssymb,xcolor}
\newcommand\RED{\color{red}}
\begin{document}
$$C= \begin{bmatrix} \RED 1 & 1 & 0\\ 0 & \RED 1 & 1\\ 1 & 0 & \RED 1\\ \end{bmatrix}$$
\end{document}


Result: