how to apply colorbox to a row or a column in matrix #3785
Replies: 2 comments
-
Sadly I don't think this is possible in KaTeX proper, but it'd be great to support Meanwhile, I imagine it might be possible with some CSS hacking. |
Beta Was this translation helpful? Give feedback.
-
@sophia-hye Did you have any luck getting any CSS hack to work? I couldn't see how to do it since the \align environment uses columns and shading the spaces between the columns proved a challenge. Here's a hacky solution (the purists will be horrified) which looks OK. Put the matrix elements in a HTML table and surround it with parentheses:
Style it as follows:
The result, with ordinary KaTeX rendering of the matrix for layout comparison: Hope it's of some use. Regards |
Beta Was this translation helpful? Give feedback.
-
question
I want to fill cell's background of my matrix in diagonal. I tried to use colorbox but the result is not pretty. (not aligned background..) Is there a way to do this?
expected result
※ I use this result on overleaf using latex and package.
This is the latex code.
\documentclass{article} \usepackage{graphicx} % Required for inserting images \usepackage[table]{xcolor}\newcommand\bgcell{\cellcolor{lightgray}}
\begin{document}
\begin{equation}
\sum=\left(\begin{array}{cccc}
\rowcolor{lightgray}
\sigma_{x_1}^2 & \sigma_{x_1x_2} & \sigma_{x_1x_3} \
\sigma_{x_1x_2} & \bgcell \sigma_{x_2}^2 & \bgcell \sigma_{x_2x_3} \
\sigma_{x_1x_3} & \sigma_{x_2x_3} & \bgcell \sigma_{x_3}^2 \
\end{array}\right)
\end{equation}
\end{document}
katex code
\begin{align}
\sum=\left(\begin{array}{}
\colorbox{gray}{$\sigma_{x_1}^2$} & \colorbox{gray}{$\sigma_{x_1x_2}$} & \sigma_{x_1x_3} \[0.5em]
\sigma_{x_1x_2} & \sigma_{x_2}^2 & \sigma_{x_2x_3} \[0.5em]
\sigma_{x_1x_3} & \sigma_{x_2x_3} & \sigma_{x_3}^2 \
\end{array}\right)
\end{align}
katex code result
Beta Was this translation helpful? Give feedback.
All reactions