
我正在使用 csvsimple 套件將 csv 檔案作為表格嵌入到我的乳膠文件中。
看起來長單元格內容破壞了渲染:
令牌.csv:
method,corpus,tokens
MI,Quran,"allah, thou, thi, punish, believ, ye, thee, messeng, unbeliev, guid"
MI,OT,"allah, jesu, christ, thi, king, israel, believ, thou, lord, thee"
MI,NT,"jesu, christ, allah, ye, discipl, lord, thing, faith, israel, peter"
CHI²,Quran,"allah, punish, believ, messeng, unbeliev, guid, beli, disbeliev, vers, clear"
CHI²,OT,"allah, jesu, christ, thi, believ, king, israel, lord, thou, world"
CHI²,NT,"jesu, christ, discipl, ye, faith, thing, paul, peter, lord, allah"
主.tex:
\csvautotabular{tokens.csv}
我假設是因為第三個單元格內容很長(單元格內容較短的其他 CSV 嵌入在我的文件中正確呈現)
我怎樣才能解決這個問題?
CSV 檔案直接來自其他程序,因此我不想編輯它們根本不,或至少不會使它們與標準 CSV 格式不相容。
答案1
從csvsimple
手冊中:
值不應被引用或用
{}
TEX 組的花括號引用。其他引號(如雙引號)不直接支持,但可以透過外部工具實現,請參閱第 41 頁的第 5.6 節。
因此,使用一組{}
而不是" "
包含第三個單元格的內容應該可行:
\documentclass{article}
\usepackage{csvsimple}
\usepackage{tabularx}
\begin{filecontents*}{tokens.csv}
method,corpus,tokens
MI,Quran,{allah, thou, thi, punish, believ, ye, thee, messeng, unbeliev, guid}
MI,OT,{allah, jesu, christ, thi, king, israel, believ, thou, lord, thee}
MI,NT,{jesu, christ, allah, ye, discipl, lord, thing, faith, israel, peter}
CHI²,Quran,{allah, punish, believ, messeng, unbeliev, guid, beli, disbeliev, vers, clear}
CHI²,OT,{allah, jesu, christ, thi, believ, king, israel, lord, thou, world}
CHI²,NT,{jesu, christ, discipl, ye, faith, thing, paul, peter, lord, allah}
\end{filecontents*}
\begin{document}
\csvautotabular{tokens.csv}
\bigskip
\csvreader[
tabular=|l | l | p{7cm}|,
table head= \hline method & corpus & tokens \\ \hline,
late after last line=\\\hline,
]{tokens.csv}{}%
{\csvcoli & \csvcolii & \csvcoliii}
\bigskip
\begin{tabularx}{\linewidth}{|l|l|X|}
\hline
method & corpus & tokens \\
\hline
\csvreader[late after line=\\, late after last line =\\\hline]
{tokens.csv}
{}
{\csvcoli & \csvcolii & \csvcoliii}
\end{tabularx}
\end{document}