0

I have the below table in my presentation and I need to create a function which takes a parameters for example

% developer: Boolean if true we will have colored circle in developer row (default true)
% devOps   : Boolean if true we will have colored circle in devOps row (default true)
% business : Boolean if true we will have colored circle in business row (default true)
% watchMethod: Int if 1 we will add all the circle under Computer column, if 2 Mobile/Tablet column else Just listening column (default listening if not passed as argument)
% length   : it is an indecator for colors if 1 red, 2 blue, else green (default green if not passed as an argument)
def makeTargetLectureClassificationTable(developer:Boolean, devOps:Boolean, business:Boolean, watchingMethod:Int, length:Int)={
}

Sample of the table code is below


%circle inside table
\newcommand*\redcircled{\tikz\draw[red,fill=red] (0,0) circle (.5ex);}
\newcommand*\bluecircled{\tikz\draw[blue,fill=blue] (0,0) circle (.5ex);}
\newcommand*\greencircled{\tikz\draw[green,fill=green] (0,0) circle (.5ex);}
\begin{table}[t]
    \centering  
    \begin{tabular}{|c |c | c | c|}
        \hline
        \thead{Watching Method \\ / Audience}  & \thead{Computer} & \thead{Mobile/Tablet} &  \thead{Just    listening} \\
        \hline
        \thead{Developer} &   &  \bluecircled & \\
        \hline
        \thead{DevOps}  &  & \bluecircled &  \\
        \hline
        \thead{Business} &  & \bluecircled & \\
        \hline
    \end{tabular}
\end{table}

The output screenshot below here.

1 Answers1

2

I am not entirely sure that I understand what you want but perhaps the code below will help. I have defined a macro \VideoClassification that creates your video classification table. This macro accepts key-value pairs for the different settings. I have used a slightly different syntax for develop etc as this was more straightforward to implementand I have used names that made more sense to me:

  • By default markers are put into the three rows and you can "turn off" the marker using nodev, nodevops and nobus, respectively. By default all rows have markers
  • The column that markers appear in is specified with column=n, where n is 1, 2 or 3 (default 3)
  • The colour of the marker is given by colour=<col> where col can be any valid colour (not just green, blue and red). By default, the markers are green.

These comma separated keys can be given in any order.

Using this syntax the commands:

  \VideoClassification
  \VideoClassification[nodev, column=2]
  \VideoClassification[column=1, colour=red]

produce (with annoying amounts of extra space because of the table environment):

enter image description here

The basic idea is to use pgfkeys to parse the arguments to the \VideoClassification. The keys set the colour and the column and then the markers are printed using the pgfkey mark that takes two arguments, which specify the column and row, respectively. There are more explanatory comments in the code below. I am sure that there are more efficient ways of doing this!

Here is the full code:

\documentclass{article}
\usepackage{pgfkeys}
\usepackage{makecell}
\usepackage{tikz}

\pgfkeys{/Videos/.is family, /Videos,
  bus/.initial=1,% by default the business row has a marker
  dev/.initial=1,% by default the developer row has a marker
  devops/.initial=1,% by default the developerOps row has a marker
  colour/.initial=green,% the colour of the marker
  column/.initial=3,% the column of the marker
  mark/.code 2 args={% place a marker ONLY if #1=column and \VIDEO{#2}=1
    \ifnum#1=\VIDEO{column}%
      \ifnum1=\VIDEO{#2}%
        \tikz\draw[\VIDEO{colour},fill=\VIDEO{colour}] (0,0) circle (.5ex);%
      \fi%
    \fi%
  },
  nobus/.style={bus=0},% turn off marker for business
  nodev/.style={dev=0},% turn off marker for developer
  nodevops/.style={devops=0},% turn off marker for devoperOps
}
% shortcut to access key values
\newcommand\VIDEO[1]{\pgfkeysvalueof{/Videos/#1}}

% Usage: \VideoClassification[optional key values]
\newcommand\VideoClassification[1][]{%
  \begin{table}[t]
    \pgfkeys{/Videos, #1}% key changes local to group (and macro)
    \centering
    \begin{tabular}{|c|c|c|c|}
        \hline
        \thead{Watching Method \\ / Audience}  & \thead{Computer} & \thead{Mobile/Tablet} &  \thead{Just listening} \\
        \hline
        \thead{Developer}& \pgfkeys{/Videos/mark={1}{dev}}   & \pgfkeys{/Videos/mark={2}{dev}}   & \pgfkeys{/Videos/mark={3}{dev}} \\
        \hline
        \thead{DevOps}   & \pgfkeys{/Videos/mark={1}{devops}}& \pgfkeys{/Videos/mark={2}{devops}}& \pgfkeys{/Videos/mark={3}{devops}} \\
        \hline
        \thead{Business} & \pgfkeys{/Videos/mark={1}{bus}}   & \pgfkeys{/Videos/mark={2}{bus}}   & \pgfkeys{/Videos/mark={3}{bus}} \\
        \hline
    \end{tabular}
  \end{table}
}

\begin{document}

  \VideoClassification

  \VideoClassification[nodev, column=2]

  \VideoClassification[column=1, colour=red]

\end{document}