2

I am interesting about drafting the following in LaTeX. I am not so much expert in this, i am going to attach the code to generate the vector and matrix, and after that I am going to attach my desired output.

Code:

\begin{align}
  \begin{pmatrix}a_1\\a_2\\\vdots\\a_k\end{pmatrix}
  \begin{pmatrix}\varepsilon_1&0&\ldots&0\\ 0&\varepsilon_2&\ldots&0\\0&0&\ldots&0\\0&0&\ldots&\varepsilon_N\\ 
   \end{pmatrix}
\end{align}

Output:

enter image description here

So what I want is a circle on the first and last element of vector (a1,..,ak) and an arrow that goes from a1 to the rectangle of first row of matrix, the same for the last row. Sorry if the circle is made in that bad way, I have done it manually, of course is preferred a circle draft in a better way.

Zarko
  • 296,517
  • 1
    Using tikzmark library is a very nice way to do it. And also, feel free to look at the Related menu on the right, where some helpful answers would be found. – SebGlav Sep 10 '21 at 11:16
  • @SebGlav What do you suggest to try on the search bar? I have tried, without result for this kind of problem.. – John_maddon Sep 10 '21 at 12:15
  • Searching (here) for "\tikzmark matrix" did well. See https://tex.stackexchange.com/questions/525421/highlighting-rows-columns-diagonals-in-matrix for example. – John Kormylo Sep 10 '21 at 14:13

4 Answers4

10

With {NiceArray} of nicematrix and Tikz.

\documentclass{article}
\usepackage{nicematrix,tikz}
\usetikzlibrary{fit}

\begin{document}

$\begin{NiceArray}{(c)(cccc)}[create-medium-nodes,nullify-dots] a_1 & \epsilon_1 & 0 & \cdots & 0 \ a_2 & 0 & \epsilon_2 & \cdots & 0 \ \Vdots & 0 & 0 & \cdots & 0 \ a_k & 0 & 0 & \cdots & \epsilon_n \ \CodeAfter \begin{tikzpicture} [cyan,inner sep=1pt] \node [circle,draw,fit=(1-1)] (A) {} ; \node [circle,draw,fit=(4-1)] (B) {} ; \node [draw,rounded corners, fit = (1-2-medium) (1-5-medium)] (C) {} ; \node [draw,rounded corners, fit = (4-2-medium) (4-5-medium)] (D) {} ; \draw [->] (A.north) to [bend left] (C.north west) ; \draw [->] (B.south) to [bend right] (D.south west) ; \end{tikzpicture} \end{NiceArray}$

\end{document}

You need several compilations (because nicematrix uses PGF/Tikz nodes under the hood).

Output of the above code

F. Pantigny
  • 40,250
4

With pure TikZ:

enter image description here

\documentclass[border=3.141592]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                fit,
                matrix,
                positioning}

\begin{document} \begin{tikzpicture}[ node distance = 7mm, FIT/.style = {inner sep=1pt, draw=red, fit=#1}, arr/.style = {draw=blue, -Straight Barb,semithick}, M/.style = {matrix of math nodes, nodes= {minimum size=1em, inner sep=1pt, anchor=base}, column sep=0pt, row sep=3pt, left delimiter=(, right delimiter=), inner sep=2pt}
] \matrix (m) [M] {|[circle,draw=red]| a_1\ a_2\ \vdots \ |[circle,draw=red]|a_k\}; % \matrix (n) [M,right=of m] {\varepsilon_1 & 0 & \ldots & 0 \ 0 &\varepsilon_2 & \ldots & 0 \ 0 & 0 & \ldots & 0 \ 0 & 0 & \ldots & \varepsilon_N \ }; \node (n1) [FIT=(n-1-1) (n-1-4)] {}; \node (n2) [FIT=(n-4-1) (n-4-4)] {}; % \draw[arr] (m-1-1) to[bend left=45] (n1); \draw[arr] (m-4-1) to[bend right=45] (n2); \end{tikzpicture} \end{document}

Zarko
  • 296,517
2

Here is a possibility with a simple pstricks code:

\documentclass[svgnames]{article}
\usepackage{amsmath}
\usepackage{pst-node}

\begin{document}

\[ \psset{linecolor=LightSteelBlue, linearc=0.1, boxsize=0.25, nodesep=1.5pt, arrowinset=0.12} \begin{pmatrix}\circlenode{a1}{a_1}\\a_2\\\vdots\\\circlenode{ak}{a_k}\end{pmatrix}
\begin{pmatrix}\,\Rnode{e1}{\varepsilon_1}&0&\ldots&\Rnode{f1}{0}\\ \, 0 & \varepsilon_2&\ldots&0\\ \,0&0&\ldots&0\\ \,\Rnode{fN}{0}&0&\ldots&\Rnode{eN}{\varepsilon_N}\\
\end{pmatrix}
\ncbox{e1}{f1}\ncbox{eN}{fN}
\nccurve[angle=90, nodesepA=0, nodesepB=5pt]{->}{a1}{e1}
\nccurve[angle=-90, nodesepA=0, nodesepB=3pt]{->}{ak}{fN}
\]%

\end{document} enter image description here

F. Pantigny
  • 40,250
Bernard
  • 271,350
2

And now with a simple TikZ solution, using tikzmark library, as suggested in my comment (note: needs to be compiled a couple of times to compute then display correctly).

nodes on matrix

\documentclass[12pt]{article}
\usepackage{tikz,amsmath}
\usetikzlibrary{tikzmark,fit}

\begin{document}

\begin{align}
    \begin{pmatrix}\tikzmarknode{A1}{a_1}\\a_2\\\vdots\\\tikzmarknode{AK}{a_k}\end{pmatrix}
    \begin{pmatrix}
        \tikzmarknode{E1}{\varepsilon_1}&0&\ldots&\tikzmarknode{0A}{0}\\
        0&\varepsilon_2&\ldots&0\\
        0&0&\ldots&0\\
        \tikzmarknode{0B}{0}&0&\ldots&\tikzmarknode{EN}{\varepsilon_N}\\ 
    \end{pmatrix}
\end{align}

\tikzset{
    circ/.style={inner sep=6pt, outer sep=0pt, line width=1pt, circle, draw=cyan},
    rect/.style={inner sep=2pt, outer sep=0pt, line width=1pt, rounded corners=5pt, draw=cyan}
    }

\begin{tikzpicture}[remember picture,overlay,cyan]
    \node[circ] (a1) at (A1) {};
    \node[circ] (ak) at (AK) {};

    \node[rect,fit=(E1)(0A)] (line1) {};
    \node[rect,fit=(EN)(0B)] (line4) {};

    \draw[-latex,line width=1pt] (a1.north) to[out=60,in=120] (line1.160);
    \draw[-latex,line width=1pt] (ak.south) to[out=-60,in=-120] (line4.-160);

\end{tikzpicture}

\end{document}

SebGlav
  • 19,186