3

Can a single column and row be highlighted within a matrix ? Would like to add some text and arrow that describes a given row within a matrix, something like :

enter image description here

latex code for above matrices :

\begin{gather*}
\begin{bmatrix}
  1 & 2 & 3 \\ 1 & 2 & 3
\end{bmatrix}
*
\begin{bmatrix}
  1 & 2 & 3 \\ 1 & 2 & 3
\end{bmatrix}
\end{gather*}

3 Answers 3

6

It's very easy with tikz:

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{positioning, arrows.meta}
\tikzset{%
    myarrow/.style = {-Stealth, shorten >=5pt}
} 
\newcommand{\mypoint}[2]{\tikz[remember picture]{\node[inner sep=0, anchor=base](#1){$#2$};}}

\begin{document}
    blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
    \begin{gather*}
    \begin{bmatrix}
    1 & 2 & 3 \\ \mypoint{here1}{1} & 2 & 3
    \end{bmatrix}
    *
    \begin{bmatrix}
    1 & 2 & \mypoint{here2}{3} \\ 1 & 2 & 3
    \end{bmatrix}
    \end{gather*}
    \begin{tikzpicture}[remember picture, overlay]
      \node[below=30pt of here1](textofhere1){some text};
      \draw[myarrow] (textofhere1) -- (here1);
      \node[right=30pt of here2](textofhere2){some other text};
      \draw[myarrow] (textofhere2) -- (here2);
    \end{tikzpicture}
    \vspace{7ex}

    blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
\end{document}

enter image description here

4
  • thanks but rendering on Overleaf shows arrows overlapping the text : overleaf.com/12495476fvqytcsgtntn , is this not related to your code and is something related to Overleaf ?
    – blue-sky
    Commented Dec 3, 2017 at 20:43
  • @blue-sky I see your link correctly, is it exactly where you got the problem?
    – CarLaTeX
    Commented Dec 3, 2017 at 20:54
  • yes, i can see it also fine, maybe an issue with my browser, anyway all good now, thanks!
    – blue-sky
    Commented Dec 3, 2017 at 21:24
  • @blue-sky I've edited my answer. Please note that I removed \overlay from \mypoint macro. It was wrong, mainly because it could give problems when the cell text is larger than the others. Now it always works.
    – CarLaTeX
    Commented Dec 4, 2017 at 6:10
3

With pstricks:

\documentclass[11pt, svgnames]{article}
\usepackage{amsmath}
\usepackage{pst-node}
\usepackage{auto-pst-pdf} %% to compile with pdflatex --enable-write18 (MiKTeX) or pdflatex -shell-escape (TeXLive, MacTeX)

\begin{document}

\[ \begin{pspicture}
    \begin{bmatrix}
      1 & 2 & 3 \\ \rnode{B}{1} & 2 & 3
    \end{bmatrix}
    *
    \begin{bmatrix}
      1 & 2 & \rnode{T}{3} \\ 1 & 2 & 3
    \end{bmatrix}
    \psset{labelsep = 2em, nodesepA = 0.3ex, nodesepB = 0.8ex, arrows = ->, arrowinset = 0.12, linewidth = 0.6pt, linecolor = Tomato}
    \everypsbox{\color{Tomato}}
    \uput[r](T){\rnode{T1}{\text{Text1}}}\ncline{T1}{T}
    \uput[d](B){\rnode{T2}{\text{Text2}}}\ncline{T2}{B}
  \end{pspicture} \]

\end{document} 

(If you don't want to compile with pdflatex, remove loading of auto-pst-pdf)

enter image description here

2

If it's OK to have the arrows above the matrix, you could (ab)use the gmatrix environment from the gauss package to place them. Two possibilities for making the arrows are shown.

No \vspace required.

output of code

\documentclass{article}
\usepackage{amsmath,gauss,tikz}
% modify some things in gmatrix environments
\renewcommand\rowmultlabel{}
\renewcommand\colmultlabel{}
\setlength\rowarrowsep{0pt}
\setlength\rowopminsize{0pt}
\begin{document}
Some text text text text and so on.
\begin{equation*}
\begin{gmatrix}[b]
  1 & 2 & 3 \\
  1 & 2 & 3
\colops
\mult{0}{\begin{array}{c}\text{text 1}\\\downarrow\end{array}}
\end{gmatrix}
\!*
\begin{gmatrix}[b]
  1 & 2 & 3 \\
  1 & 2 & 3
\rowops
\mult{0}{\leftarrow\text{text 2}}
\end{gmatrix}
\end{equation*}
More text text text text text and so on.
\begin{equation*}
\begin{gmatrix}[b]
  1 & 2 & 3 \\
  1 & 2 & 3
\colops
\mult{0}{\tikz\draw[<-](0,0)--(0,5mm)node[above]{text 1};}
\end{gmatrix}
\!*
\begin{gmatrix}[b]
  1 & 2 & 3 \\
  1 & 2 & 3
\rowops
\mult{0}{\tikz[baseline=(a.base)]\draw[<-](0,0)--(5mm,0)node[name=a,right]{text 2};}
\end{gmatrix}
\end{equation*}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .