5

I need to draw some arrow marks in the border some cells in a tabular. That arrow should start from the bottom right corner of the cell and end at top right corner of the cell. I have drawn such arrows tikzmark and calc libraries. The following is my solution

\newcommand\cellarrow[1]{%
    \begin{tikzpicture}[remember picture, overlay, >=stealth, shift={(0,0)}]
      \draw[->, line width=2pt,color =brown]  ( $ (pic cs:#1) +(2.7\tabcolsep,-1ex) $ )  to   ( $ (pic cs:#1) +(16pt,2.5ex) $ ) ;
    \end{tikzpicture}%
    }

enter image description here

Obviously This is not a good solution since it works well width only a particular table shown in Section 1. So we need to some how position the bottom right corner and draw the arrow with the height same as that of the corresponding cell.

How to do this?

Any idea is highly appreciated.

MWE:

\documentclass{article}

\usepackage{tikz}
\usepackage{xcolor}

\usetikzlibrary{calc,tikzmark}


\newcommand\cellarrow[1]{%
\begin{tikzpicture}[remember picture, overlay, >=stealth, shift={(0,0)}]
  \draw[->, line width=2pt,color =brown]  ( $ (pic cs:#1) +(2.7\tabcolsep,-1ex) $ )  to   ( $ (pic cs:#1) +(16pt,2.5ex) $ ) ;
\end{tikzpicture}%
}
\def\done{done}


    \begin{document}
    \section{Table with Same width}
            \begin{tabular}{|l|c|c|c|c|c|c|}
        \hline
        Some column  & \done & \done &  \done&  \done& \done&\done \\
        \hline
        This has arrows&\tikzmark{a}   & \tikzmark{b} & \tikzmark{c} & & &  \\
        \hline
        Communication of Papers
        & &  & &  & &    \\ \hline  
    \end{tabular}
        \cellarrow{a} 
        \cellarrow{b} 
        \cellarrow{c} 



    \section{Some other table}
    \renewcommand{\arraystretch}{2}
    \begin{tabular}{|l|c|c|c|c|c|c|c|c|}
        \hline
        Some column  & \done & \done &  \done&  \done&  \done& \done &\done  &\\
        \hline
        This has arrows&  &  &  &  & & \tikzmark{f} & \tikzmark{g} & \tikzmark{h} \\
        \hline
        Communication of Papers
        & &  & &  & &  & &  \\ \hline   
    \end{tabular}
    \cellarrow{f} 
    \cellarrow{g} 
    \cellarrow{h} 

    \end{document}
3
  • 1
    Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, \end{document}, and definitions of custom macros. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem.
    – Skillmon
    Commented Jul 24, 2018 at 8:00
  • Sorry for the mistake happened and I didnt notice too. I have edited the question.
    – David
    Commented Jul 24, 2018 at 9:50
  • Tabulars use a strut of height \arraystretch\ht\strutbox and depth \arraystretch\dp\strutbox. Of course, if the contents are larger than the strut, it will use the height and depth of the contents. Commented Jul 24, 2018 at 19:42

2 Answers 2

2

Maybe in your case is more convenient to use a TikZ matrix.

I created a \cellarrow macro with two options: row and column of the cell where the arrow has to be drawn.

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{matrix}
\tikzset{
  mymatr/.style={
    matrix of nodes, 
    nodes in empty cells,
    nodes={draw, text centered, text width=width("\done")},
    row sep=-\pgflinewidth,
    column sep=-\pgflinewidth,
    }
  }

\usepackage{xcolor}

\def\done{done}

\newcommand\cellarrow[2]{
  \draw[-stealth, line width=2pt, color=brown] (matr-#1-#2.south east) -- (matr-#1-#2.north east);
  }

\begin{document}
\section{Table with Same width}
\begin{tikzpicture}
  \matrix[mymatr,
     column 1/.style={nodes={text width=width("Communication of Papers")}},
     nodes={text height=height("C"), text depth=depth("p")}
     ] (matr) {
     Some column & \done & \done & \done& \done& \done&\done \\
     This has arrows& & & & & & \\
     Communication of Papers & & & & & & \\};
  \foreach \cell in {2,3,4}
    {\cellarrow{2}{\cell}}
\end{tikzpicture}            

\section{Some other table}
\begin{tikzpicture}
  \matrix[mymatr,
     column 1/.style={nodes={text width=width("Communication of Papers")}},
     column 9/.style={nodes={text width=width("~~")}},
     nodes={text height=3.5ex, text depth=2ex}
     ] (matr) {
     Some column & \done & \done & \done& \done& \done& \done &\done &\\
     This has arrows& & & & & & & & \\
     Communication of Papers & & & & & & & & \\};
  \foreach \cell in {7,8,9}
    {\cellarrow{2}{\cell}}
\end{tikzpicture}            
\end{document}

enter image description here

2

Here is a solution with {NiceTabular} of nicematrix.

\documentclass{article}
\usepackage{nicematrix}
\usepackage{tikz}
\usepackage{xcolor}

\def\done{done}

\makeatletter
\ExplSyntaxOn

\cs_new_protected:Nn \__David_Arrow:nn
  {
    \tikz \draw [->,red,very~thick] 
             ( \int_eval:n { #1 + 1 } -| \int_eval:n { #2 + 1 } )
          -- ( #1 -| \int_eval:n { #2 + 1 } ) ; 
  }

\NewDocumentCommand \Arrow { }
  { 
    \tl_gput_right:Nx \g_nicematrix_code_after_tl
      { \__David_Arrow:nn { \arabic{iRow} } { \arabic{jCol} } }
  }

\ExplSyntaxOff
\makeatother

\begin{document}

\section{Table with Same width}
\begin{NiceTabular}{|l|c|c|c|c|c|c|}
    \hline
    Some column  & \done & \done &  \done&  \done& \done&\done \\
    \hline
    This has arrows& \Arrow & \Arrow & \Arrow & & &  \\
    \hline
    Communication of Papers & &  & &  & &    \\ \hline  
\end{NiceTabular}


\section{Some other table}
\renewcommand{\arraystretch}{2}
\begin{NiceTabular}{|l|c|c|c|c|c|c|c|c|}
    \hline
    Some column  & \done & \done &  \done&  \done&  \done& \done &\done  &\\
    \hline
    This has arrows&  &  &  &  & & \Arrow & \Arrow & \Arrow \\
    \hline
    Communication of Papers
    & &  & &  & &  & &  \\ \hline   
\end{NiceTabular}

\end{document}

You need several compilations because of the PGF/Tikz nodes.

Ouput of the above code

You must log in to answer this question.

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