TransWikia.com

Arrows in table environment

TeX - LaTeX Asked by Eric Barbarian on August 27, 2020

I want to draw Arrows in my table like below

documentclass[a4paper,11pt]{article}
usepackage[utf8]{inputenc}
usepackage[T1]{fontenc}
usepackage{graphicx}
usepackage{tikz}
usepackage{amsthm}
usepackage{tabularx}
newcolumntype{L}[1]{>{raggedrightarraybackslash}p{#1}} % linksbündig mit Breitenangabe
newcolumntype{C}[1]{>{centeringarraybackslash}m{#1}}
newcolumntype{L}[1]{>{raggedrightarraybackslash}m{#1}}
newcolumntype{N}{@{}m{0pt}@{}}
usepackage{booktabs}

begin{document}
begin{table}centering
{defarraystretch{1}
$begin{array}{C{2.5cm}|C{1cm}C{1cm}C{1cm}C{1cm}C{1cm}|C{1cm}}toprule
$f_{(X,Y)}(x,y)$      & $y=1$          & $y=2$     & $y=5$     & $y=7$    & $y=8$    &      $f_{X}(x)$    midrule
 $x=1$         & 0,08       & 0,02  & 0,04  & 0,12  & 0,06 & color{red} 0,32
$x=2$         & 0,10       & 0,05  & 0,07  & 0,12  & 0,04 & color{red} 0,38
$x=3$         & 0,03       & 0,04  & 0,07  & 0,10  & 0,06 & color{red} 0,3midrule
$f_{Y}(y) $     & color{red}0,21&color{red}0,11 &color{red}0,18 &color{red}0,34 &     color{red}0,16 & 1bottomrule
end{array}$}
end{table}
end{document}

enter image description here

2 Answers

enter image description here

documentclass{article}
usepackage{array}
usepackage{tikz}
usetikzlibrary{tikzmark,arrows,calc}
usepackage{booktabs}
definecolor{hotmagenta}{rgb}{1.0, 0.11, 0.81}

begin{document}
    begin{table}[ht]   % <---
        [
        begin{array}{c|ccccc|c}toprule[1pt]
        f_{(X,Y)}(x,y) & y=1 & y=2 & y=5 & y=7 & y=8 & f_{X}(x)   midrule
        x=1  & tikzmarknode{A} 0,08 & 0,02  & 0,04  & 0,12  & 0,06 & color{hotmagenta}   tikzmarknode{B} 0,32
        x=2  & 0,10 & 0,05  & 0,07  & 0,12  & 0,04 &  color{hotmagenta}  0,38
        x=3  & 0,03 & 0,04  & 0,07  & 0,10  & 0,06 & color{hotmagenta}  0,3midrule
        f_{Y}(y) & tikzmarknode{C} 0,21 & color{hotmagenta} 0,11 & color{hotmagenta}  0,18 & color{hotmagenta}  0,34 & color{hotmagenta}  0,16 & 1 bottomrule[1pt]
        end{array}
        tikz[remember picture,overlay]
        {draw[<-, red, thick, >=stealth] ($(A.east)+(14pt,0pt)$) -- (B);
        draw[<-, blue, thick, >=stealth] ($(A.south)+(6pt,0pt)$) -- ($(C.north)+(6pt,0pt)$);}
        ]
    end{table}
end{document}

Answered by js bibra on August 27, 2020

With nicematrix:

documentclass[a4paper,11pt]{article}
usepackage[T1]{fontenc}
usepackage{booktabs}
usepackage{nicematrix}
usepackage{icomma}
usepackage{tikz}

begin{document}
begin{table}
centering
$begin{NiceArray}{wc{2.5cm}|wc{1cm}wc{1cm}wc{1cm}wc{1cm}wc{1cm}|wc{1cm}}toprule
f_{(X,Y)}(x,y) & y=1          & y=2     & y=5     & y=7    & y=8    &      f_{X}(x)    midrule
x=1            & 0,08       & 0,02  & 0,04  & 0,12  & 0,06 & color{red} 0,32
x=2            & 0,10       & 0,05  & 0,07  & 0,12  & 0,04 & color{red} 0,38
x=3            & 0,03       & 0,04  & 0,07  & 0,10  & 0,06 & color{red} 0,3midrule
f_{Y}(y)       & color{red}0,21&color{red}0,11 &color{red}0,18 &color{red}0,34 & color{red}0,16 & 1
bottomrule
omit CodeAfter
begin{tikzpicture} [line width=1pt] 
  draw[red,->] (2-7.west) -- (2-2.east) ; 
  draw[blue,->] (5-2.north) -- (2-2.south) ; 
end{tikzpicture}
end{NiceArray}$
end{table}
end{document}

Output of the above code

Remarks:

  • With nicematrix, you need several compilations.
  • I have used a wc type for the columns which is easier for this type of array.
  • I have used icomma to have correct spaces around the commas used as decimal point.

Answered by F. Pantigny on August 27, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP