Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm trying to indent some of the words in the first column of a table using PGFplotstable. I can't figure out any other way to do this other than to put 4 spaces in front of the word. Unfortunately, pgfplotstable or latex is stripping away the spaces so the words aren't indented. In the MWE below, see that "cat c" and "cat f" are meant to be indented, but once rendered they are left-aligned.

I found the option trim cells=true|false, but turning it off had no effect.

\documentclass{article}

\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{filecontents}

\begin{document}

\begin{filecontents}{testdata.csv}
category, value, value 2
cat a,    1,     7
cat b,    2,     6
    cat c,    3,     5
cat d,    4,     4
cat e,    5,     3
    cat f,    6,     2
cat g,    7,     1
\end{filecontents}

\pgfplotstableread[col sep=comma]{testdata.csv}\datatable
\pgfplotstabletypeset[
trim cells=false,
col sep=comma,
columns/category/.style={string type,column type=l}
]{\datatable}

\end{document}
share|improve this question
    
Put \quad in front of cat c (or any other spacing commands \ ,\;,\qquad etc.) –  percusse Jul 31 '12 at 22:28
    
@percusse Hmm.. I can do that if creating the table inline like in the MWE... but I'm actually importing the real data from an external .CSV, so that's not really possible. –  Trevor Aug 1 '12 at 0:38
    
Then how do you put four whitespaces in the real data? –  percusse Aug 1 '12 at 8:44
    
Do you want to indent every 3rd row by any chance? –  percusse Aug 1 '12 at 10:42
    
Good question about the four white spaces... I was putting them in the csv, but I guess that's just as ugly as putting \quad in the csv.... And yes, indenting every third row could work, but selecting specific rows would be preferred. –  Trevor Aug 1 '12 at 14:26

1 Answer 1

up vote 2 down vote accepted

You can use the style every row no <index> to set before row=\quad for the desired rows.

If you need to change a large number of rows in the same fashion, you can supply the row numbers as a comma separated list if you first call

\pgfplotstableset{
    every row no list/.code 2 args={
        \pgfplotsforeachungrouped \rownumber in {#1}     {
            \pgfplotsset{/pgfplots/table/every row no \rownumber/.append style={#2}}
        }
    }
}

to define a new key every row no list.

\documentclass{article}

\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{filecontents}

\begin{document}

\begin{filecontents}{testdata.csv}
category, value, value 2
cat a,    1,     7
cat b,    2,     6
cat c,    3,     5
cat d,    4,     4
cat e,    5,     3
cat f,    6,     2
cat g,    7,     1
\end{filecontents}

\pgfplotstableset{
    every row no list/.code 2 args={
        \pgfplotsforeachungrouped \rownumber in {#1}     {
            \pgfplotsset{/pgfplots/table/every row no \rownumber/.append style={#2}}
        }
    }
}

\pgfplotstableread[col sep=comma]{testdata.csv}\datatable
\pgfplotstabletypeset[
    trim cells=false,
    col sep=comma,
    columns/category/.style={string type,column type=l},
    every row no list={2,5}{before row=\quad}
]{\datatable}


\end{document}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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