## LaTeX forum ⇒ Graphics, Figures & Tables ⇒ I Need help for highlight row an col in matrix

Information and discussion about graphics, figures & tables in LaTeX documents.
tamer540
Posts: 3
Joined: Sun Sep 14, 2014 10:17 pm

### I Need help for highlight row an col in matrix

Dear All:-
I need help for making figure with highlight row and col in matrix with label
I attach Image for what i wont
anybody can help?
Attachments
anybody can help
Picture1.jpg (20.01 KiB) Viewed 4473 times

Stefan Kottwitz
Posts: 9618
Joined: Mon Mar 10, 2008 9:44 pm
Welcome to the forum!

Sure, that can be done for example with TikZ. Here's a way, I would do it similarly: Highlighting elements in matrices.

Specifically, I would use the tikzmark package, but it's not required. I would have posted the code, if you would have posted the starting code as a minimal compilable example. I don't spend time just typing a matrix. But perhaps the above linked example already shows you the way.

Stefan

tamer540
Posts: 3
Joined: Sun Sep 14, 2014 10:17 pm
my code is :
1. \documentclass[a4paper]{article}
2. \usepackage[english]{babel}
3. \usepackage[utf8x]{inputenc}
4. \usepackage[colorinlistoftodos]{todonotes}
5.
6. \begin{document}
7. \begin{figure}
8. \usetikzlibrary{fit}
9. \tikzset{%
10. highlight/.style={rectangle,rounded corners,fill=red!15,draw,
11. fill opacity=0.5,thick,inner sep=0pt}
12. }
13. \newcommand{\tikzmark}[2]{\tikz[overlay,remember picture,
14. baseline=(#1.base)] \node (#1) {#2};}
15. %
16. \newcommand{\Highlight}[1][row]{%
17. \tikz[overlay,remember picture]{
18. \node[highlight,fit=(left.north west) (right.south east)] (#1) {};}
19. }
20.
21. $22. X = \left(\begin{array}{*5{c}} 23. \tikzmark{left}{x_{1,1}} & x_{1,2} & x_{1,3} & x_{1,4} & \tikzmark{right}{x_{1,5}} \\ 24. 6 & 7 & 8 & 9 & 10 \\ 25. 11 & 12 &13 & 14 & 15 \\ 26. 16 & 17 & 18 & 19 & 20 27. \end{array}\right) 28. \Highlight[first] 29. \qquad 30. M^T = \left(\begin{array}{*5{c}} 31. \tikzmark{left}{1} & 6 & 11 & 16 \\ 32. 2 & 7 & 12 & 17 \\ 33. 3 & 8 & \tikzmark{right}{13} & 18 \\ 34. 4 & 9 & 14 & 19 \\ 35. 5 & 10 & 15 & 20 36. \end{array}\right) 37.$
38. %\Highlight[second]
39. %
40. \tikz[overlay,remember picture] {
41. % \draw[->,thick,red,dashed] (first) -- (second) node [pos=0.66,above] {Transpose};
42. % \node[above of=first] {$N$};
43. % \node[above of=second] {$N^T$};
44. }
45.
46. \end{figure}
47. \end{document}

tomV
Posts: 2
Joined: Sun Feb 21, 2021 11:38 pm
Hi Stefan,

I posted this question in the new members area but subsequently found that you are an administrator and more to the point the person to whom I should address this question.

Firstly thanks for your posting of this code way back which I came across a week or two ago.

Hopefully you have the time to revisit this area and can give me some pointers as to how I can modify your code to allow for the ability to have three different styles that encompass three different three different colors such that you can highlight element in different matrices each with a different color.

Example: Highlighting elements in matrices
by tomV » Sun Feb 21, 2021 3:58 pm

The posting by Stefan Kottwitz under the title in the Subject line is a great example for Highlighting a Submatrix.

I was wondering if it is possible to have three styles such that under each style you can choose a different color to Highlight a different submatrix?

So far I have found that \.style takes arguments but after that I am lost.

Here is my dilemma. How do I modify Stefan's code such that I can define the three styles and then how do I identify these differing styles when I identify the area to be highlighted as a submatrix using \tikzmark?

Bartman
Posts: 159
Joined: Fri Jan 03, 2020 2:39 pm
Please do not attach your question to an old topic, but start a new one.

Since October of last year, several commands from the xparse package have been transferred to the LaTeX kernel. You can find out more in ltnews on the CTAN website.

With the help of a command like \NewDocumentCommand you can create a command that can have more than one optional argument.

Section 4 "Efficient use of TikZ styles" of the hf-tikz package shows a different approach.

tomV
Posts: 2
Joined: Sun Feb 21, 2021 11:38 pm