Math & Science ⇒ Box around matrix entries
-
- Posts: 3
- Joined: Fri Nov 27, 2009 10:19 pm
Box around matrix entries
I am trying to put coloured boxes around certain minors of an nxn matrix, but am unable to find anywhere on the web how to do this, and I was therefore hoping someone may have a suggestion on how to do this. Thank you in advance,
Jong-il
NEW: TikZ book now 40% off at Amazon.com for a short time.
And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Box around matrix entries
Code: Select all
\documentclass[english]{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{amsmath}
\usepackage[table]{xcolor}
\begin{document}
\[
\begin{pmatrix}
\cellcolor{gray} 1 & 0 & 0 \\
0 & \cellcolor{gray} 1 & 0 \\
0 & 0 & \cellcolor{gray} 1
\end{pmatrix}
\]
\[
\left(
\begin{array}{ccc}
\cellcolor{gray} 1 & 0 & 0 \\
0 & \cellcolor{gray} 1 & 0 \\
0 & 0 & \cellcolor{gray} 1
\end{array}
\right)
\]
\end{document}
Further information about the packages as well as their manuals can be found on CTAN.
Best regards and welcome to the board
Thorsten
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
-
- Posts: 3
- Joined: Fri Nov 27, 2009 10:19 pm
Re: Box around matrix entries
After colouring several separate cells, I would like to put a frame around them. i.e. in your matrix I would like to colour the cells in the minor consisting of the entries in the 1st and 2nd row and column, and then put a frame around these 4 entries.
Thank you in advance,
Jong-il
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Box around matrix entries
Code: Select all
\documentclass[english]{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{amsmath}
\usepackage[table]{xcolor}
\begin{document}
\[
\left(
\begin{array}{ccc}
\cellcolor{gray!25} a_{11} & \cellcolor{gray!25} a_{12} & a_{13} \\
\cellcolor{gray!25} a_{21} & \cellcolor{gray!25} a_{22} & a_{23} \\
a_{31} & a_{32} & a_{33}
\end{array}
\right)
\]
\[
\left(
\begin{array}{ccc}\cline{1-2}
\multicolumn{1}{|c}{a_{11}} & \multicolumn{1}{c|}{a_{12}} & a_{13} \\
\multicolumn{1}{|c}{a_{21}} & \multicolumn{1}{c|}{a_{22}} & a_{23} \\ \cline{1-2}
a_{31} & a_{32} & a_{33}
\end{array}
\right)
\]
\[
\left(
\begin{array}{ccc}\cline{1-2}
\multicolumn{1}{|c}{\cellcolor{gray!25} a_{11}} & \multicolumn{1}{c|}{\cellcolor{gray!25} a_{12}} & a_{13} \\
\multicolumn{1}{|c}{\cellcolor{gray!25} a_{21}} & \multicolumn{1}{c|}{\cellcolor{gray!25} a_{22}} & a_{23} \\ \cline{1-2}
a_{31} & a_{32} & a_{33}
\end{array}
\right)
\]
\end{document}
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10