是否可以使用 DTLforeach 中定义的命令作为 tikz 环境中的条件?

是否可以使用 DTLforeach 中定义的命令作为 tikz 环境中的条件?

我整个下午都在为这个问题而烦恼,希望有人能帮我。本质上,我遇到的问题是,我使用 DTLforeach 循环迭代 .csv 文件中的值并将它们放入表中。我希望在这个表中看到的一件事是一系列形状,它们会根据 .csv 文件中出现的文本改变颜色。

但是到目前为止,每次我尝试这样做时,它似乎只运行一次颜色测试,因此所有形状最终都是相同的颜色,而不是根据文本而不同的颜色。所以我的问题归结为我正在尝试做什么,如果可以的话,你会怎么做?

希望这些都与主题相关,如果这是重复的,我很抱歉,但我搜索过,找不到与我的问题类似的问题。如果这段代码很糟糕,我也很抱歉,我对 LaTeX 相当不熟悉,所以如果有一种非常简单的方法可以做到这一点,我愿意接受建议。

数据在 .csv 文件中看起来像这样,并由编译时添加的命令提供,以便可以从数据库动态生成 .csv 文件:

{"jobRefId","CISKeywords","problemLocation","jobProgress"
 "2","Broken, Other","Gate Green  NA Ticket Office","Issue Reported"
 "4","Blocked, Broken, Flooded","Village Purple Purple 4 Toilet (Disabled)","Issue Reported"
 "6","Shower, Blocked, Too Hot","Venue Children/Youth Stepping Stones Shower","Issue Reported"}

代码:

\documentclass{beamer}     
\usepackage{tikz}
\usepackage{xifthen}
\usepackage{longtable}
\usetikzlibrary{shapes}
\usepackage{xcolor}
\usepackage{tabu}

\definecolor{mellowyellow}{RGB}{255,255,199}
\definecolor{darkred}{RGB}{150,0,0}
\definecolor{darkyellow}{RGB}{255,178,0}
\definecolor{darkgreen}{RGB}{0,65,0}
\setbeamercolor{background canvas}{bg=mellowyellow}

\tikzset{

image/.cd,
1/.style = {ellipse, align=center, minimum height = 1.3cm, minimum width = 2.1cm, darkred, fill = darkred},
2/.style = {ellipse, align=center, minimum height = 1.3cm, minimum width = 2.1cm, darkyellow, fill = darkyellow},
3/.style = {ellipse, align=center, minimum height = 1.3cm, minimum width = 2.1cm, darkgreen, fill = darkgreen},
test/.code={
    \ifthenelse{\isin{#1}{Issue Reported}}{\tikzset{image/1}}{
    \ifthenelse{\isin{#1}{Ticket Printed Job In Progress Job Escalated}}{\tikzset{image/2}}{
    \ifthenelse{\isin{#1}{Job Complete}}{\tikzset{image/3}}{
    }}}
},
}

\newcommand{\jobindicator}[5]{
\node (#1) [xshift=#2cm,yshift=#3cm]  [image/test=#4] {\color{mellowyellow}{#5}};
}

\begin{frame}[allowframebreaks, noframenumbering]
\transduration{5}

 \frametitle{\huge{\\[-8pt] Ongoing Jobs Around Site}}
{\tabulinesep=1mm\begin{longtabu}to\linewidth{|X[c,m]|X[c,m]|X[c,m]|}
 \firsthline
 \bfseries{Where?} & \bfseries{What?} & \bfseries{\vspace{4mm} Job Ref \& Status} % 

 \DTLforeach{CIS}{%
 \ciskeywords=CISKeywords, \problemlocation=problemLocation, \jobrefid=jobRefId, \jobprogress=jobProgress}
   {%
  \\ \hline
  \problemlocation & \ciskeywords &  \expandafter{\begin{tikzpicture}\jobindicator{ell1}{0}{0}{\expandafter{\jobprogress}}{\jobrefid} \end{tikzpicture}}
  }
 \\ \lasthline
  \end{longtabu}}

 \end{frame}
 \end{document}

答案1

这是一个解决方案:

\documentclass{beamer}

\usepackage{tikz}
\usepackage{xifthen}
\usepackage{longtable}
\usetikzlibrary{shapes}
\usepackage{xcolor}
\usepackage{tabu}
\usepackage{datatool}

\begin{filecontents*}{test.csv}
"jobRefId","CISKeywords","problemLocation","jobProgress"
"2","Broken, Other","Gate Green  NA Ticket Office","Issue Reported"
"4","Blocked, Broken, Flooded","Village Purple Purple 4 Toilet (Disabled)","In Progress"
"6","Shower, Blocked, Too Hot","Venue Children/Youth Stepping Stones Shower","Job Complete"
\end{filecontents*}

\DTLloaddb{CIS}{test.csv}

\definecolor{mellowyellow}{RGB}{255,255,199}
\definecolor{darkred}{RGB}{150,0,0}
\definecolor{darkyellow}{RGB}{255,178,0}
\definecolor{darkgreen}{RGB}{0,65,0}
\setbeamercolor{background canvas}{bg=mellowyellow}

\tikzset{
image/.cd,
1/.style = {ellipse, align=center, minimum height = 1.3cm, minimum width = 2.1cm, darkred, fill = darkred},
2/.style = {ellipse, align=center, minimum height = 1.3cm, minimum width = 2.1cm, darkyellow, fill = darkyellow},
3/.style = {ellipse, align=center, minimum height = 1.3cm, minimum width = 2.1cm, darkgreen, fill = darkgreen},
test/.code={
    \ifthenelse{\expandafter\isin\expandafter{#1}{Issue Reported}}{\tikzset{image/1}}{
    \ifthenelse{\expandafter\isin\expandafter{#1}{Ticket Printed Job In Progress Job Escalated}}{\tikzset{image/2}}{
    \ifthenelse{\expandafter\isin\expandafter{#1}{Job Complete}}{\tikzset{image/3}}{
    }}}
},
}

\newcommand{\jobindicator}[5]{
\node (#1) [xshift=#2cm,yshift=#3cm]  [image/test=#4] {\color{mellowyellow}{#5}};
}

\begin{document}

\begin{frame}[allowframebreaks, noframenumbering]
\transduration{5}

 \frametitle{\huge{\\[-8pt] Ongoing Jobs Around Site}}

{\tabulinesep=1mm\begin{longtabu}to\linewidth{|X[c,m]|X[c,m]|X[c,m]|}
 \firsthline
 \bfseries{Where?} & \bfseries{What?} & \bfseries\vspace{4mm} Job Ref \& Status % 
 \DTLforeach{CIS}{%
 \ciskeywords=CISKeywords, \problemlocation=problemLocation, \jobrefid=jobRefId, \jobprogress=jobProgress}
   {%
     \\ \hline
     \problemlocation & \ciskeywords &  
    \begin{tikzpicture}
     \jobindicator{ell1}{0}{0}{\jobprogress}{\jobrefid}%
    \end{tikzpicture}
  }
  \\\lasthline
\end{longtabu}}

\end{frame}
 \end{document}

得出的结果为:

结果页面的图像

相关内容