我正在使用pgfplotstable
将.csv
文件导入 LaTeX。
我成功地使用p{width}
命令在每种列类型中包装了列文本,这也阻止我将列居中并且没有包装标题(标题与下一列标题重叠)。
您能帮我把页眉和文本换行并使其居中吗?
以下是部分代码:
\renewcommand{\arraystretch}{1.5}
\afterpage{
\pgfplotstableset{
begin table=\begin{longtable},
end table=\end{longtable},
%outfile={testtable.tex} % to check the resulting table code
}
\pgfplotstabletypeset[
col sep=comma,
string type,
columns/No/.style={column name=No, column type={p{.05\textwidth}}},
columns/Abbreviation/.style={column name={Abbreviation}, column type={p{.05\textwidth}}},
columns/Trait/.style={column name={Trait}, column type={p{.2\textwidth}}},
columns/Unit/.style={column name={Unit}, column type={p{.2\textwidth}}},
columns/Trait description/.style={column name={Trait description}, column type={p{.4\textwidth}}},
every head row/.style={before row=\hline, after row=\hline},
every last row/.style={after row=\hline},
every head row/.append style={before row={% <==================
\caption{List of the data to be collected from different traits, their abbreviation, units and description}\label{datalist}\\[0.5cm]
\hline
\endfirsthead
\multicolumn{5}{c}{{\bfseries \tablename\ \thetable{} -- continued from previous page}} \\
\hline
\multicolumn{1}{p{.05\textwidth}}{\textbf{No}} & \multicolumn{1}{p{.05\textwidth}}{\textbf{Abbreviation}} & \multicolumn{1}{p{.2\textwidth}} {\textbf{Trait}} & \multicolumn{1}{p{.2\textwidth}}{\textbf{Unit}} & \multicolumn{1}{p{.4\textwidth}}{\textbf{Trait description}} \\
\hline
\endhead
\hline
\multicolumn{5}{r}{{Continued on next page}} \\ %\bottomrule
\endfoot % <============================================================
\endlastfoot % <========================================================
}
}
]{Datalist.csv}
}
在此代码中,标题“缩写”和“特征”重叠,而不是包装标题“缩写”。
答案1
问题并不重要pgfplotstable
,只是“缩写”比 长.05\textwidth
,您应该修改列的宽度(正如我在下面的代码中所做的那样)或/和更改表格的字体大小或写“缩写。”而不是“缩写”(以便有一个带有
Abbre-
viation
对我来说似乎不太漂亮)。另请参阅此处:我的桌子放不下;我有什么办法吗?
由于您没有发布完整的 MWE,并且我们不知道您的实际数据,因此我们无法说出哪种解决方案更好。
至于使列居中,我C
使用array
包创建了一个新的列类型,该包以列宽作为参数。
\documentclass[12pt,a4paper]{report}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.15}% current version
%\usepackage{showframe}% for testing purpose only
\usepackage{afterpage}
\usepackage{array}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
\usepackage{longtable}
\usepackage{booktabs}
\usepackage{caption}
\captionsetup{labelfont=bf, textfont=bf, labelsep=endash,
justification=centering}
\usepackage{filecontents}
\begin{filecontents*}{Datalist.csv}
No,Abbreviation,Trait,Unit,Trait description
1,$U_{g}$,Good users,\TeX\ Stack Exchange,They always add a complete MWE (these definition are taken from the first DuckBoat - Herr Professor Paulinho van Duck's article)
2,$U_{b}$,Bad users,\TeX\ Stack Exchange,They do not add a complete MWE
2a,$U_{k}$,Uninformed users,\TeX\ Stack Exchange,They do not know what an MWE is
2b,$U_{h}$,Disoriented users,\TeX\ Stack Exchange,They vaguely know what an MWE is but do not know how to create it in a correct way
2c,$U_{l}$,Free riders,\TeX\ Stack Exchange,They do know what an MWE and how to create it but are too lazy to add it
1,$U_{g}$,Good users,\TeX\ Stack Exchange,They always add a complete MWE (these definition are taken from the first DuckBoat - Herr Professor Paulinho van Duck's article)
2,$U_{b}$,Bad users,\TeX\ Stack Exchange,They do not add a complete MWE
2a,$U_{k}$,Uninformed users,\TeX\ Stack Exchange,They do not know what an MWE is
2b,$U_{h}$,Disoriented users,\TeX\ Stack Exchange,They vaguely know what an MWE is but do not know how to create it in a correct way
2c,$U_{l}$,Free riders,\TeX\ Stack Exchange,They do know what an MWE and how to create it but are too lazy to add it
\end{filecontents*}
\begin{document}
\renewcommand{\arraystretch}{1.5}
\afterpage{
\pgfplotstableset{
begin table=\begin{longtable},
end table=\end{longtable},
%outfile={testtable.tex} % to check the resulting table code
}
\pgfplotstabletypeset[
col sep=comma,
string type,
columns/No/.style={column name=\textbf{No},
column type={C{.05\textwidth}}},
columns/Abbreviation/.style={column name={\textbf{Abbreviation}},
column type={C{.2\textwidth}}},
columns/Trait/.style={column name={\textbf{Trait}},
column type={C{.16\textwidth}}},
columns/Unit/.style={column name={\textbf{Unit}},
column type={C{.15\textwidth}}},
columns/Trait description/.style={
column name={\textbf{Trait description}},
column type={C{.28\textwidth}}},
every head row/.style={before row=\hline, after row=\hline},
every last row/.style={after row=\hline},
every head row/.append style={before row={% <==================
\caption{List of the data to be collected from different traits, their abbreviation, units and description}\label{datalist}\\[0.5cm]
\hline
\endfirsthead
\multicolumn{5}{c}{{\bfseries \tablename\ \thetable{} -- continued from previous page}}\\[7pt]
\hline
\multicolumn{1}{C{.05\textwidth}}{\textbf{No}} & \multicolumn{1}{C{.2\textwidth}}{\textbf{Abbreviation}} & \multicolumn{1}{C{.16\textwidth}}{\textbf{Trait}} & \multicolumn{1}{C{.15\textwidth}}{\textbf{Unit}} & \multicolumn{1}{C{.28\textwidth}}{\textbf{Trait description}} \\
\hline
\endhead
\hline
\multicolumn{5}{r}{{Continued on next page}} \\ %\bottomrule
\endfoot % <============================================================
\endlastfoot % <========================================================
}
}
]{Datalist.csv}
}
\end{document}