8

Is it possible to create a table like the one shown in the figure below with LaTeX?

I don't care much about the colors as I care about the arrows and the fact that the arrows are crossing cells. The table looks empty, but I would eventually also put some text inside the arrows and in the task column. I know how to create a table, but from that point forward I'm lost. It seems that this could be accomplished using the tikz package as I found in this post.

Enter image description here

This is what I have so far:

\documentclass{article}

\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage{subfig}
\usepackage{booktabs}
\usepackage{tikz}
\usetikzlibrary{calc,shadings,patterns,tikzmark}

% increase table row spacing
\renewcommand{\arraystretch}{1.2}

% command for colored cells
\newcommand{\scell}[1]{\cellcolor{black!25} \it #1 }

% hatched table
\newcommand\HatchedCell[4][0pt]{%
  \begin{tikzpicture}[overlay,remember picture]%
    \fill[#4] ( $ (pic cs:#2) + (0,1.9ex) $ ) rectangle ( $ (pic cs:#3) + (0pt,-#1*\baselineskip-.8ex) $ );
  \end{tikzpicture}%
}%!TEX encoding = UTF-8 Unicode
\newcommand*{\hatch}[2]{\multicolumn{#2}{!{\hspace*{-0.4pt}\tikzmark{start#1}}c!{\tikzmark{end#1}}}{}}

% roman numbers
\makeatletter
\newcommand*{\rom}[1]{\expandafter\@slowromancap\romannumeral #1@}
\makeatother


\begin{document}

\begin{table}[htb]
  \centering
  \rowcolors{2}{gray!10}{white}
\begin{tabular}{lrrrrrrrrrr}
\toprule
    Activity & \multicolumn{10}{c}{semester} \\
     & \scriptsize{1} & \scriptsize{2} & \scriptsize{3} & \scriptsize{4} & \scriptsize{5} & \scriptsize{6} & \scriptsize{7} & \scriptsize{8} & \scriptsize{9} & \scriptsize{10} \\
    \toprule
   \multicolumn{11}{l}{\scell{Theme 1}}  \\
   Task 1  & & \hatch{1}{1}  & \\
   Task 2  & & \hatch{2}{2} & & & & & & & \\
   Task 3  & & \hatch{4}{6} \\
   \multicolumn{11}{l}{\scell{Theme 2}}  \\
   Task 1  & & \hatch{2}{2} & & & & & & & \\
   \multicolumn{11}{l}{\scell{Theme 3}}  \\
   Task 1  & & \hatch{2}{2} & & & & & & & \\
    \bottomrule
    \rowcolor{white}
\end{tabular}
\captionof{table}{Table with rows.}
\label{tab:work_plan}

% loop over odd rows
\foreach \x/\y  in {1/1,3/3,5/5}{
  \HatchedCell{start\x}{end\y}{%
     pattern color=black!70,pattern=north east lines}
}
\foreach \x/\y  in {2/2,4/4,6/6}{
  \HatchedCell{start\x}{end\y}{%
    pattern color=black!70,pattern=north west lines}
}
\end{table}[![enter image description here][3]][3]

\end{document}

which creates this table:

Enter image description here

UPDATE

So after taking a look at this post, I tried my best to come up with something and this is what I got so far: enter image description here

For which the code is:

\documentclass{article}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor} % use color


\usepackage{tikz}
\usetikzlibrary{matrix, shapes.symbols,calc,shadings,patterns,tikzmark,decorations.pathmorphing,fit,backgrounds}

\begin{document}

% styles
\tikzstyle{none}=[]
\tikzstyle{myarrow}=[signal, minimum height=0.7cm, fill=LightGray, signal to]
\tikzstyle{background}=[rectangle,
                                                fill=gray!10,
                                                inner sep=0.2cm,
                                                rounded corners=5mm]

\tikzstyle{darkBackground}=[rectangle,
                                                fill=gray!50,
                                                inner sep=0.2cm]



\begin{tikzpicture}[>=latex,text height=1.5ex,text depth=0.25ex, minimum width=1.5cm, inner sep=0pt, outer sep=0pt, ]
    % "text height" and "text depth" are required to vertically
    % align the labels with and without indices.

  % The various elements are conveniently placed using a matrix:
  \matrix[row sep=0.5cm,column sep=0.5cm] {
    % First line: Control input
        \node (1) {1}; & \node (2) {2}; & \node (3) {3}; & \node (4) {4}; & \node (5) {5}; & \node (Task) {Task}; \\
        % Second line
         \node (Theme-1) [] {}; & & & &  \node (End-Theme-1) [] {}; \\
        % Third line
        \node (A-1-1) [] {}; & & & &  & \node (Task1) [] {First task of theme 1}; \\
        % Fourth line
        \node (A-2-1) [] {}; & & & &  & \node (Task2) [] {Second task of theme 1}; \\
        % Fifth line
         \node (Theme-2) [] {}; & & & &  \node (End-Theme-2) [] {}; \\
        % Sixth line
         & \node (A-3-2) [] {}; & & &  & \node (Task3) [] {First task of theme 2}; \\
        % Seventh line
         & \node (A-4-2) [] {}; & & &  & \node (Task4) [] {Second task of theme 2}; \\
        % Eighth line
         \node (Theme-3) [] {}; & & & &  \node (End-Theme-3) [] {}; \\
        % Ninth line
        &  \node (A-5-2) [] {}; & & &  \node (A-5-5) [] {}; & \node (Task5) [] {First task of theme 3}; \\


        % Fifth line: Measurement
         \node (Milestones) [] {}; &
        \node (z_k-1) [] {1}; &
        &
        \node (z_k)   [] {2};     &
        \\
    };

    % draw arrows
    \node[myarrow, minimum width=3cm, anchor=west] at (A-1-1.west) {};
    \node[myarrow, minimum width=1.5cm, anchor=west] at (A-2-1.west) {};
    \node[myarrow, minimum width=3cm, anchor=west] at (A-3-2.west) {};
    \node[myarrow, minimum width=1.5cm, anchor=west] at (A-4-2.west) {};
    \node[myarrow, minimum width=4cm, anchor=west] at (A-5-2.west) {};


    % Now that the diagram has been drawn, background rectangles
    % can be fitted to its elements. This requires the TikZ
    % libraries "fit" and "background".
    % Control input and measurement are labeled. These labels have
    % not been translated to English as "Measurement" instead of
    % "Messung" would not look good due to it being too long a word.
    \begin{pgfonlayer}{background}
        \node [none,
                    fit=(1) (5),
                    label=left:Year:] {};
        \node [none,
                    fit=(Milestones),
                    label=left:Milestones:] {};
        \node [background,
                    fit=(1) (A-5-5)] {};
        \node [darkBackground,
                    fit=(Theme-1) (End-Theme-1), label=center:Theme 1] {};
        \node [darkBackground,
                    fit=(Theme-2) (End-Theme-2), label=center:Theme 2] {};
        \node [darkBackground,
                    fit=(Theme-3) (End-Theme-3), label=center:Theme 3] {};
    \end{pgfonlayer}
\end{tikzpicture}

\end{document}  

Now there are many things I would like to improve and I need your help finishing it. First, the Task column should be left-justified. Is there a way to set the arrow length for the year duration in a better way? Any suggestions that could improve the appearance of the table is very welcome.

  • So please post the code you've got for the table and somebody can then help you with the arrows. – cfr Sep 29 '15 at 21:30
  • @cfr I modified my question. – aaragon Sep 29 '15 at 21:45
  • @arragom, and which image you like to obtain. The first one (in color) or what you generated with your code? Do you like in it replace hatched nodes with arrows? – Zarko Sep 29 '15 at 21:58
  • I would like to replace the hatched code by arrows, in the same way I posted the color picture. – aaragon Sep 29 '15 at 22:02
  • @aaragon, you complete change your answer and with this made received answers obsolete! My opinion: it would be better to ask new question, but before that rethinking about design of your time table (from your comments I concluded different design intention) and than clearly ask, what is your problem. – Zarko Sep 30 '15 at 16:02
6

With standard tabular and use of tikz for signal shapes you can design following table:

enter image description here

Code is derived from your MWE:

\documentclass[border=3mm]{standalone}

\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage{subfig}
\usepackage{array,booktabs}

\usepackage{tikz}
\usetikzlibrary{shapes}

\tikzset{event/.style = {baseline=-3pt,
E/.style args = {##1/##2}{shape=signal, draw, 
    minimum width=##1, minimum height=4mm,
    fill=##2,
    signal to=no where, signal to=east, 
    inner sep=1mm, node contents={}},
        }}

\newcommand{\mc}[2]{\multicolumn{#1}{@{}l@{}|}{#2}}
\newcommand{\scell}[1]{\multicolumn{10}{c|}{\cellcolor{black!25}%
                                           \itshape Theme #1}}
\newcolumntype{P}[1]{@{}>{\centering\arraybackslash}p{#1}@{}}

    \begin{document}
    \renewcommand{\arraystretch}{1.2}
\begin{tabular}{l|*{10}{P{11mm}|}}
    \cline{2-11}
    &   \multicolumn{10}{c|}{semester}                       \\
    \cline{2-11}
    &   \scriptsize{1} 
        &   \scriptsize{2} 
            &   \scriptsize{3} 
                &   \scriptsize{4} 
                    &   \scriptsize{5} 
    &   \scriptsize{6} 
        &   \scriptsize{7} 
            & \scriptsize{8}    
                &   \scriptsize{9} 
                    &   \scriptsize{10}                     \\
        &   \scell{1}\\ 
Task 1  &   \mc{1}{\tikz[event]\node[E=11mm/yellow!10];}
                &&&&&&&&&                                   \\
Task 2  &   &   \mc{2}{\tikz[event]\node[E=22mm/orange!10];}
                &&&&&&&                                     \\
        &   \scell{2}\\ 
Task 1  &&&   \mc{5}{\tikz[event]\node[E=55mm/green!10];}
                &&&                                         \\
Task 2  &&    \mc{5}{\tikz[event]\node[E=55mm/blue!10];}
                &&&&                                        \\
Task 3  &&&&  \mc{7}{\tikz[event]\node[E=77mm/purple!10];}  \\
    \cline{2-11}
\end{tabular}
%    \captionof{table}{Table with rows.}
%    \label{tab:work_plan}
\end{document}

Edit: In case, that more tasks has common shape signal, than it should be placed in multirow. For example:

Task 1  && && && && && \\
Task 2  &&   \mc{5}{\multirow{-2}*{
                    \tikz[event]\node[E=55mm/green!10,minimum height=7mm];}
                                 }
                &&&&                                            \\

Since "signal" now is used for two task, I make it taller.

The idea, that instead explicit determination of "signals" length be used hsize doesn't works correctly, so I erase it now.

  • Could I make the arrows overlap many tasks as in the figure I showed originally? – aaragon Sep 30 '15 at 6:29
  • Common for 2 or more task? With the same heights? Yes, this is possible with use of multirow package. See upgrade of my answer. – Zarko Sep 30 '15 at 9:09
5

One approach is to use the pgfgantt package. This is based on TikZ, so you can customize the appearance of things accordingly. Here is an example that might help get you started.

\documentclass[11pt]{article}
\usepackage{tikz}
\usetikzlibrary{shapes}
\usepackage{pgfgantt}
\begin{document}
\begin{ganttchart}[bar/.append style={shape=signal,fill=blue!20},x unit=7mm]{1}{10}
\gantttitle[title/.style={draw=none},title left shift=-1mm]{Activity}{-0}
\gantttitle{semester}{10}\\
\gantttitlelist{1,...,10}{1} \\
\ganttgroup{Theme 1}{1}{10} \\
\ganttbar[inline]{Task 1}{1}{2} \\
\ganttbar{Task 2}{1}{1} \\
\ganttbar{Task 3}{1}{7} \\
\ganttgroup{Theme 2}{1}{10} \\
\ganttbar{Task 1}{1}{1} \\
\ganttgroup{Theme 3}{1}{10} \\
\ganttbar{Task 1}{1}{4}
\end{ganttchart}
\end{document}

enter image description here

4

Here's another approach using the pgfgantt package (the other answer also suggests this package, but I had already written this example as an answer and has a different approach and shows new elements so I decided to add this answer). I defined a new element arrbar which has the desired arrow-like shape and also show how to produce the filled rectangles for the "themes":

\documentclass{article}
\usepackage{pgfgantt}
\usetikzlibrary{shapes.misc}

\newganttchartelement{arrbar}{
arrbar/.style={
  shape={chamfered rectangle},
  chamfered rectangle corners={north east,south east},
  draw=cyan!70!black,
  very thick,
  top color=white,
  bottom color=cyan!50,
  },
arrbar incomplete/.style={
  /pgfgantt/foobar,
  draw=orange,
  bottom color=orange!50
},
  arrbar label font=\slshape,
  arrbar left shift=0,
  arrbar right shift=0,
}


\begin{document}

\begin{ganttchart}[
  hgrid=true,
  vgrid={dotted,dotted},
  bar/.append style={fill=gray!30,text height=20pt}
]{1}{10}
\gantttitle{Semester}{10} \\
\gantttitlelist{1,...,10}{1} \\
\ganttbar[name=theme1]{}{1}{10}\\
\node at (theme1.center) {Theme 1};
\ganttarrbar{Task 1}{1}{3} \\
\ganttarrbar{Task 2}{2}{5} \\
\ganttbar[name=theme2]{}{1}{10}\\
\node at (theme2.center) {Theme 2};
\ganttarrbar[name=task3]{Task 3}{1}{7} \\
\node at (task3.center) {Test text};
\ganttarrbar{Task 4}{3}{5} \\
\ganttarrbar{Task 5}{4}{10}
\end{ganttchart}

\end{document} 

enter image description here

  • I like the simplicity in this approach but would it be possible to make the arrows overlap many tasks as in the figure I showed originally? – aaragon Sep 30 '15 at 6:34
  • @aaragon I'm afraid I don't understand. Could you please describe in more detail what do you mean with "make the arrows overlap many tasks"? – Gonzalo Medina Sep 30 '15 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.