5

I try to color the diagonal of a matrix.

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

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}
8
\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}

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

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

\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}

enter image description here

6

Welcome, you can use something like this:

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

Result:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.