我試圖包含前兩行作為標題。我想- - m m m
在每一頁和下面的另一行上都有單位等。
我不是進階用戶簡單的csv,我一直無法在手冊中找到答案。
第一頁如下圖所示:
第二個:
我已經解決了像 \delta 這樣的乳膠符號的問題。
另外,我面臨的另一個問題是我無法讓標題顯示在每個頁面上。
\begin{longtable}{lllllllllll}
\caption{Database of Ropax Ships.}\\
\toprule
\csvreader[
head=false,
late after line=\\,
filter equal={\thecsvinputline}{1},
]{data_appendix.csv}{}{\csvcoli & \csvcolii & \csvcoliii & \csvcoliv & \csvcolv & \csvcolvi & \csvcolvii & \csvcolviii & \csvcolix}
\midrule
\endfirsthead
\toprule
\csvreader[
head=false,
late after line=\\,
filter equal={\thecsvinputline}{1},
]{data_appendix.csv}{}{\csvcoli & \csvcolii & \csvcoliii & \csvcoliv & \csvcolv & \csvcolvi & \csvcolvii & \csvcolviii & \csvcolix}
\midrule
\endhead
\midrule
\endfoot
\bottomrule
\endlastfoot
\csvreader[
head=false,
late after line=\\,
filter not equal={\thecsvinputline}{1},
]{data_appendix.csv}{}{\csvcoli & \csvcolii & \csvcoliii & \csvcoliv & \csvcolv & \csvcolvi & \csvcolvii & \csvcolviii & \csvcolix}
\end{longtable}
我真的很感激一些幫助。
答案1
好吧,你沒有給出 MWE,所以在某些部分我只能猜測,但這裡的主要罪魁禍首是在 longtable 的標題中使用前兩行 csv 行,並省略顯示數據的前兩行 csv 行。
使用以下程式碼\endfirsthead
:
\csvreader[%
head=false,
late after line=\\,
filter equal={\thecsvinputline}{1},
]{\jobname.csv}{}{\csvcoli & \csvcolii & \csvcoliii & \csvcoliv & \csvcolv & \csvcolvi & \csvcolvii & \csvcolviii & \csvcolix}
\csvreader[% <====================================================== added
head=false,
late after line=\\,
filter equal={\thecsvinputline}{2}, % <========================= line 2
]{\jobname.csv}{}{\csvcoli & \csvcolii & \csvcoliii & \csvcoliv & \csvcolv & \csvcolvi & \csvcolvii & \csvcolviii & \csvcolix}
\midrule
\endfirsthead
對於\endhead
:
\toprule
\csvreader[
head=false,
late after line=\\,
filter equal={\thecsvinputline}{1},
]{\jobname.csv}{}{\csvcoli & \csvcolii & \csvcoliii & \csvcoliv & \csvcolv & \csvcolvi & \csvcolvii & \csvcolviii & \csvcolix}
\csvreader[% <================================================== added
head=false,
late after line=\\,
filter equal={\thecsvinputline}{2}, % <========================= line 2
]{\jobname.csv}{}{\csvcoli & \csvcolii & \csvcoliii & \csvcoliv & \csvcolv & \csvcolvi & \csvcolvii & \csvcolviii & \csvcolix}
\midrule
\endhead
新增的行將帶有\csvreader
單位的第二行列印到表標題中。
要列印完整的表格,我們只需從第 3 行開始列印(行filter test=\ifnumgreater{\thecsvinputline}{2},
檢查目前行號是否大於 2):
\csvreader[%
head=false,
late after line=\\,
filter test=\ifnumgreater{\thecsvinputline}{2},
]{\jobname.csv}{}{\csvcoli & \csvcolii & \csvcoliii & \csvcoliv & \csvcolv & \csvcolvi & \csvcolvii & \csvcolviii & \csvcolix}
因此,請使用以下完整的 mwe(請注意標頭需要您已經完成的工作,請使用未顯示的程式碼):
\begin{filecontents*}{\jobname.csv}
Vessel Name , Year, LOA , LBP , B , T , D , DUP , Delta
- , - , m , m , m , m , m , m , t
Abel Matutes, 2010, 187 , 177 , 26.2, 6 , 9.2, 14.54, -
Aretousa , 1995, 177.3, 166.4, 27 , 6.3, 9.1, 20.05, -
Abel Matutes, 2010, 187 , 177 , 26.2, 6 , 9.2, 14.54, -
Aretousa , 1995, 177.3, 166.4, 27 , 6.3, 9.1, 20.05, -
Abel Matutes, 2010, 187 , 177 , 26.2, 6 , 9.2, 14.54, -
Aretousa , 1995, 177.3, 166.4, 27 , 6.3, 9.1, 20.05, -
Abel Matutes, 2010, 187 , 177 , 26.2, 6 , 9.2, 14.54, -
Aretousa , 1995, 177.3, 166.4, 27 , 6.3, 9.1, 20.05, -
Abel Matutes, 2010, 187 , 177 , 26.2, 6 , 9.2, 14.54, -
Aretousa , 1995, 177.3, 166.4, 27 , 6.3, 9.1, 20.05, -
Abel Matutes, 2010, 187 , 177 , 26.2, 6 , 9.2, 14.54, -
Aretousa , 1995, 177.3, 166.4, 27 , 6.3, 9.1, 20.05, -
Abel Matutes, 2010, 187 , 177 , 26.2, 6 , 9.2, 14.54, -
Aretousa , 1995, 177.3, 166.4, 27 , 6.3, 9.1, 20.05, -
Abel Matutes, 2010, 187 , 177 , 26.2, 6 , 9.2, 14.54, -
Aretousa , 1995, 177.3, 166.4, 27 , 6.3, 9.1, 20.05, -
Abel Matutes, 2010, 187 , 177 , 26.2, 6 , 9.2, 14.54, -
Aretousa , 1995, 177.3, 166.4, 27 , 6.3, 9.1, 20.05, -
Abel Matutes, 2010, 187 , 177 , 26.2, 6 , 9.2, 14.54, -
Aretousa , 1995, 177.3, 166.4, 27 , 6.3, 9.1, 20.05, -
Abel Matutes, 2010, 187 , 177 , 26.2, 6 , 9.2, 14.54, -
Aretousa , 1995, 177.3, 166.4, 27 , 6.3, 9.1, 20.05, -
Abel Matutes, 2010, 187 , 177 , 26.2, 6 , 9.2, 14.54, -
Aretousa , 1995, 177.3, 166.4, 27 , 6.3, 9.1, 20.05, -
Abel Matutes, 2010, 187 , 177 , 26.2, 6 , 9.2, 14.54, -
Aretousa , 1995, 177.3, 166.4, 27 , 6.3, 9.1, 20.05, -
Abel Matutes, 2010, 187 , 177 , 26.2, 6 , 9.2, 14.54, -
Aretousa , 1995, 177.3, 166.4, 27 , 6.3, 9.1, 20.05, -
Abel Matutes, 2010, 187 , 177 , 26.2, 6 , 9.2, 14.54, -
Aretousa , 1995, 177.3, 166.4, 27 , 6.3, 9.1, 20.05, -
Abel Matutes, 2010, 187 , 177 , 26.2, 6 , 9.2, 14.54, -
Aretousa , 1995, 177.3, 166.4, 27 , 6.3, 9.1, 20.05, -
Abel Matutes, 2010, 187 , 177 , 26.2, 6 , 9.2, 14.54, -
Aretousa , 1995, 177.3, 166.4, 27 , 6.3, 9.1, 20.05, -
Abel Matutes, 2010, 187 , 177 , 26.2, 6 , 9.2, 14.54, -
Aretousa , 1995, 177.3, 166.4, 27 , 6.3, 9.1, 20.05, -
Abel Matutes, 2010, 187 , 177 , 26.2, 6 , 9.2, 14.54, -
Aretousa , 1995, 177.3, 166.4, 27 , 6.3, 9.1, 20.05, -
Abel Matutes, 2010, 187 , 177 , 26.2, 6 , 9.2, 14.54, -
Aretousa , 1995, 177.3, 166.4, 27 , 6.3, 9.1, 20.05, -
Abel Matutes, 2010, 187 , 177 , 26.2, 6 , 9.2, 14.54, -
Aretousa , 1995, 177.3, 166.4, 27 , 6.3, 9.1, 20.05, -
Abel Matutes, 2010, 187 , 177 , 26.2, 6 , 9.2, 14.54, -
Aretousa , 1995, 177.3, 166.4, 27 , 6.3, 9.1, 20.05, -
Abel Matutes, 2010, 187 , 177 , 26.2, 6 , 9.2, 14.54, -
Aretousa , 1995, 177.3, 166.4, 27 , 6.3, 9.1, 20.05, -
Abel Matutes, 2010, 187 , 177 , 26.2, 6 , 9.2, 14.54, -
Aretousa , 1995, 177.3, 166.4, 27 , 6.3, 9.1, 20.05, -
Abel Matutes, 2010, 187 , 177 , 26.2, 6 , 9.2, 14.54, -
Aretousa , 1995, 177.3, 166.4, 27 , 6.3, 9.1, 20.05, -
\end{filecontents*}
\documentclass{article}
\usepackage{csvsimple}
\usepackage{booktabs}
\usepackage{longtable}
\begin{document}
\begin{longtable}{lllllllllll}
\caption{Database of Ropax Ships.}\\
\toprule
\csvreader[%
head=false,
late after line=\\,
filter equal={\thecsvinputline}{1},
]{\jobname.csv}{}{\csvcoli & \csvcolii & \csvcoliii & \csvcoliv & \csvcolv & \csvcolvi & \csvcolvii & \csvcolviii & \csvcolix}
\csvreader[% <====================================================== added
head=false,
late after line=\\,
filter equal={\thecsvinputline}{2}, % <========================= line 2
]{\jobname.csv}{}{\csvcoli & \csvcolii & \csvcoliii & \csvcoliv & \csvcolv & \csvcolvi & \csvcolvii & \csvcolviii & \csvcolix}
\midrule
\endfirsthead
\toprule
\csvreader[
head=false,
late after line=\\,
filter equal={\thecsvinputline}{1},
]{\jobname.csv}{}{\csvcoli & \csvcolii & \csvcoliii & \csvcoliv & \csvcolv & \csvcolvi & \csvcolvii & \csvcolviii & \csvcolix}
\csvreader[% <================================================== added
head=false,
late after line=\\,
filter equal={\thecsvinputline}{2}, % <========================= line 2
]{\jobname.csv}{}{\csvcoli & \csvcolii & \csvcoliii & \csvcoliv & \csvcolv & \csvcolvi & \csvcolvii & \csvcolviii & \csvcolix}
\midrule
\endhead
\midrule
\endfoot
\bottomrule
\endlastfoot
\csvreader[%
head=false,
late after line=\\,
filter test=\ifnumgreater{\thecsvinputline}{2},
]{\jobname.csv}{}{\csvcoli & \csvcolii & \csvcoliii & \csvcoliv & \csvcolv & \csvcolvi & \csvcolvii & \csvcolviii & \csvcolix}
\end{longtable}
\end{document}
及其結果:
將 csv 行 1 和 2 顯示為表格標題,並以第 3 行開始表格內容,對於第二頁,您也根據需要將第 1 行和 2 行顯示為標題: