Graphics, Figures & TablesI Need help for highlight row an col in matrix

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
tamer540

I Need help for highlight row an col in matrix

Post by tamer540 »

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
anybody can help
Picture1.jpg (20.01 KiB) Viewed 8369 times

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

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

Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

I Need help for highlight row an col in matrix

Post by Stefan Kottwitz »

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
LaTeX.org admin
tamer540

I Need help for highlight row an col in matrix

Post by tamer540 »

Please Help i can`t fix what i need
my code is :

Code: Select all

\documentclass[a4paper]{article}
\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage[colorinlistoftodos]{todonotes}

\begin{document}
\begin{figure}
\usetikzlibrary{fit}
\tikzset{%
  highlight/.style={rectangle,rounded corners,fill=red!15,draw,
    fill opacity=0.5,thick,inner sep=0pt}
}
\newcommand{\tikzmark}[2]{\tikz[overlay,remember picture,
  baseline=(#1.base)] \node (#1) {#2};}
%
\newcommand{\Highlight}[1][row]{%
    \tikz[overlay,remember picture]{
    \node[highlight,fit=(left.north west) (right.south east)] (#1) {};}
}

\[
  X = \left(\begin{array}{*5{c}}
    \tikzmark{left}{$x_{1,1}$} & x_{1,2} & x_{1,3} & x_{1,4} & \tikzmark{right}{$x_{1,5}$} \\
    6 & 7 & 8 & 9 & 10 \\
    11 & 12 &13 & 14 & 15 \\
    16 & 17 & 18 & 19 & 20
  \end{array}\right)
  \Highlight[first]
 \qquad 
 M^T = \left(\begin{array}{*5{c}}
    \tikzmark{left}{1} & 6 & 11 & 16 \\
    2 & 7 & 12 & 17 \\
    3 & 8 & \tikzmark{right}{13} & 18 \\
    4 & 9 & 14 & 19 \\
    5 & 10 & 15 & 20
  \end{array}\right) 
\]
%\Highlight[second]
%
\tikz[overlay,remember picture] {
%  \draw[->,thick,red,dashed] (first) -- (second) node [pos=0.66,above] {Transpose};
 % \node[above of=first] {$N$};
%  \node[above of=second] {$N^T$};
}

\end{figure}
\end{document}
tomV
Posts: 2
Joined: Sun Feb 21, 2021 11:38 pm

I Need help for highlight row an col in matrix

Post by tomV »

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: 369
Joined: Fri Jan 03, 2020 2:39 pm

I Need help for highlight row an col in matrix

Post by Bartman »

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

I Need help for highlight row an col in matrix

Post by tomV »

@Bartman thanks for your advise and tips.
Post Reply