我必須建立桌面單(標籤)。此數據可在 Excel 表格中找到。列名稱為 - RollNo、Subject、Venue of Exam(考試中心)。
目前我們正在使用建立桌面單據CSVtools
。標籤看起來像——
NAME OF EXAMINATION
Subject : xyz
Roll No. : 000000
為此,我們必須建立幾個 csv 資料表 - 考試地點和主題。有沒有一種方法可以在不建立多個 csv 資料表的情況下,根據考試地點和主題建立標籤?
微量元素:
\documentclass[a4paper,12pt]{article}
\usepackage{csvtools}
\usepackage[left=.5cm,right=.5cm,top=.5cm,bottom=.5cm]{geometry}
\usepackage{multicol}
\usepackage{xcolor}
\usepackage{filecontents}
\begin{filecontents*}{data.csv}
RollNo,Subject,Venue
022701,Sociology,Deptt. of Physics
022702,Sociology,Deptt. of Physics
022704,Sociology,Deptt. of Physics
022705,Sociology,Deptt. of Physics
022706,Sociology,Deptt. of Physics
022707,Sociology,Deptt. of Physics
022708,Sociology,Deptt. of Physics
022709,Sociology,Deptt. of Physics
022709,Sociology,Deptt. of Physics
022710,Sociology,Deptt. of Physics
023001,Psychology,Deptt. of Physics
023002,Psychology,Deptt. of Physics
023004,Psychology,Deptt. of Physics
023005,Psychology,Deptt. of Physics
023006,Psychology,Deptt. of Physics
023007,Psychology,Deptt. of Physics
023008,Psychology,Deptt. of Physics
023009,Psychology,Deptt. of Physics
023010,Psychology,Deptt. of Physics
\end{filecontents*}
\begin{document}
\applyCSVfile{data.csv}{% here put the name of the file
%\begin{multicols}{2}
\noindent\fbox{\parbox{6.3cm}{%
{\color{white}.}\\[7pt]
\centering{\LARGE UGC NET - 2014}\\[2pt]
\raggedright
{\Large Subject : \insertSubject}\\[5pt]
{\Large Roll No. : \textbf{0\insertRollNo}}\\[12pt]
}} % This is for parbox
%\end{multicols}
}% This is for CSV file
\end{document}
答案1
這是一些應該作為起點的程式碼。這個使用datatool
包。center
除了您的列之外,我還添加了一個帶有快捷鍵的列。
center,RollNo,Subject,Venue
Bangalore,022701,Sociology,Deptt. of Physics
Bangalore,022702,Sociology,Deptt. of Physics
Bangalore,022704,Sociology,Deptt. of Physics
Bangalore,022705,Sociology,Deptt. of Physics
在第四列中,如果需要,您可以指定完整的中心。
\documentclass[a4paper,12pt]{article}
\usepackage[left=.5cm,right=.5cm,top=.5cm,bottom=.5cm]{geometry}
\usepackage{xcolor}
\usepackage{filecontents}
\begin{filecontents*}{data.csv}
center,RollNo,Subject,Venue
Bangalore,022701,Sociology,Deptt. of Physics
Bangalore,022702,Sociology,Deptt. of Physics
Bangalore,022704,Sociology,Deptt. of Physics
Bangalore,022705,Sociology,Deptt. of Physics
Bangalore,022706,Sociology,Deptt. of Physics
Bangalore,022707,Sociology,Deptt. of Physics
Bangalore,022708,Sociology,Deptt. of Physics
Bangalore,022709,Sociology,Deptt. of Physics
Bangalore,022709,Sociology,Deptt. of Physics
Bangalore,022710,Sociology,Deptt. of Physics
Mangalore,023001,Psychology,Deptt. of Physics
Mangalore,023002,Psychology,Deptt. of Physics
Mangalore,023004,Psychology,Deptt. of Physics
Mangalore,023005,Psychology,Deptt. of Physics
Mangalore,023006,Psychology,Deptt. of Physics
Mangalore,023007,Psychology,Deptt. of Physics
Mangalore,023008,Psychology,Deptt. of Physics
Mangalore,023009,Psychology,Deptt. of Physics
Mangalore,023010,Psychology,Deptt. of Physics
\end{filecontents*}
\usepackage{datatool}
\DTLloaddb{data}{data.csv}
\begin{document}
This is for Bangalore center
\DTLforeach*[\DTLisopenbetween{\center}{B}{C}]{data}{%
\center=center,\roll=RollNo,\sub=Subject, \venue=Venue}{%
\noindent\fbox{\parbox{6.3cm}{%
{\color{white}.}\\[7pt]
\centering{\LARGE UGC NET - 2014}\\[2pt]
\raggedright
{\Large Subject : \sub}\\[5pt]
{\Large Roll No. : \textbf{\roll}}\\[12pt]
}}\hfill % This is for parbox
}%
\clearpage
This is for Mangalore
\DTLforeach*[\DTLisopenbetween{\center}{M}{N}]{data}{%
\center=center,\roll=RollNo,\sub=Subject, \venue=Venue}{%
\noindent\fbox{\parbox{6.3cm}{%
{\color{white}.}\\[7pt]
\centering{\LARGE UGC NET - 2014}\\[2pt]
\raggedright
{\Large Subject : \sub}\\[5pt]
{\Large Roll No. : \textbf{\roll}}\\[12pt]
}}\hfill % This is for parbox
}%
\clearpage
This is for Sociology
\DTLforeach*[\DTLisopenbetween{\sub}{S}{T}]{data}{%
\center=center,\roll=RollNo,\sub=Subject, \venue=Venue}{%
\noindent\fbox{\parbox{6.3cm}{%
{\color{white}.}\\[7pt]
\centering{\LARGE UGC NET - 2014}\\[2pt]
\raggedright
{\Large Subject : \sub}\\[5pt]
{\Large Roll No. : \textbf{\roll}}\\[12pt]
}}\hfill % This is for parbox
}%
\clearpage
This is for Psychology
\DTLforeach*[\DTLisopenbetween{\sub}{P}{Q}]{data}{%
\center=center,\roll=RollNo,\sub=Subject, \venue=Venue}{%
\noindent\fbox{\parbox{6.3cm}{%
{\color{white}.}\\[7pt]
\centering{\LARGE UGC NET - 2014}\\[2pt]
\raggedright
{\Large Subject : \sub}\\[5pt]
{\Large Roll No. : \textbf{\roll}}\\[12pt]
}}\hfill % This is for parbox
}%
\end{document}
請注意,對於大型 csv 文件,編譯速度可能會很慢。使用 可以在一定程度上解決這個問題pgfplotstable
。在這裡,可以針對特定中心或主題篩選出大型的單一資料文件,並且可以動態建立單獨的 csv 檔案。建立這些標籤後,您可以使用您的csvtools
包方式或使用datatool
.這是範例程式碼,其使用data.csv
與先前的程式碼相同的內容。
\documentclass[a4paper,12pt]{article}
\usepackage[left=.5cm,right=.5cm,top=.5cm,bottom=.5cm]{geometry}
\usepackage{xcolor}
\usepackage{pgfplotstable,xstring}
\pgfplotsset{compat=1.11}
\usepackage{datatool}
\pgfplotstableread[col sep=comma]{data.csv}\data
\begin{document}
%%----------------------------------------------------------subjectwise
%% following will filter all Psychology rows and save it as Psychology.csv
\pgfplotstablesave[col sep=comma,
row predicate/.code={%
\pgfplotstablegetelem{#1}{Subject}\of\data%
\IfStrEq{\pgfplotsretval}{Psychology}{%True %% >>imp<< Psychology is case sensitive, psychology won't work
\relax}%
{\pgfplotstableuserowfalse}%False
}%
]
{\data}
{Psychology.csv}
%%----------------------------------------------------------
%% from here use datatool
\DTLloaddb{Psychology}{Psychology.csv}
\DTLforeach{Psychology}{%
\center=center,\roll=RollNo,\sub=Subject, \venue=Venue}{%
\noindent\fbox{\parbox{6.3cm}{%
{\color{white}.}\\[7pt]
\centering{\LARGE UGC NET - 2014}\\[2pt]
\raggedright
{\Large Subject : \sub}\\[5pt]
{\Large Roll No. : \textbf{\roll}}\\[12pt]
}}\hfill % This is for parbox
}%
\clearpage
%%---------------------------------------------------------- centerwise
%% following will filter all Bangalore rows and save it as bangalore.csv
\pgfplotstablesave[col sep=comma,
row predicate/.code={%
\pgfplotstablegetelem{#1}{center}\of\data%
\IfStrEq{\pgfplotsretval}{Bangalore}{%True %% >>imp<< Bangalore is case sensitive
\relax}%
{\pgfplotstableuserowfalse}%False
}%
]
{\data}
{bangalore.csv}
%%----------------------------------------------------------
%% from here use datatool/csvtools
\DTLloaddb{bangalore}{bangalore.csv}
\DTLforeach{bangalore}{%
\center=center,\roll=RollNo,\sub=Subject, \venue=Venue}{%
\noindent\fbox{\parbox{6.3cm}{%
{\color{white}.}\\[7pt]
\centering{\LARGE UGC NET - 2014}\\[2pt]
\raggedright
{\Large Subject : \sub}\\[5pt]
{\Large Roll No. : \textbf{\roll}}\\[12pt]
}}\hfill % This is for parbox
}%
\end{document}