我想使用非常有用的工具从 csv 文件生成一个表格datatool
,并插入每个人的圆形照片,照片周围有一个圆圈,照片的颜色也应该从提供的 csv 文件中获取,请参阅下面的 MWE:
平均能量损失
\documentclass[fontsize=11pt,paper=a4,DIV=6,landscape]{scrartcl}
\usepackage{tikz}
\usepackage{graphicx}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{datatool}
\newcolumntype{s}{>{\hsize=.05\hsize\centering\arraybackslash}X} %for id
\newcolumntype{n}{>{\hsize=.1\hsize\raggedright\arraybackslash}X} %for name
\newcolumntype{y}{>{\hsize=.2\hsize\centering\arraybackslash}X} %for everthing else
\newcolumntype{e}{>{\hsize=.3\hsize\raggedright\arraybackslash}X} %for email
\DTLloaddb[noheader]{data}{namelist.csv}
\newcommand{\circleme}[1]{\begin{tikzpicture}
\begin{scope}
\clip [rounded corners=.4cm] (0,0) rectangle coordinate (centerpoint) (.8,.8cm);
\node [inner sep=0pt] at (centerpoint) {\includegraphics[width=.8cm, height=.8cm]{#1}};
\end{scope}
\draw[\mycolor,very thick] (.4cm,.4cm) circle (.4cm);
\end{tikzpicture}}
\begin{filecontents*}{namelist.csv}
1,Name One,PhD,supervisor,Immunology,[email protected],logo,red
2,Name Two,MSc,worker,Microbiology,[email protected],logo,blue
3,Name Three,BSc,worker,Chemistry,[email protected],logo,green
\end{filecontents*}
\newcommand{\tabcontents}{\begin{tabularx}{\textwidth}{@{}snyyyey@{}}
\toprule
& \multicolumn{1}{c}{\textbf{Name}}
& \multicolumn{1}{c}{\textbf{Qual}}
& \multicolumn{1}{c}{\textbf{Specs}}
& \multicolumn{1}{c}{\textbf{Descr}}
& \multicolumn{1}{c}{\textbf{E-mail}}
&}
\begin{document}
\thispagestyle{empty}
\DTLforeach*{data}{\idcode=Column1,\name=Column2,\qual=Column3,%
\descr=Column4,\spec=Column5,\email=Column6,\figpath=Column7,\mycolor=Column8}%
{%
\eappto\tabcontents{\noexpand\\\noexpand\midrule
\idcode \noexpand&
\name \noexpand&
\qual \noexpand&
\spec \noexpand&
\descr \noexpand&
\email \noexpand&
\noexpand\raisebox{-.5\baselineskip}{\noexpand\circleme{\figpath}}}
}%
\appto\tabcontents{\\\bottomrule\end{tabularx}}
\tabcontents%
\end{document}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% TeX-engine: xetex
%%% End:
所需的输出是第一个圆圈为红色,第二个圆圈为蓝色,第三个圆圈为绿色,如 csv 文件所规定的那样。如何让 tikz 宏按照上述示例接受此参数?
答案1
只需添加另一个参数\circleme
并传递\mycolor
给它:
\documentclass[fontsize=11pt,paper=a4,DIV=6,landscape]{scrartcl}
\usepackage{tikz}
\usepackage{graphicx}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{filecontents}
\newcolumntype{s}{>{\hsize=.05\hsize\centering\arraybackslash}X} %for id
\newcolumntype{n}{>{\hsize=.1\hsize\raggedright\arraybackslash}X} %for name
\newcolumntype{y}{>{\hsize=.2\hsize\centering\arraybackslash}X} %for everthing else
\newcolumntype{e}{>{\hsize=.3\hsize\raggedright\arraybackslash}X} %for email
\usepackage{datatool}
\DTLloaddb[noheader]{data}{namelist.csv}
\newcommand{\circleme}[2]{\begin{tikzpicture}
\begin{scope}
\clip [rounded corners=.4cm] (0,0) rectangle coordinate (centerpoint) (.8,.8cm);
\node [inner sep=0pt] at (centerpoint) {\includegraphics[width=.8cm, height=.8cm]{#1}};
\end{scope}
\draw[#2,very thick] (.4cm,.4cm) circle (.4cm);
\end{tikzpicture}}
\begin{filecontents*}{namelist.csv}
1,Name One,PhD,supervisor,Immunology,[email protected],example-image-a,red
2,Name Two,MSc,worker,Microbiology,[email protected],example-image-b,blue
3,Name Three,BSc,worker,Chemistry,[email protected],example-image-c,green
\end{filecontents*}
\newcommand{\tabcontents}{\begin{tabularx}{\textwidth}{@{}snyyyey@{}}
\toprule
& \multicolumn{1}{c}{\textbf{Name}}
& \multicolumn{1}{c}{\textbf{Qual}}
& \multicolumn{1}{c}{\textbf{Specs}}
& \multicolumn{1}{c}{\textbf{Descr}}
& \multicolumn{1}{c}{\textbf{E-mail}}
&}
\begin{document}
\thispagestyle{empty}
\DTLforeach*{data}{\idcode=Column1,\name=Column2,\qual=Column3,%
\descr=Column4,\spec=Column5,\email=Column6,\figpath=Column7,\mycolor=Column8}%
{%
\eappto\tabcontents{\noexpand\\\noexpand\midrule
\idcode \noexpand&
\name \noexpand&
\qual \noexpand&
\spec \noexpand&
\descr \noexpand&
\email \noexpand&
\noexpand\raisebox{-.5\baselineskip}{\noexpand\circleme{\figpath}{\mycolor}}}
}%
\appto\tabcontents{\\\bottomrule\end{tabularx}}
\tabcontents%
\end{document}