3

Is there a way to merge cells in a specific row in a table using pgfplotstable?

I would like to merge all cells is the last and second last row, so that the text spans trough all the width of the table. I figured out how to do this with the head rows, although can't find anything about merging specific rows other than head.

CSV file content:

;coefficient;(SE);coefficient;(SE);coefficient;(SE);coefficient;(SE);coefficient;(SE)
Data ;;;;;;;;;;
Data 1;2.030;(.081);2.020;(.081);2.032;(.082);2.017;(.081);2.020;(.081)
Data 2;.117;(.212);.110;(.212);.110;(.212);.084;(.217);.110;(.212)
Data 3;2.002;(.020);2.004;(.020);2.004;(.020);2.004;(.020);2.003;(.020)
Note: All models include individual-level control variables: age, age-squared, gender, ethnicity, living together, having children, length of residence, employment status, highest educational level attained, highest education father.;;;;;;;;;;
*p , 0.05, **p , 0.01, ***p , 0.001;;;;;;;;;;

The code so far:

\documentclass{article}
    \usepackage{booktabs}
    \usepackage{pgfplotstable}
    \usepackage{pdflscape}    
\begin{document}
    \begin{landscape}
    \begin{table}[h!]
      \begin{center}
        \caption{Table title}
        \label{Table4}
    \pgfplotstabletypeset[
    multicolumn names,
        col sep=semicolon, 
        header=false,
        string type,
        every head row/.style={after row={\toprule & \multicolumn{2}{c}{model 1 }& \multicolumn{2}{c}{model 2} & \multicolumn{2}{c}{model 3} & \multicolumn{2}{c}{model 4} & \multicolumn{2}{c}{model 5}\\}},
        every first row/.style={after row=\midrule},
        every last row/.style={after row=\bottomrule},
        display columns/0/.style={column name=, column type = {p{.4\textwidth}}},
        display columns/1/.style={column name=},
        display columns/2/.style={column name=},
        display columns/3/.style={column name=},
        display columns/4/.style={column name=},
        display columns/5/.style={column name=},
        display columns/6/.style={column name=},
        display columns/7/.style={column name=},
        display columns/8/.style={column name=},
        display columns/9/.style={column name=},
        display columns/10/.style={column name=},
        ]{tabela4.csv}
     \end{center}
    \end{table}
    \end{landscape}
    \end{document}
3
  • \pgfplotstablerows contains the number of rows, may be you can use it to do an special treatment to every last row and \pgfplotstablerows-1. I've no idea about how to do it.
    – Ignasi
    Commented Aug 6, 2016 at 12:16
  • I am not sure if I understand @JohnKormylo...
    – emes
    Commented Aug 6, 2016 at 13:10
  • @JohnKormylo - Still not sure what would be the target of this - to remove the row(s) with cells and place a new one? Would the new row have one cell only, and will it be able to get the content from the CSV file? I am a LaTeX newbie...
    – emes
    Commented Aug 6, 2016 at 17:50

1 Answer 1

1

I extracted the note from the last two rows and displayed it outside the \pgfplotstabletypeset itself.

I separated the reading and typesetting steps to experiment with actually removing the last two rows, but it turned out the [skip rows between index=] did the trick.

\documentclass{article}
    \usepackage{booktabs}
    \usepackage{pgfplotstable}
    \usepackage{pdflscape}  

    \newcounter{row}
    \newcommand{\note}{}% reserve global name
\begin{document}
    \begin{landscape}% automatic \clearpage
    \begin{table}[p]% vertically centers table in page
    \begin{center}% easier to turn off than \centering
        \caption{Table title}
        \label{Table4}
    \pgfplotstableread[% read in data
        col sep=semicolon, 
        header=false,
        string type]{temp.dat}\tableA
    % extract note from last two rows
    \pgfplotstablegetrowsof\tableA
    \setcounter{row}{\pgfplotsretval}%
    \addtocounter{row}{-2}% starts at row 0
    \edef\skiprow{\therow}% will be used later
    \pgfplotstablegetelem{\therow}{0}\of\tableA
    \let\note=\pgfplotsretval
    \stepcounter{row}%
    \pgfplotstablegetelem{\therow}{0}\of\tableA
    \xdef\note{\note{} \pgfplotsretval}%
    %
    \pgfplotstabletypeset[string type,multicolumn names,skip rows between index={\skiprow}{\pgfplotstablerows},
        every head row/.style={after row={\toprule & \multicolumn{2}{c}{model 1 }& \multicolumn{2}{c}{model 2} & \multicolumn{2}{c}{model 3} & \multicolumn{2}{c}{model 4} & \multicolumn{2}{c}{model 5}\\}},
        every first row/.style={after row=\midrule},
        every last row/.style={after row=\bottomrule},
        display columns/0/.style={column name=, column type = {l}},
        display columns/1/.style={column name=},
        display columns/2/.style={column name=},
        display columns/3/.style={column name=},
        display columns/4/.style={column name=},
        display columns/5/.style={column name=},
        display columns/6/.style={column name=},
        display columns/7/.style={column name=},
        display columns/8/.style={column name=},
        display columns/9/.style={column name=},
        display columns/10/.style={column name=},
        ]\tableA
    \end{center}
    \note
    \end{table}
    \end{landscape}% automatic \clearpage
    \end{document}

demo

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .