调整 pgfplot 表

调整 pgfplot 表

使用\pgfplotstabletypeset宏,我已使用 create col 命令和\edef宏成功创建了一个新的组合列,其中包含来自 3 列的文本。我不了解这些命令的全部范围和机会,因为我是从这些论坛的其他地方学到的。那么我如何调整表格以提供以下内容:

  1. 在表格中的组合列中添加换行符,以便将从源表列“出版物”收集的文本放在其新的组合单元格内的新行上(我已插入\allowbreak\edef但没有帮助)
  2. 更改组合列中单行的行距(例如,包含来自源“出版物”的数据的行)
  3. 定义一个文本字符串,该字符串每次出现在表格中时都应以粗体显示,例如“Strand TE”
  4. 仅选择 Cat 列中具有给定字符串的列将其包含在最终表中,例如 Cat =“A”

最终文本将从 .csv 文件导入,因此我需要使用\pgfplotstabletypeset

代码在这里:

\documentclass{report} 
\usepackage{pgfplotstable}
\usepackage{array}
\usepackage{longtable}
\usepackage{filecontents}
\pgfplotsset{compat=1.15}  

\newcolumntype{C}{>{\arraybackslash}m{1.5 cm}}    
\newcolumntype{D}{>{\arraybackslash}m{14 cm}}

\begin{filecontents*}{data.txt}
    Cat, Author, Publication, Forum
    A, Ashraf H; Strand TE; Friesland S; Koyi H, Implementation of Lung Cancer CT Screening in the Nordic Countries., Acta Oncol. 2017:56:1249-57. doi: 10.1080/0284186X.2017.1329592
    B, Strand TE; Zare HK; Boico A; Radiloff D; Zhao Y; Irwin D, The novel combination of theophylline and bambuterol as a potential treatment of hypoxemia in humans., Can J Physiol Pharmacol. 2017 May 3. doi: 10.1139/cjpp-2016-0635.
    B, Chahal-Kummen M; Strand TE; Owe JO; Gulliksen E; Wagstaff AS., Aeromedical Evaluation for an F-16 Candidate with Incomplete Paraplegia, Aerospace Medicine and Human Performance Vol. 87 No. 11 November 2016
    A, Amini M; Hisdal J; Gjovaag T; Kapetanovic N; Strand TE; Owe JO; Horthe JR; Mirtaheri P., Near Infrared spectra in buccal tissue as a marker for detection of hypoxia, Aerosp Med Hum Perform. 2016:87:498-504
\end{filecontents*}
\begin{document}

\pgfplotstabletypeset[
    begin table=\begin{longtable},
    col sep=comma,
    header=has colnames,
    create on use/Combined/.style={
        create col/assign/.code={
            \edef\entry{
                \thisrow{Author}, \thisrow{Publication}, \allowbreak  \thisrow{Forum}
                    }
            \pgfkeyslet{/pgfplots/table/create col/next content}{\entry} 
        }
    },
    columns={Cat, Combined},
    columns/Kat/.style={column name=Category, column type=C},
    columns/Combined/.style={column name=Combined column, column type=D},  
    string type,
    end table=\end{longtable}
    ]{data.txt}

\end{document}

答案1

这实现了所有规范;我已将 14 厘米改为 8 厘米以适合页面,并用作tabularx内部表格以获取所需的换行符。过滤器已设置,B但可以在行谓词中更改。

\documentclass[]{report}
\usepackage{pgfplotstable}
\usepackage{array}
\usepackage{longtable}
\usepackage{filecontents}
\usepackage{tabularx}
\pgfplotsset{compat=1.16}

\newcolumntype{C}{>{\arraybackslash}m{1.5 cm}}    
\newcolumntype{D}{>{\arraybackslash}m{10 cm}}

\begin{filecontents*}{data.txt}
Cat, Author, Publication, Forum
A, Ashraf H; Strand TE; Friesland S; Koyi H, Implementation of Lung Cancer CT Screening in the Nordic Countries., Acta Oncol. 2017:56:1249-57. doi: 10.1080/0284186X.2017.1329592
B, Strand TE; Zare HK; Boico A; Radiloff D; Zhao Y; Irwin D, The novel combination of theophylline and bambuterol as a potential treatment of hypoxemia in humans., Can J Physiol Pharmacol. 2017 May 3. doi: 10.1139/cjpp-2016-0635.
B, Chahal-Kummen M; Strand TE; Owe JO; Gulliksen E; Wagstaff AS., Aeromedical Evaluation for an F-16 Candidate with Incomplete Paraplegia, Aerospace Medicine and Human Performance Vol. 87 No. 11 November 2016
A, Amini M; Hisdal J; Gjovaag T; Kapetanovic N; Strand TE; Owe JO; Horthe JR; Mirtaheri P., Near Infrared spectra in buccal tissue as a marker for detection of hypoxia, Aerosp Med Hum Perform. 2016:87:498-504
\end{filecontents*}

\pgfplotstableread[
  col sep=comma,
  header=has colnames,
]{data.txt}\mytable

\begin{document}

\pgfplotstabletypeset[
  create on use/Combined/.style={
    create col/assign/.code={%
      \edef\entry{\noexpand\begin{tabularx}{10cm}{@{}X@{}}\thisrow{Author}\noexpand\\[5mm]
                  \thisrow{Publication}, \thisrow{Forum}\noexpand\end{tabularx}}%
      \pgfkeyslet{/pgfplots/table/create col/next content}{\entry}%
    }
  },
  begin table=\begin{longtable},
  end table=\end{longtable},
  columns={Cat, Combined},
  columns/Cat/.style={column name=Category, column type=C},
  columns/Combined/.style={column name=Combined column, column type=D,
                           string replace*={Strand TE}{\textbf{Strand TE}}},
  string type,
  row predicate/.code={\pgfplotstablegetelem{#1}{Cat}\of\mytable%
                       \expandafter\if\pgfplotsretval B\else\pgfplotstableuserowfalse\fi}
]{\mytable}

\end{document}

在此处输入图片描述

相关内容