2

I would like to highlight some elements in a matrix and link them with arrows to their definition given on the matrix side (like in the picture below). I know there are possibilities to highlight elements in a matrix with TikZ, but is it possible to have boxes, arrows, and text (math symbols) on the side? What is the easiest way to do this? Is it possible to do this without TikZ?enter image description here

Here is my code so far:

\documentclass[twocolumn]{article}
\usepackage{mathtools}
\mathtoolsset{showonlyrefs}

\begin{document}
\begin{eqnarray}
    \mathbf{N} &=& \begin{pmatrix}
        n_{11} & 0 & n_{13} & n_{14} \\
        n_{21} & n_{22} & n_{23} & n_{24} \\
        n_{31} & n_{32} & n_{33} & 0 \\
        n_{41} & n_{42} & n_{43} & n_{44} 
    \end{pmatrix}\\
     &=& \begin{pmatrix}
        \sqrt{\beta_x} & 0 & n_{13} & n_{14} \\
        -\frac{\alpha_x}{\sqrt{\beta_x}} & n_{22} & n_{23} & n_{24} \\
        n_{31} & n_{32} & \sqrt{\beta_y} & 0 \\
        n_{41} & n_{42} & -\frac{\alpha_y}{\sqrt{\beta_y}} & n_{44} 
    \end{pmatrix}
\end{eqnarray}

\end{document}

Thank you already for your help!

3
  • 1
    The easiest way to overlap arrows and text is to put \tikzmarks into the matrix and overlay a tikzpicture. There are many example here. Apr 1, 2022 at 13:36
  • 1
    Welcome to TeX.SE. I'd second @JohnKormylo's suggestion to use \tikzmark (depending on how the matrices are written). FYI, It is always best to compose a fully compilable MWE that sets up the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. In this case the MWE could produce the two matrcies -- the solution's depend on exactly how you are creating the matrices. Apr 1, 2022 at 17:22
  • Thank you very much for your comment. I edited my question to add the MWE with the two matrices! I will try to learn more about \tikzmark, but I have never used TikZ before, so any advice is welcome! :)
    – Marion V.
    Apr 2, 2022 at 15:30

1 Answer 1

4

This is with TikZ, forgive me.

The problem is that what you want to draw is too large for only one column of a two-column document.

Here are two possible solutions: in one column, with different positions of the description, or in two columns.

\documentclass[twocolumn]{article}
\usepackage{mwe}% <--- for testing purpose only
\usepackage{cuted}
\usepackage{tikz}
\usetikzlibrary{matrix, fit}
\usetikzlibrary{arrows.meta}
\tikzset{mymatrixstyle/.style={matrix of math nodes,
        ampersand replacement=\&,
        left delimiter=(,
        right delimiter=), 
        inner sep=0pt,
        outer sep=0pt,
        row sep=2pt, column sep=10pt},
        myarrow/.style={-{Straight Barb[angle=60:3pt 3]}}}
\usepackage{mathtools}
\mathtoolsset{showonlyrefs}

\begin{document} 
\blindtext % <--- for testing purpose only

In one column:
%\begin{eqnarray} see https://tex.stackexchange.com/a/197/101651
\begin{align}
    \mathbf{N} &= \begin{pmatrix}
        n_{11} & 0 & n_{13} & n_{14} \\
        n_{21} & n_{22} & n_{23} & n_{24} \\
        n_{31} & n_{32} & n_{33} & 0 \\
        n_{41} & n_{42} & n_{43} & n_{44} 
    \end{pmatrix}\\
     &= \begin{tikzpicture}[baseline]
        \matrix[mymatrixstyle] (mymatr) {
        \sqrt{\beta_x} \& 0 \& n_{13} \& n_{14} \&[-7pt]\\
        -\dfrac{\alpha_x}{\sqrt{\beta_x}} \& n_{22} \& n_{23} \& n_{24} \\
        n_{31} \& n_{32} \& \sqrt{\beta_y} \& 0 \\
        n_{41} \& n_{42} \& -\dfrac{\alpha_y}{\sqrt{\beta_y}} \& n_{44}\\};
        \node[draw, fit=(mymatr-3-1)(mymatr-3-2)] (n3132) {};
        \node[draw, fit=(mymatr-4-1)(mymatr-4-2)] (n4142) {};
        \node[draw, fit=(mymatr-1-3)(mymatr-1-4)] (n1314) {};
        \node[draw, fit=(mymatr-2-3)(mymatr-2-4)] (n2324) {};
        \draw[myarrow, overlay] (n3132) -- ++(-1.8,0) -| +(0,-1.6) node[anchor=north] {$\zeta_y=n_{31}+in_{32}$};
        \draw[myarrow] (n4142) -- +(0,-1.8) node[anchor=north] {$\tilde{\zeta}_y=n_{41}-in_{42}$};
        \draw[myarrow, overlay] (n1314) -- ++(2,0) -|  +(0,-3.6) node[anchor=20] {$\zeta_y=n_{13}-in_{14}$};
        \draw[myarrow, overlay] (n2324) -- ++(1.4,0) -|  +(0,-2.1) node[anchor=20] {$\tilde{\zeta}_y=n_{23}-in_{24}$};
    \end{tikzpicture}        
\end{align}

\blindtext[7] % <--- for testing purpose only

In two columns:

\begin{strip}
\begin{align}
    \mathbf{N} &= \begin{pmatrix}
        n_{11} & 0 & n_{13} & n_{14} \\
        n_{21} & n_{22} & n_{23} & n_{24} \\
        n_{31} & n_{32} & n_{33} & 0 \\
        n_{41} & n_{42} & n_{43} & n_{44} 
    \end{pmatrix}\\
     &= \begin{tikzpicture}[baseline]
        \matrix[mymatrixstyle] (mymatr) {
        \sqrt{\beta_x} \& 0 \& n_{13} \& n_{14} \&[-7pt]\\
        -\dfrac{\alpha_x}{\sqrt{\beta_x}} \& n_{22} \& n_{23} \& n_{24} \\
        n_{31} \& n_{32} \& \sqrt{\beta_y} \& 0 \\
        n_{41} \& n_{42} \& -\dfrac{\alpha_y}{\sqrt{\beta_y}} \& n_{44}\\};
        \node[draw, fit=(mymatr-3-1)(mymatr-3-2)] (n3132) {};
        \node[draw, fit=(mymatr-4-1)(mymatr-4-2)] (n4142) {};
        \node[draw, fit=(mymatr-1-3)(mymatr-1-4)] (n1314) {};
        \node[draw, fit=(mymatr-2-3)(mymatr-2-4)] (n2324) {};
        \draw[myarrow, overlay] (n3132) -- +(-1.8,0) node[anchor=east] {$\zeta_y=n_{31}+in_{32}$};
        \draw[myarrow, overlay] (n4142) -- +(-1.8,0) node[anchor=east] {$\tilde{\zeta}_y=n_{41}-in_{42}$};
        \draw[myarrow, overlay] (n1314) -- +(1.8,0) node[anchor=west] {$\zeta_y=n_{13}-in_{14}$};
        \draw[myarrow, overlay] (n2324) -- +(1.8,0) node[anchor=west] {$\tilde{\zeta}_y=n_{23}-in_{24}$};
    \end{tikzpicture}        
\end{align}
\end{strip}

\blindtext[7] % <--- for testing purpose only
\end{document}

enter image description here

enter image description here

Off-topic: do not use eqnarray, see here for the reasons: https://tex.stackexchange.com/a/197/101651

You must log in to answer this question.

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