Draw an arrow that connect each column by the corresponding entry in LaTeX

  • Context: LaTeX 
  • Thread starter Thread starter EngWiPy
  • Start date Start date
  • Tags Tags
    Column Latex
Click For Summary

Discussion Overview

The discussion revolves around drawing arrows in LaTeX using the TikZ package to connect corresponding entries in a matrix. Participants explore how to label nodes and create arrows between specific elements of a matrix, as well as addressing additional questions about modifying the matrix structure.

Discussion Character

  • Technical explanation
  • Exploratory

Main Points Raised

  • One participant seeks assistance in drawing arrows that connect each column entry to a corresponding entry in a separate row using LaTeX and TikZ.
  • Another participant provides a solution by labeling matrix areas with node names and demonstrates how to draw arrows between these nodes.
  • The solution includes an example of how to implement the arrow drawing in the provided LaTeX code.
  • A later reply expresses satisfaction with the provided solution, indicating it meets the original request.
  • Another participant introduces a new question about how to remove a cell completely from the matrix.

Areas of Agreement / Disagreement

Participants generally agree on the method for drawing arrows in LaTeX, as one participant successfully implements the suggested solution. However, the discussion remains unresolved regarding the new question about removing a cell from the matrix.

Contextual Notes

There are no explicit limitations noted, but the discussion does not address the specifics of how to remove a cell from the matrix, leaving that question open for further exploration.

EngWiPy
Messages
1,361
Reaction score
61
Hello,

I have the following Latex code, and I need to draw an arrow that connect each column by the corresponding entry in the last (separated) row, e.g.: the column [x_0^{(1)} x_0^{(2)} ... x_0^{(M)}]^T with the entry x_0^{(R)} and so on. How can I do that?

Code:
\documentclass{article}
\usepackage{tikz}
\usepackage{amsmath}
\usetikzlibrary{matrix}
\begin{document}

\tikzset{ 
    table/.style={
        matrix of nodes,
        row sep=-\pgflinewidth,
        column sep=-\pgflinewidth,
        nodes={
            rectangle,
            draw=black,
            align=center
        },
        minimum height=1.5em,
        text depth=0.5ex,
        text height=2ex,
        nodes in empty cells,
%%
        %every even row/.style={
            %nodes={fill=gray!20}
        %},
        column 1/.style={
            nodes={text width=2em,font=\bfseries}
        },
				column 2/.style={
            nodes={text=red}
        },
				column 3/.style={
            nodes={text=blue}
        },
				column 5/.style={
            nodes={text=violet}
        },
        row 5/.style={
            nodes={
                fill=gray!20,
                %text=black,
                font=\bfseries
            }
        }
    }
}

\begin{tikzpicture}

\matrix (first) [table,text width=6em]
{
$\mathbf{x}^{(1)}$   & $x_0^{(1)}$ & $x_1^{(1)}$ & $\cdots$ & $x_{N-1}^{(1)}$ \\
$\mathbf{x}^{(2)}$   & $x_0^{(2)}$ & $x_1^{(2)}$ & $\cdots$ & $x_{N-1}^{(2)}$ \\
$\vdots$             & $\vdots$    & $\vdots$    & $\ddots$ & $\vdots$ \\
$\mathbf{x}^{(M)}$   & $x_0^{(M)}$ & $x_1^{(M)}$ & $\cdots$ & $x_{N-1}^{(M)}$ \\[10mm]
$\mathbf{x}^{(R)}$   & $x_0^{(R)}$ & $x_1^{(R)}$ & $\cdots$ & $x_{N-1}^{(R)}$ \\
};


\end{tikzpicture}
\end{document}

Thanks in advance
 
Physics news on Phys.org
I did one for you. I checked out this site for examples, always love learning new latex packages.

www.texample.net/tikz/examples/feature/arrows/

Basically I labelled to areas using the label maker for nodes : |[name=a]|

Then after the matrix I drew an arrow from a to b. So repeat wherever you need it.

Code:
\matrix (first) [table,text width=6em]
{
$\mathbf{x}^{(1)}$   & $x_0^{(1)}$ & $x_1^{(1)}$ & $\cdots$ & $x_{N-1}^{(1)}$ \\
$\mathbf{x}^{(2)}$   & $x_0^{(2)}$ & $x_1^{(2)}$ & $\cdots$ & $x_{N-1}^{(2)}$ \\
$\vdots$             & $\vdots$    & $\vdots$    & $\ddots$ & $\vdots$ \\
|[name=a]| $\mathbf{x}^{(M)}$   & $x_0^{(M)}$ & $x_1^{(M)}$ & $\cdots$ & $x_{N-1}^{(M)}$\\[10mm]
|[name=b]| $\mathbf{x}^{(R)}$   & $x_0^{(R)}$ & $x_1^{(R)}$ & $\cdots$ & $x_{N-1}^{(R)}$ \\
};
 \draw[->,thick] (a) edge (b);
 
Hepth said:
I did one for you. I checked out this site for examples, always love learning new latex packages.

www.texample.net/tikz/examples/feature/arrows/

Basically I labelled to areas using the label maker for nodes : |[name=a]|

Then after the matrix I drew an arrow from a to b. So repeat wherever you need it.

Code:
\matrix (first) [table,text width=6em]
{
$\mathbf{x}^{(1)}$   & $x_0^{(1)}$ & $x_1^{(1)}$ & $\cdots$ & $x_{N-1}^{(1)}$ \\
$\mathbf{x}^{(2)}$   & $x_0^{(2)}$ & $x_1^{(2)}$ & $\cdots$ & $x_{N-1}^{(2)}$ \\
$\vdots$             & $\vdots$    & $\vdots$    & $\ddots$ & $\vdots$ \\
|[name=a]| $\mathbf{x}^{(M)}$   & $x_0^{(M)}$ & $x_1^{(M)}$ & $\cdots$ & $x_{N-1}^{(M)}$\\[10mm]
|[name=b]| $\mathbf{x}^{(R)}$   & $x_0^{(R)}$ & $x_1^{(R)}$ & $\cdots$ & $x_{N-1}^{(R)}$ \\
};
 \draw[->,thick] (a) edge (b);

Perfect. Look very nice. Thanks
 
Another question: How can I remove a cell completely?
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 0 ·
Replies
0
Views
6K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 0 ·
Replies
0
Views
4K
  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 4 ·
Replies
4
Views
3K