How can I create Table in TeX and get information from txt file
Can be solved with some TeX magic:
\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{data.txt}
\r Julo:Petrzlen:011:100:101:
\r Ivan:Hrasok:110:101:010:
\end{filecontents*}
\usepackage{array}
\def\Conv#1#2#3!!{%
\ifnum#1=0 -\else x\fi \ifnum#2=0 -\else x\fi \ifnum#3=0 -\else x\fi}
\def\r#1:#2:#3:#4:#5:{#1 & #2 & \Conv#3!! & \Conv#4!! & \Conv#5!! \\}
% !! marks the end of input
\begin{document}
\begin{tabular}{@{} ll *3{>{\ttfamily}l} @{}}\hline
\emph{Firstname} & \emph{Lastname} & \ldots & \ldots & \ldots\\\hline
\input{data.txt}
\hline
\end{tabular}
\end{document}
And the same for a short firstname:
\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{data.txt}
\r Julo:Petrzlen:011:100:101:
\r Ivan:Hrasok:110:101:010:
\end{filecontents*}
\usepackage{array}
\def\Short#1#2!!{#1. }
\def\Conv#1#2#3!!{%
\ifnum#1=0 -\else x\fi \ifnum#2=0 -\else x\fi \ifnum#3=0 -\else x\fi}
\def\r#1:#2:#3:#4:#5:{\Short#1!! #2 & \Conv#3!! & \Conv#4!! & \Conv#5!! \\}
\begin{document}
\begin{tabular}{@{} l *3{>{\ttfamily}l} @{}}\hline
\emph{name} & \ldots & \ldots & \ldots\\\hline
\input{data.txt}
\hline
\end{tabular}
\end{document}
And, last but not least, all courses in an own column (\Conv
now writes 3 columns.)!
\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{data.txt}
\r Julo:Petrzlen:011:100:101:
\r Ivan:Hrasok:110:101:010:
\end{filecontents*}
\usepackage{array}
\def\Short#1#2!!{#1. }
\def\Conv#1#2#3!!{%
\ifnum#1=0 -\else x\fi & \ifnum#2=0 -\else x\fi & \ifnum#3=0 -\else x\fi}
\def\r#1:#2:#3:#4:#5:{\Short#1!! #2 & \Conv#3!! & \Conv#4!! & \Conv#5!! \\}
\begin{document}
\begin{tabular}{@{} l *9{>{\ttfamily}l} @{}}\hline
\emph{name} & \multicolumn{9}{c}{\ldots}\\\hline
\input{data.txt}
\hline
\end{tabular}
\end{document}
For reference, here is one version using pgfplotstable
:
\documentclass{article}
\usepackage{pgfplotstable}
\begin{document}
\pgfplotstabletypeset[col sep=colon,columns={First,Last,Mon,Tue,Wed},
string type,string replace*={0}{\(- \)},string replace*={1}{\(+ \)}]{students.txt}
\end{document}
with students.txt
:
First:Last:Mon:Tue:Wed:
Julo:Petrzlen:011:100:101:
Ivan:Hrasok:110:101:010:
If the first two columns could contain zeros and ones, then you would have to limit the substitutions. The following makes specifications for each column separately, and shows how to left align the first columns:
\documentclass{article}
\usepackage{pgfplotstable}
\begin{document}
\pgfplotstabletypeset[col sep=colon,columns={First,Last,Mon,Tue,Wed},
string type,
columns/First/.style={column type=l},
columns/Last/.style={column type=l},
columns/Mon/.style={string replace*={0}{\(- \)},string replace*={1}{\(+ \)}},
columns/Tue/.style={string replace*={0}{\(- \)},string replace*={1}{\(+ \)}},
columns/Wed/.style={string replace*={0}{\(- \)},string replace*={1}{\(+ \)}}%
]{students.txt}
\end{document}