6

With \pgfplotstabletypeset and macro I have successfully made a new combined column including text from 3 columns with the create col command and \edef macro. I do not understand the full extent and opportunities of these commands as I have picked them up from other places on these forums. How can I then tweak the table to give me the following:

  1. Add linebreaks in the combined column in the table so that text collected from sourcetable column “Publication” is placed on a new line within its new combined cell (I have inserted \allowbreak in the \edef macro but doesn’t help)
  2. Change line spacing for a single line in the combined column (in example the line with data from source "Publication")
  3. Define a string of text which should be in bold in the table every time it appears, in example “Strand TE”
  4. Select only columns with a given string in column Cat to be included in final table, in example Cat = “A”

The final text will be imported from .csv file therefore I need to use \pgfplotstabletypeset

Code here:

\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}
  • Welcome to TeX.SX! – egreg Jan 4 '18 at 17:29
2

This implement all specifications; I've changed the 14cm to 8cm to fit to the page and also used tabularx as an inner tabular to get the required linebreaks. The filter is set for B but can be changed in the row predicate.

\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}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.