Bold one cell in table using CSV reader
Not a direct answer but I would recommend the pgfplotstable
for such tasks. It's quite comprehensive and file operations are quite convenient. It might seem like an overkill for this specific question but as the tasks get more complicated it reveals its true potential.
\documentclass{article}
\usepackage{pgfplotstable,filecontents,booktabs}
% Make csv in question
\begin{filecontents*}{scientists2.csv}
name,surname
Albert,Einstein
Marie,Curie
Thomas,Edison
\end{filecontents*}
\pgfplotstableread[col sep=comma]{scientists2.csv}\mytable
\begin{document}
\begin{center}
\pgfplotstabletypeset[
string type,
columns/name/.style={column name=Name},
columns/surname/.style={column name=Surname},
% Row/column numbering starts from zero
every row 1 column 1/.style={postproc cell content/.style={@cell content=\textbf{##1}}},
every head row/.style={before row={\toprule},after row=\midrule},
every last row/.style={after row={\toprule}},
]\mytable
\end{center}
\end{document}
You can also so this with the datatool
package:
Notes:
- I used the
xstring
package for\IfStrEq
.
Code:
\documentclass{article}
\usepackage{datatool}
\usepackage{booktabs}
\usepackage{xstring}
\usepackage{xcolor}
% Make csv in question
%\usepackage{filecontents}
\begin{filecontents*}{scientists2.csv}
name,surname,
Albert,Einstein,
Marie,Curie,
Thomas,Edison,
\end{filecontents*}
\newcommand*{\FormatCell}[1]{%
\IfStrEq{#1}{Curie}{\textcolor{red}{#1}}{#1}%
}%
\begin{document}
\DTLloaddb[keys={Name,Surname}]{myDB}{scientists2.csv}
\bigskip
\begin{tabular}{l l}\toprule
\textbf{First Name} & \textbf{Last Name}\\\cmidrule{1-2}
\DTLforeach*{myDB}{\Name=Name,\Surname=Surname}{%
\Name & \FormatCell{\Surname} \\
}%
\end{tabular}
\end{document}
csvsimple version 1.06 released 2012-11-08 does exactly what you want. The code below is your original MWE, the only modification being \textbf{Curie}
instead of Curie
within the filecontents environment.
\documentclass{article}
\usepackage{csvsimple} % requires csvsimple version 1.06 released 2012-11-08
% Make csv in question
\begin{filecontents*}{scientists2.csv}
name,surname
Albert,Einstein
Marie,\textbf{Curie}
Thomas,Edison
\end{filecontents*}
\begin{document}
\begin{center}
\csvreader[tabular=|l|l|,
table head=\hline \textbf{ First Name} & \textbf{Last Nmae} \\\hline,
late after line = \\\hline]%
{scientists2.csv}{name=\name,surname=\surname}%
{\name & \surname}%
\end{center}
\end{document}
It is also worth checking out the new "Macro code inside the data" section in the documentation (p.21). The code below has been taken directly from this section.
\documentclass{scrreprt}
\usepackage{tikz,csvsimple,filecontents}
\begin{document}
%-- file embedded for simplicity --
\begin{filecontents*}{macrodata.csv}
type,description,content
M,A nice \textbf{formula}, $\displaystyle \int\frac{1}{x} = \ln|x|+c$
G,A \textcolor{red}{colored} ball, {\tikz \shadedraw [shading=ball] (0,0) circle (.5cm);}
M,\textbf{Another} formula, $\displaystyle \lim\limits_{n\to\infty} \frac{1}{n}=0$
\end{filecontents*}
%-- end embedded file --
\csvautotabular{macrodata.csv}
\csvstyle{my enumerate}{head to column names}
\begin{enumerate}
\csvreader[my enumerate]{macrodata.csv}{}{\item \description:\par\content}
\end{enumerate}
Now, formulas only:
\begin{enumerate}
\csvreader[my enumerate,filter equal={\type}{M}]{macrodata.csv}{}{%
\item \description:\qquad\content}
\end{enumerate}
\end{document}
"Mega cool", as my kids would say :-).