csvsimple 换行表格单元格

csvsimple 换行表格单元格

我正在使用 csvsimple 包将 csv 文件作为表格嵌入到我的 latex 文档中。

看起来长单元格内容会破坏渲染:

令牌.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}

相关内容