我正在为论文附录制作一个长表格,该表格跨越多页。我希望每行都不要用线标记,除非指定部分。我唯一能想到的方法是将“\hline”放在 csv 中。当我将它放在第四列文本的末尾时,有时会添加一个额外的单元格或添加一个额外的行;当我将“\hline”放在它自己的行中时,它会添加额外的行。是否可以在不添加额外行的情况下指定这些部分标记在 csv 中的位置?
如果可能的话,我希望得到一个可以在 pgfplotstable 和我已经拥有的 csv 输入/格式化代码中工作的答案,因为其他几个包和尝试最终都无法满足我的表格需求。我从这里的答案中改编了一些代码(pgfplotstable;带有标题和重复标题的长表),如果可能的话,我想继续使用 pgfplotstable - 但这对我来说是一次学习经历,我很感激任何建议。谢谢!
\begin{filecontents*}{SE_example.csv}
\textbf{Section 1:},,,
Item 1 has a long description,2000-2010,Short description here,a
Item 2 also has a long description,1999-2005,This is a longer description and I need to keep this description long so I can be sure that the table will wrap,b
Item 3 is short,1995-2006,This is some text.,c
\hline ,,,
\textbf{Section 2:},,,
Item 4,1999-2005,This is some more text.,d
Item 5,1995-2006,Text here,e \\ \hline
\textbf{Section 3:},,,
Item 6,1990-1997,Text text text,f
Item 7,2000-2004,Text text text text text,g \\ \hline
\textbf{Section 4:},,,
Item 8,1990-1997,Text text text,h
Item 9,2000-2004,Text text text text text,i
\end{filecontents*}
\documentclass[12pt, english]{article}
\usepackage[table]{xcolor}
\definecolor{lightgray}{gray}{0.9}
\usepackage{csvsimple}
\usepackage{longtable}
\usepackage{caption}
\usepackage{setspace}
\usepackage{booktabs}
\usepackage{pgfplotstable}
\usepackage[hmargin=2.54cm, vmargin=2.54cm]{geometry}
\begin{document}
\pgfkeysifdefined{/pgfplots/table/output empty row/.@cmd}{
% upcoming releases offer this more convenient option:
\pgfplotstableset{
empty header/.style={
every head row/.style={output empty row},
}
}
}{
% versions up to and including 1.5.1 need this:
% \pgfplotstableset{
% empty header/.style={
% typeset cell/.append code={%
% \ifnum\pgfplotstablerow=-1 %
% \pgfkeyssetvalue{/pgfplots/table/@cell content}{}%
% \fi
% }
% }
% }
}
\rowcolors{1}{}{lightgray}
\scriptsize
\pgfplotstabletypeset[
empty header,
header=false,
begin table=\begin{longtable},
every first row/.append style={before row={%
\caption{Description of Policies}%
\label{tab:policies}\\\toprule
\textbf{Policy} &\textbf{Years} &\textbf{Description} &\textbf{Sources} \\ \toprule
\endfirsthead
%
\multicolumn{4}{l}%
{{\bfseries Description of Policies \thetable\ Continued from previous page}} \\
\toprule
%
\textbf{Policy} &\textbf{Years} &\textbf{Description} &\textbf{Sources} \\ \toprule
\endhead
%
\midrule \multicolumn{4}{r}{{Continued on next page}} \\ \bottomrule
\endfoot
%
\midrule
\multicolumn{4}{r}{{Concluded}} \\ \bottomrule
\endlastfoot
}},%
%
end table=\end{longtable},
col sep=comma,
string type,
column type=l,
columns/0/.style={column type=p{6cm}},
columns/1/.style={column type=p{1.3cm}},
columns/2/.style={column type=p{6cm}},
columns/3/.style={column type=p{1cm}},
]{SE_example.csv}
\end{document}
答案1
插入\hline
到行首。另外您不需要使用\\
。
\textbf{Section 1:},,,
Item 1 has a long description,2000-2010,Short description here,a
Item 2 also has a long description,1999-2005,This is a longer description and I need to keep this description long so I can be sure that the table will wrap,b
Item 3 is short,1995-2006,This is some text.,c
\hline\textbf{Section 2:},,,
Item 4,1999-2005,This is some more text.,d
Item 5,1995-2006,Text here,e
\hline\textbf{Section 3:},,,
Item 6,1990-1997,Text text text,f
Item 7,2000-2004,Text text text text text,g
\hline\textbf{Section 4:},,,
Item 8,1990-1997,Text text text,h
Item 9,2000-2004,Text text text text text,i