创建 csv 简单双标题

创建 csv 简单双标题

我正在尝试将前两行作为标题。我希望- - m m m在每一页上都显示单位等,并在下方另设一行。

我不是csvsimple,而且我在手册中也无法找到答案。

第一页如下所示:

第一的

第二:

第二

我已经解决了存在 \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}

及其结果:

结果页面 1

将 csv 的第 1 行和第 2 行显示为表格标题,并从第 3 行开始表格内容,对于第二页,您还可以按希望显示第 1 行和第 2 行作为标题:

在此处输入图片描述

相关内容