如何在导入的 csv 表和周围文本之间放置垂直间距?

如何在导入的 csv 表和周围文本之间放置垂直间距?

我想要的是在表格顶部和其上方的段落之间以及表格底部和其下方的段落之间有垂直间距。

我在序言中的具体说明是:

\usepackage{pgfplotstable}

这是桌子周围的布置:

 Age (0-120 years and over) by sex, usually resident population. Table 8001, using the Timaru District area specification. First 30 of 210 rows.


\pgfplotstabletypeset[
col sep = comma,
columns/Area/.style={string type},
columns/Age.group/.style={string type},
columns/Sex/.style={string type},
columns/Value/.style={string type},
every head row/.style={
before row=\toprule,after row=\midrule},
every last row/.style={
after row=\bottomrule}
]
{Table8001a.csv}


Table 8001a modified for use with aegis. First 30 of 210 rows. 

我在前一段的末尾和\pfgplotstabletypeset[行之间有两个硬回车,在行{Table8001a.csv}和下一段之间也有两个硬回车。

结果是: 布局不佳的表格

您可以看到前一段与表格之间缺少垂直空间,并且后一段与表格末尾之间也缺少垂直空间。

我尝试在其周围包裹一个图形环境,这给了我正确的间距。但是,本章(附录)中将有多个表格。当我添加第二个表格时,日志中出现警告,提示图形包装器缺少标题。当我尝试caption{}删除警告时,我得到了编号的图形。

我不需要标题,因为我有节标题可以完成这个工作。附录是表格的附录,因此任何标题都只会重复节标题/节文本中的信息。基本上,我只想要使用

\begin{figure}[htbp]
 ...
\end{figure}

\begin{table}[htbp]
 \begin{tabular}{...}
 ...
\end{tabular}
...
\end{table}

我使用术语“对齐”在手册和本网站(以及 [pfgplotstable] 标签)进行了搜索。我所找到的只是如何在单元格内对齐,而不是在表格周围对齐。

提前致谢。

答案1

表格似乎会很长,而且会与文本混杂在一起。我的建议是将pgfplotstable定义更改为生成代码longtable,以便表格在必要时可以跨越多页。longtable还在每个表格前后添加额外的间距。

下面是一个演示此方法的示例。
笔记,我插入了filecontents环境,它会产生两个额外的文件,使代码自成一体。你不需要这部分,因为在你的例子中,这些文件已经可用

在此处输入图片描述

以下是完整代码

\begin{filecontents*}[overwrite]{main-pgfplotstable-1.csv}
Area,Age.group,Sex,Value
Timaru District,17,Male,330
Timaru District,17,Female,318
Timaru District,18,Male,261
Timaru District,18,Female,177
Timaru District,19,Male,243
Timaru District,19,Female,153
Timaru District,20,Male,243
Timaru District,20,Female,204
Timaru District,Less than one year,Male,264
Timaru District,Less than one year,Female,228
Timaru District,One year,Male,249
Timaru District,One year,Female,225
Timaru District,Two years,Male,267
Timaru District,Two years,Female,237
Timaru District,Three years,Male,294
Timaru District,Three years,Female,249
Timaru District,Four years,Male,288
Timaru District,Four years,Female,237
Timaru District,Five years,Male,273
Timaru District,Five years,Female,261
Timaru District,Six years,Male,267
Timaru District,Six years,Female,255
Timaru District,Less than one year,Male,264
Timaru District,Less than one year,Female,228
Timaru District,One year,Male,249
Timaru District,One year,Female,225
Timaru District,Two years,Male,267
Timaru District,Two years,Female,237
Timaru District,Three years,Male,294
Timaru District,Three years,Female,249
Timaru District,Four years,Male,288
Timaru District,Four years,Female,237
Timaru District,Five years,Male,273
Timaru District,Five years,Female,261
Timaru District,Six years,Male,267
Timaru District,Six years,Female,255
\end{filecontents*}
\begin{filecontents*}[overwrite]{main-pgfplotstable-2.csv}
Area,Sex,Value
Timaru District,Male,330
Timaru District,Female,318
Timaru District,Male,261
Timaru District,Female,177
Timaru District,Male,243
Timaru District,Female,153
Timaru District,Male,243
Timaru District,Female,204
Timaru District,Male,264
Timaru District,Female,228
Timaru District,Male,249
Timaru District,Female,225
Timaru District,Male,267
Timaru District,Female,237
Timaru District,Male,294
Timaru District,Female,249
Timaru District,Male,288
Timaru District,Female,237
Timaru District,Male,273
Timaru District,Female,261
Timaru District,Male,267
Timaru District,Female,255
\end{filecontents*}


%%% DOCUMENT
\documentclass{article}
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{pgfplotstable}
\usepackage{kantlipsum}

\pgfplotstableset{
  mystyle/.style = {
    begin table=\begin{longtable},
    end table=\end{longtable},
    col sep = comma,
    every head row/.style={
      before row=\toprule,
      after row={
        \midrule\endhead
        \bottomrule\endfoot
      },
    },
  }
}


\begin{document}
\section{Appendix}
\label{sec:appendix}
\kant[1]

\subsection{Description of the first table}
\label{sec:first-table}
\kant[2][1]

\pgfplotstabletypeset[
  mystyle,
  columns/Area/.style={string type},
  columns/Age.group/.style={string type},
  columns/Sex/.style={string type},
  columns/Value/.style={string type},
  every head row/.style={
    before row=\toprule,
    after row={
      \midrule\endhead
      \bottomrule
      \multicolumn{4}{r@{}}{\itshape Continues on next page ...}\endfoot
      \bottomrule\endlastfoot
    },
  },
]
{main-pgfplotstable-1.csv}

\kant[2][3]

\subsection{Description of the second table}
\label{sec:second-table}
\kant[2][3]

\pgfplotstabletypeset[
  mystyle,
  columns/Area/.style={string type},
  columns/Sex/.style={string type},
  columns/Value/.style={string type},
]{main-pgfplotstable-2.csv}

\kant[2][4-6]
\end{document}

相关内容