我想将 csv 转换为这样的精美表格:
首先,我用我的 MWE 制作一个基本表格,如下所示:
\documentclass{article}
%\usepackage{csvsimple}
\usepackage{pgfplotstable,filecontents}
\usepackage{pdflscape}
\pgfplotsset{compat=1.9}% supress warning
\begin{filecontents*}{test.csv}
Presentation,Views,Downloads,Favorites,Comments,Email Shares,Facebook Shares,Tweets,LinkedIn Shares
Biber,3,0,0,0,0,0,0,0
Matlab Prettifier Package,68,0,0,0,0,0,0,0
LaTeX3,173,1,0,0,0,0,0,0
PythonTeX,84,0,0,0,0,0,0,0
PerlTeX,131,0,0,0,0,0,0,0
Matplotlib ,37,0,0,0,0,0,0,0
SciPy,68,0,1,0,0,0,0,0
PythonTeX Quick Start,22,0,0,0,0,0,0,0
Introduction to PythonTeX,34,0,0,0,0,0,0,0
IPython,30,0,0,0,0,0,0,0
Matplotlib Introduction ,30,0,0,0,0,0,0,0
Galeri PythonTeX,54,0,0,0,0,0,0,0
IPython : Operasi Dasar di Sympy,30,0,0,0,0,0,0,0
Introduction to IPython ,22,1,0,0,0,0,0,0
Introduction to NumPy,23,0,0,0,0,0,0,0
Road to PythonTeX ,72,0,0,0,0,0,0,0
PythonTeX dan Sympy kolaborasi ,28,3,0,0,0,0,0,0
Andreas Linz Beamer ,33,0,0,0,0,0,0,0
Menyisipkan teks Arab ke LaTeX,21,0,0,0,0,0,0,0
Xelatex & Japanese,17,0,0,0,0,0,0,0
Korean xelatex,27,0,0,0,0,0,0,0
Wordlike,19,0,0,0,0,0,0,0
LaTeX Notasi Matematika ,68,10,0,0,0,0,0,0
MusicTEX " Simpony LATEX dalam Musik " ,255,0,0,0,0,0,0,0
Membuat Dokumen LaTeX3,23,1,0,0,0,0,0,0
Membuat Dokumen Beamer LaTeX,63,1,0,0,0,0,0,0
Membuat Dokumen LaTeX ,146,4,0,0,0,0,0,0
Beamer Media Presentasi LaTeX,141,15,0,0,0,0,0,0
Membuat Dokumen LaTeX,273,5,0,0,0,0,3,0
Beamer Theme Glugor,49,0,0,0,0,0,0,0
Minted, High Lighting Source Code,68,0,0,0,0,0,0,0
Penggunaan dua bahasa dalam dokumen LATEX,142,0,0,0,0,0,0,0
Solusi kesalahan ketika penggantian bahasa,138,0,0,0,0,0,0,0
Ping! LaTeX ,215,0,0,0,0,0,0,0
Membuat Dokumen LaTeX edisi 13,313,6,0,0,0,0,0,0
Beamer, Media Presentasi LaTeX,216,5,0,0,0,0,0,0
Membuat dokumen la tex edisi 12,405,2,0,0,0,0,5,0
Membuat Dokumen LaTeX Eleventh Edition,454,18,2,0,0,0,0,0
Presentasi Beamer : Dark Themes,228,0,0,0,0,0,0,0
Simpleslides, Media Presentasi ConTeXt ,83,3,0,0,0,0,0,0
Laporan Metode Statistikia II,236,0,0,0,0,0,0,0
Con text Untuk Pemula,48,1,0,0,0,0,0,0
My Talking Custom and Tools ,116,0,0,0,0,0,0,0
Farm Frenzy ,299,1,0,0,0,0,0,0
LaTeX 3 Paper,73,1,0,0,0,0,0,0
R -Sweave/ Sweave For Statistical Programming at LaTeX ,165,5,0,0,0,0,0,0
LaTeX Cheat Sheet,194,9,0,0,0,0,0,0
LaTeX Cheat Sheet ,77,0,0,0,0,0,0,0
PlainTeX, A Virgin TeX :),129,2,0,0,0,0,0,0
Beamer atau .PpT,288,11,0,0,0,0,0,0
Xelatex,142,5,0,0,0,0,0,0
Powerdot slide,276,25,0,0,0,0,0,0
Kaligrafi and math font,328,2,0,0,0,0,0,0
Utopia regular with math design,225,1,0,0,0,0,0,0
Tx fonts,195,1,0,0,0,0,0,0
Times,203,1,0,0,0,0,0,0
Px fonts,189,1,0,0,0,0,0,0
Palatino,209,1,0,0,0,0,0,0
New century school book,201,1,0,0,0,0,0,0
Lx font,21,0,0,0,0,0,0,0
Latin modern,25,0,0,0,0,0,0,0
Kurier light condensed,24,0,0,0,0,0,0,0
Kurier light,18,0,0,0,0,0,0,0
Kurier condensed,13,0,0,0,0,0,0,0
Kurier condensed,21,0,0,0,0,0,0,0
Kurier,203,0,0,0,0,0,0,0
Kurier,50,0,0,0,0,0,0,0
Kerkis,42,0,0,0,0,0,0,0
Kp sans serif,38,0,0,0,0,0,0,0
Iwona light condensed,15,0,0,0,0,0,0,0
Iwona light,16,0,0,0,0,0,0,0
Iwona condensed,27,0,0,0,0,0,0,0
Iwona,15,0,0,0,0,0,0,0
Gfs neohellenic,19,0,0,0,0,0,0,0
Gfs artemisia with,22,0,0,0,0,0,0,0
Gfs artemisia,22,0,0,0,0,0,0,0
Computer modern light,18,0,0,0,0,0,0,0
Computer modern,12,0,0,0,0,0,0,0
Computer concrete,16,0,0,0,0,0,0,0
Charter bt,13,0,0,0,0,0,0,0
Charter bt,20,0,0,0,0,0,0,0
Boisik,21,0,0,0,0,0,0,0
Arev,24,0,0,0,0,0,0,0
Antykwa toruńska light,9,0,0,0,0,0,0,0
Antykwa toruńska condensed light,18,0,0,0,0,0,0,0
Antykwa toruńska condensed,16,0,0,0,0,0,0,0
Antykwa toruńska,23,0,0,0,0,0,0,0
Chap16 scr,158,3,0,0,0,0,0,0
Chap15 scr,36,2,0,0,0,0,0,0
Chap14 scr,56,1,0,0,0,0,0,0
Chap12 scr,68,3,0,0,0,0,0,0
Chap11 scr,53,2,0,0,0,0,0,0
Chap10 scr,41,2,0,0,0,0,0,0
Chap09 scr,240,1,0,0,0,0,0,0
Chap08 scr,51,2,0,0,0,0,0,0
Chap07 scr,56,1,0,0,0,0,0,0
Chap06 scr,48,1,0,0,0,0,0,0
Chap05 scr,36,1,0,0,0,0,0,0
Chap04 scr,33,1,0,0,0,0,0,0
Chap03 scr,56,1,0,0,0,0,0,0
Chap02 scr,88,1,0,0,0,0,0,0
Chap01 scr,401,2,0,0,0,0,0,0
Chap17 scr,140,1,0,0,0,0,0,0
Chap13 scr,66,4,0,0,0,0,0,0
Fancy Beamer :),78,0,0,0,0,0,1,0
Vector in ConTeXt ,55,0,0,0,0,0,1,0
Synonyms in ConTeXt,47,0,0,0,0,0,1,0
Special character in ConTeXt ,63,0,0,0,0,0,1,0
Powerdot LaTeX,324,1,0,0,0,0,1,0
Outlinde text in ConTeXt,49,0,0,0,0,0,1,0
MetaPost in LaTeX,137,3,0,0,0,0,1,0
Math in ConTeXt ,142,4,0,0,0,0,1,0
Math basic in ConTeXt,124,1,0,0,0,0,1,0
Math align in ConTeXt ,64,0,0,0,0,0,1,0
Itemize in ConTeXt,459,0,0,0,0,0,1,0
Definitions in ConTeXt,153,0,0,0,0,0,1,0
Columns in ConTeXt ,61,0,0,0,0,0,0,0
Combining Statistical Programming with LaTeX,29,0,0,0,0,0,0,0
Combining Statistical Programming with LaTeX,38,2,0,0,0,0,0,0
Beamer Presentation,459,11,0,2,0,0,1,0
Pengantar la tex,246,5,0,0,0,0,1,0
LaTeX InDesign Creative Cloud with PGF/ TikZ,1512,24,0,0,0,0,1,0
Post Script LaTeX,50,0,0,0,0,0,0,0
Post Script LATEX,76,0,0,0,0,0,0,0
LaTeX InDesign with Smart Diagram Miicrosoft Word 2013,1323,183,0,0,2,0,1,0
Letech indesign cc,372,4,0,0,0,0,1,0
LaTeX InDesign Crative Cloud ,751,27,0,0,0,0,1,0
LaTeX InDesign CC,986,7,0,0,0,0,1,0
Adobe in design cc,1435,72,1,0,1,0,0,0
Adobe InDesign CC with LaTeX,225,11,0,0,0,0,1,0
Membuat dokumen latex Revisi I,129,5,0,0,0,0,0,0
Post Script LaTeX ?,51,2,0,0,0,0,1,0
Membuat Dokumen LaTeX,3480,362,1,1,5,0,1,0
Cover book with post scripts,77,0,1,0,0,0,0,0
Risalah Jumat, Islam Agama Akal dan Ilmu,669,0,0,0,0,0,0,0
Paperksmt,249,0,0,0,3,0,0,0
Beamer color,282,0,0,0,0,0,0,0
Doble color with beamer LaTeX,36,0,0,0,0,0,0,0
Beameruse theme Purdue University,152,0,0,0,0,0,0,0
Freewilly with beamerusetheme Torino.sty,399,0,0,0,0,0,0,0
Transparansi Background with LaTeX beamer,114,0,0,0,0,0,0,0
Chameleon, beameruse theme Torino.sty ,1150,0,0,0,1,0,0,0
Fancy Page with LaTeX ,93,0,0,0,0,0,0,0
Majalah with Adobe InDesign ,42,0,0,0,0,0,0,0
Poster with LaTeX,45,0,0,0,0,0,0,0
Collecting Code LaTeX 2013 ,665,0,1,0,1,0,0,0
Mengenal adobe in design cs6,3078,0,7,0,18,0,0,0
A Beautiful Beamer LaTeX,73,0,0,0,0,0,0,0
Coding Theory Report Final ,1001,0,1,1,10,0,0,0
Papercoding Final,200,0,0,0,2,0,0,0
Self Dual Codes and Binary Golay Code Presentation ,192,5,0,0,0,0,0,0
Bch codes final slide ,307,19,0,0,0,0,0,0
Beautifull pink latex,65,0,0,0,0,0,0,0
Bch codes,315,14,0,0,0,0,0,0
\end{filecontents*}
\begin{document}
\section*{Theory}
\pgfplotstabletypeset[col sep=comma,
columns={Presentation,Views,Downloads,Favorites,Comments,Email Shares,Facebook Shares,Tweets,LinkedIn Shares},
]{test.csv}
\end{document}
但是,我收到了如下错误:
LaTeX Warning: Overwriting file `./test.csv'.
LaTeX Warning: Tab has been converted to Blank Space.
No file Slide_share.aux.
ABD: EveryShipout initializing macros
("C:\Program Files\MiKTeX 2.9\tex\context\base\supp-pdf.mkii"
[Loading MPS to PDF converter (version 2006.09.02).]
)
Package pgfplots notification 'compat/show suggested version=true': you might b
enefit from \pgfplotsset{compat=1.11} (current compat level: 1.9).
! Package pgfplots Error: Table 'test.csv' appears to have too many columns in
line 31: Ignoring '0'. PGFPlots found that the number of columns is larger than
the previously determined number of columns. Please verify that every cell ent
ry is separated correctly (use braces {<cell entry>} if necessary. Also verify
that column names are plain ASCII.). This error is not critical.
See the pgfplots package documentation for explanation.
Type H <return> for immediate help.
...
l.172 ]{test.csv}
?
如何解决?
答案1
至少有两个问题。首先,你需要告诉程序你的第一列不是浮点数,而程序需要浮点数。例如:
\pgfplotstabletypeset[
col sep=comma,
columns/Presentation/.style={string type},
columns={Presentation,Views,Downloads,Favorites,Comments,Email Shares,Facebook Shares,Tweets,LinkedIn Shares},
]{test.csv}
第二,您需要考虑在第一列中传递的内容。例如,如果名称包含逗号,则该逗号将被解释为新列。为了避免这种情况,您需要使用花括号。例如:
{Minted, High Lighting Source Code},68,0,0,0,0,0,0,0
正如手册所解释的那样,这里没有什么神奇之处——它只是通过按照你的指示解析代码来创建表格环境。如果你指定逗号作为列分隔符,则任何逗号之内必须处理某一列以避免解析器将其解释为新列。
顺便说一句,您的表格对于页面来说太宽、太高了。
代码可以编译,但这就是它的全部内容:
\documentclass{article}
\usepackage{pgfplotstable,filecontents}
\usepackage{pdflscape}
\pgfplotsset{compat=1.9}% supress warning
\begin{filecontents*}{test.csv}
Presentation,Views,Downloads,Favorites,Comments,Email Shares,Facebook Shares,Tweets,LinkedIn Shares
Biber,3,0,0,0,0,0,0,0
Matlab Prettifier Package,68,0,0,0,0,0,0,0
LaTeX3,173,1,0,0,0,0,0,0
PythonTeX,84,0,0,0,0,0,0,0
PerlTeX,131,0,0,0,0,0,0,0
Matplotlib ,37,0,0,0,0,0,0,0
SciPy,68,0,1,0,0,0,0,0
PythonTeX Quick Start,22,0,0,0,0,0,0,0
Introduction to PythonTeX,34,0,0,0,0,0,0,0
IPython,30,0,0,0,0,0,0,0
Matplotlib Introduction ,30,0,0,0,0,0,0,0
Galeri PythonTeX,54,0,0,0,0,0,0,0
IPython : Operasi Dasar di Sympy,30,0,0,0,0,0,0,0
Introduction to IPython ,22,1,0,0,0,0,0,0
Introduction to NumPy,23,0,0,0,0,0,0,0
Road to PythonTeX ,72,0,0,0,0,0,0,0
PythonTeX dan Sympy kolaborasi ,28,3,0,0,0,0,0,0
Andreas Linz Beamer ,33,0,0,0,0,0,0,0
Menyisipkan teks Arab ke LaTeX,21,0,0,0,0,0,0,0
Xelatex \& Japanese,17,0,0,0,0,0,0,0
Korean xelatex,27,0,0,0,0,0,0,0
Wordlike,19,0,0,0,0,0,0,0
LaTeX Notasi Matematika ,68,10,0,0,0,0,0,0
MusicTEX " Simpony LATEX dalam Musik " ,255,0,0,0,0,0,0,0
Membuat Dokumen LaTeX3,23,1,0,0,0,0,0,0
Membuat Dokumen Beamer LaTeX,63,1,0,0,0,0,0,0
Membuat Dokumen LaTeX ,146,4,0,0,0,0,0,0
Beamer Media Presentasi LaTeX,141,15,0,0,0,0,0,0
Membuat Dokumen LaTeX,273,5,0,0,0,0,3,0
Beamer Theme Glugor,49,0,0,0,0,0,0,0
{Minted, High Lighting Source Code},68,0,0,0,0,0,0,0
Penggunaan dua bahasa dalam dokumen LATEX,142,0,0,0,0,0,0,0
Solusi kesalahan ketika penggantian bahasa,138,0,0,0,0,0,0,0
Ping! LaTeX ,215,0,0,0,0,0,0,0
Membuat Dokumen LaTeX edisi 13,313,6,0,0,0,0,0,0
{Beamer, Media Presentasi LaTeX},216,5,0,0,0,0,0,0
Membuat dokumen la tex edisi 12,405,2,0,0,0,0,5,0
Membuat Dokumen LaTeX Eleventh Edition,454,18,2,0,0,0,0,0
Presentasi Beamer : Dark Themes,228,0,0,0,0,0,0,0
{Simpleslides, Media Presentasi ConTeXt },83,3,0,0,0,0,0,0
Laporan Metode Statistikia II,236,0,0,0,0,0,0,0
Con text Untuk Pemula,48,1,0,0,0,0,0,0
My Talking Custom and Tools ,116,0,0,0,0,0,0,0
Farm Frenzy ,299,1,0,0,0,0,0,0
LaTeX 3 Paper,73,1,0,0,0,0,0,0
R -Sweave/ Sweave For Statistical Programming at LaTeX ,165,5,0,0,0,0,0,0
LaTeX Cheat Sheet,194,9,0,0,0,0,0,0
LaTeX Cheat Sheet ,77,0,0,0,0,0,0,0
{PlainTeX, A Virgin TeX :)},129,2,0,0,0,0,0,0
Beamer atau .PpT,288,11,0,0,0,0,0,0
Xelatex,142,5,0,0,0,0,0,0
Powerdot slide,276,25,0,0,0,0,0,0
Kaligrafi and math font,328,2,0,0,0,0,0,0
Utopia regular with math design,225,1,0,0,0,0,0,0
Tx fonts,195,1,0,0,0,0,0,0
Times,203,1,0,0,0,0,0,0
Px fonts,189,1,0,0,0,0,0,0
Palatino,209,1,0,0,0,0,0,0
New century school book,201,1,0,0,0,0,0,0
Lx font,21,0,0,0,0,0,0,0
Latin modern,25,0,0,0,0,0,0,0
Kurier light condensed,24,0,0,0,0,0,0,0
Kurier light,18,0,0,0,0,0,0,0
Kurier condensed,13,0,0,0,0,0,0,0
Kurier condensed,21,0,0,0,0,0,0,0
Kurier,203,0,0,0,0,0,0,0
Kurier,50,0,0,0,0,0,0,0
Kerkis,42,0,0,0,0,0,0,0
Kp sans serif,38,0,0,0,0,0,0,0
Iwona light condensed,15,0,0,0,0,0,0,0
Iwona light,16,0,0,0,0,0,0,0
Iwona condensed,27,0,0,0,0,0,0,0
Iwona,15,0,0,0,0,0,0,0
Gfs neohellenic,19,0,0,0,0,0,0,0
Gfs artemisia with,22,0,0,0,0,0,0,0
Gfs artemisia,22,0,0,0,0,0,0,0
Computer modern light,18,0,0,0,0,0,0,0
Computer modern,12,0,0,0,0,0,0,0
Computer concrete,16,0,0,0,0,0,0,0
Charter bt,13,0,0,0,0,0,0,0
Charter bt,20,0,0,0,0,0,0,0
Boisik,21,0,0,0,0,0,0,0
Arev,24,0,0,0,0,0,0,0
Antykwa toruńska light,9,0,0,0,0,0,0,0
Antykwa toruńska condensed light,18,0,0,0,0,0,0,0
Antykwa toruńska condensed,16,0,0,0,0,0,0,0
Antykwa toruńska,23,0,0,0,0,0,0,0
Chap16 scr,158,3,0,0,0,0,0,0
Chap15 scr,36,2,0,0,0,0,0,0
Chap14 scr,56,1,0,0,0,0,0,0
Chap12 scr,68,3,0,0,0,0,0,0
Chap11 scr,53,2,0,0,0,0,0,0
Chap10 scr,41,2,0,0,0,0,0,0
Chap09 scr,240,1,0,0,0,0,0,0
Chap08 scr,51,2,0,0,0,0,0,0
Chap07 scr,56,1,0,0,0,0,0,0
Chap06 scr,48,1,0,0,0,0,0,0
Chap05 scr,36,1,0,0,0,0,0,0
Chap04 scr,33,1,0,0,0,0,0,0
Chap03 scr,56,1,0,0,0,0,0,0
Chap02 scr,88,1,0,0,0,0,0,0
Chap01 scr,401,2,0,0,0,0,0,0
Chap17 scr,140,1,0,0,0,0,0,0
Chap13 scr,66,4,0,0,0,0,0,0
Fancy Beamer :),78,0,0,0,0,0,1,0
Vector in ConTeXt ,55,0,0,0,0,0,1,0
Synonyms in ConTeXt,47,0,0,0,0,0,1,0
Special character in ConTeXt ,63,0,0,0,0,0,1,0
Powerdot LaTeX,324,1,0,0,0,0,1,0
Outlinde text in ConTeXt,49,0,0,0,0,0,1,0
MetaPost in LaTeX,137,3,0,0,0,0,1,0
Math in ConTeXt ,142,4,0,0,0,0,1,0
Math basic in ConTeXt,124,1,0,0,0,0,1,0
Math align in ConTeXt ,64,0,0,0,0,0,1,0
Itemize in ConTeXt,459,0,0,0,0,0,1,0
Definitions in ConTeXt,153,0,0,0,0,0,1,0
Columns in ConTeXt ,61,0,0,0,0,0,0,0
Combining Statistical Programming with LaTeX,29,0,0,0,0,0,0,0
Combining Statistical Programming with LaTeX,38,2,0,0,0,0,0,0
Beamer Presentation,459,11,0,2,0,0,1,0
Pengantar la tex,246,5,0,0,0,0,1,0
LaTeX InDesign Creative Cloud with PGF/ TikZ,1512,24,0,0,0,0,1,0
Post Script LaTeX,50,0,0,0,0,0,0,0
Post Script LATEX,76,0,0,0,0,0,0,0
LaTeX InDesign with Smart Diagram Miicrosoft Word 2013,1323,183,0,0,2,0,1,0
Letech indesign cc,372,4,0,0,0,0,1,0
LaTeX InDesign Crative Cloud ,751,27,0,0,0,0,1,0
LaTeX InDesign CC,986,7,0,0,0,0,1,0
Adobe in design cc,1435,72,1,0,1,0,0,0
Adobe InDesign CC with LaTeX,225,11,0,0,0,0,1,0
Membuat dokumen latex Revisi I,129,5,0,0,0,0,0,0
Post Script LaTeX ?,51,2,0,0,0,0,1,0
Membuat Dokumen LaTeX,3480,362,1,1,5,0,1,0
Cover book with post scripts,77,0,1,0,0,0,0,0
{Risalah Jumat, Islam Agama Akal dan Ilmu},669,0,0,0,0,0,0,0
Paperksmt,249,0,0,0,3,0,0,0
Beamer color,282,0,0,0,0,0,0,0
Doble color with beamer LaTeX,36,0,0,0,0,0,0,0
Beameruse theme Purdue University,152,0,0,0,0,0,0,0
Freewilly with beamerusetheme Torino.sty,399,0,0,0,0,0,0,0
Transparansi Background with LaTeX beamer,114,0,0,0,0,0,0,0
{Chameleon, beameruse theme Torino.sty },1150,0,0,0,1,0,0,0
Fancy Page with LaTeX ,93,0,0,0,0,0,0,0
Majalah with Adobe InDesign ,42,0,0,0,0,0,0,0
Poster with LaTeX,45,0,0,0,0,0,0,0
Collecting Code LaTeX 2013 ,665,0,1,0,1,0,0,0
Mengenal adobe in design cs6,3078,0,7,0,18,0,0,0
A Beautiful Beamer LaTeX,73,0,0,0,0,0,0,0
Coding Theory Report Final ,1001,0,1,1,10,0,0,0
Papercoding Final,200,0,0,0,2,0,0,0
Self Dual Codes and Binary Golay Code Presentation ,192,5,0,0,0,0,0,0
Bch codes final slide ,307,19,0,0,0,0,0,0
Beautifull pink latex,65,0,0,0,0,0,0,0
Bch codes,315,14,0,0,0,0,0,0
\end{filecontents*}
\begin{document}
编辑
接下来?从手册的第 21 页开始,其中解释了如何自定义表环境。例如(逐字引用手册):
% replicate column names on top of every page of a multi-page table:
\pgfplotstableset{
row sep=\\,
begin table=\begin{longtable},
end table=\end{longtable},
every head row/.append style={after row=\endhead},
}