所以我遇到了一个问题,因为我的 longtable 似乎总是在表中渲染一个额外的字段。根据我将 \ 放在哪里,它会在经过 csv 之后或之前渲染。
我的代码是:
\documentclass{article}
\usepackage[english]{babel} %Set to icelandic for icelandic documents
\usepackage[left=2cm, top=2cm, right=2cm, bottom=2cm, landscape]{geometry}
\usepackage[table]{xcolor} % For coloring tables rows
\usepackage{csvsimple} % Used to import from csv files to tables
\usepackage{longtable} % For tables spanning multiple pages
\usepackage{filecontents}
\newcolumntype{A}{>{\centering\arraybackslash}m{1.3cm}} % ATA CHAPTER
\newcolumntype{R}{>{\centering\arraybackslash}m{1.5cm}} % Registration code
\newcolumntype{F}{>{\centering\arraybackslash}m{5cm}} % Faults/corredctive
\newcolumntype{T}{>{\centering\arraybackslash}m{2cm}}
\begin{document}
\begin{filecontents*}{csv/pireps.dat}
a;b;c;d;e;f;g;h
a;b;c;d;e;f;g;h
a;b;c;d;e;f;g;h
a;b;c;d;e;f;g;h
a;b;c;d;e;f;g;h
a;b;c;d;e;f;g;h
a;b;c;d;e;f;g;h
a;b;c;d;e;f;g;h
a;b;c;d;e;f;g;h
a;b;c;d;e;f;g;h
a;b;c;d;e;f;g;h
a;b;c;d;e;f;g;h
a;b;c;d;e;f;g;h
a;b;c;d;e;f;g;h
a;b;c;d;e;f;g;h
a;b;c;d;e;f;g;h
a;b;c;d;e;f;g;h
a;b;c;d;e;f;g;h
a;b;c;d;e;f;g;h
a;b;c;d;e;f;g;h
a;b;c;d;e;f;g;h
a;b;c;d;e;f;g;h
a;b;c;d;e;f;g;h
a;b;c;d;e;f;g;h
a;b;c;d;e;f;g;h
\end{filecontents*}
\begin{center}
\rowcolors{2}{gray!25}{white}
\begin{longtable}{|R|T|T|A|F|F|A|A|}
\caption{Summary of PIREPS for}
\label{grid_mlmmh} \\\hline
\rowcolor{gray!50}
\multicolumn{1}{|R|}{\textbf{Reg. code}} &
\multicolumn{1}{T|}{\textbf{Found on date}} &
\multicolumn{1}{T|}{\textbf{Closed on date}} &
\multicolumn{1}{A|}{\textbf{ATA Chapter}} &
\multicolumn{1}{F|}{\textbf{Fault description}} &
\multicolumn{1}{F|}{\textbf{Corrective action}} &
\multicolumn{1}{A|}{\textbf{Flight number}} &
\multicolumn{1}{A|}{\textbf{Fault source}}\\\hline
\endfirsthead
\rowcolor{white!50}
\multicolumn{8}{c}%
{{\bfseries PIREPS -- continued from previous page}} \\\hline
\rowcolor{gray!50}
\multicolumn{1}{|R|}{\textbf{Reg. code}} &
\multicolumn{1}{T|}{\textbf{Found on date}} &
\multicolumn{1}{T|}{\textbf{Closed on date}} &
\multicolumn{1}{A|}{\textbf{ATA chapter}} &
\multicolumn{1}{F|}{\textbf{Fault description}} &
\multicolumn{1}{F|}{\textbf{Corrective action}} &
\multicolumn{1}{A|}{\textbf{Flight number}} &
\multicolumn{1}{A|}{\textbf{Fault source}}
\endhead
\hline \multicolumn{8}{|r|}{{Continued on next page}} \\ \hline
\endfoot
\endlastfoot
\csvreader[separator=semicolon, head to column names]{csv/pireps.dat}{}
{\a & \b & \c & \d & \e & \f & \g & \h\\}
\end{longtable}
\end{center}
\end{document}
非常感谢您的帮助。
答案1
问题在于每个 CSV 行之后都有一个换行符,并且 listings 也会在插入脚之前调用换行符,这样在 CSV 输入之后就有一行只有一个空单元格。
通过使用late after line
选项解决此问题\csvreader
:您可以使用它在除最后一行之外的每个 CSV 行后指定换行符。
\documentclass{article}
\usepackage{csvsimple}
\usepackage{longtable}
\usepackage{filecontents}
\begin{filecontents*}{csv-pireps.dat}
a;b;c;d;e;f;g;h
a;b;c;d;e;f;g;h
a;b;c;d;e;f;g;h
a;b;c;d;e;f;g;h
a;b;c;d;e;f;g;h
\end{filecontents*}
\begin{document}
\begin{longtable}{|c|c|c|c|c|c|c|c|}
\caption{Summary of PIREPS for}
\\\hline
A & B & C & D & E & F & G & H \\\hline
\endfirsthead
\hline
\endlastfoot
\csvreader[separator=semicolon, head to column names, late after line=\\]{csv-pireps.dat}{}
{\a & \b & \c & \d & \e & \f & \g & \h}
\end{longtable}
\end{document}