# How to align \vrule partial vertical lines in a pgfplotstable

I had a look at this post on Misaligned multicolumn but it doesn't really solve my problem. I have the code below which is supposed to produce a table with a blue line for the first row and red lines for the other two.

In the table below there should be a single blue line and a single contiguous red line below it, with the numbers all aligned.

Could someone guide me to what I'm doing wrong? I recognize the dire imprecations against vertical lines but in the final output this will present financial information and I thought it would be useful to clearly separate the inflows from the outflows with a colour coded side line.

If anyone can help with the Misplaced \omit error too that would be really helpful

\documentclass{article}
\usepackage{pgfplotstable}

\def\pgfplotstableeach(#1-#2,#3-#4,#5){% columns 1-2 rows 3-4 input 5
\xdef\ACCUM{}%
\foreach \col in {#1,...,#2} {%
\foreach \ro in {#3,...,#4} {%
\toks0=\expandafter{\ACCUM}%
\edef\temp{every row \ro\space column \col/.style}%
\toks1={#5}%
\xdef\ACCUM{\the\toks0 \temp={\the\toks1},}%
}%
}%
\message{setting \meaning\ACCUM^^J}%
\expandafter\pgfplotstableset\expandafter{\ACCUM}%
}

\begin{document}

1 & 2 & 3 & 4\\%
5 & 6 & 7 & 8\\%
9 & 10 & 11 & 12\\%
}\mytable

\pgfplotstableset{
outline/.style={postproc cell content/.style={@cell content=\fbox{##1}}},
vblue/.style={postproc cell content/.style={@cell content=\multicolumn{1}{!{\color{blue}\vrule width 2pt height 1ex}l}{##1}}},
vred/.style= {postproc cell content/.style={@cell content=\multicolumn{1}{!{\color{red} \vrule width 2pt height 2ex}l}{##1}}}
}

\pgfplotstableeach(0-0,1-2,{vred})
\pgfplotstableeach(0-0,0-0,{vblue})

\pgfplotstabletypeset[
debug,
column name={},
every row 2 column 1/.style={outline},
every row 1 column 0/.style={vred},
every row no 0/.style={after row={\rule{0pt}{2em}}}
]\mytable

\end{document}

-

The content is inserted into the cell too late for \multicolumn which must have no non-expandable tokens before it. So something like this:

\documentclass{article}
\usepackage{pgfplotstable}

\def\pgfplotstableeach(#1-#2,#3-#4,#5){% columns 1-2 rows 3-4 input 5
\xdef\ACCUM{}%
\foreach \col in {#1,...,#2} {%
\foreach \ro in {#3,...,#4} {%
\toks0=\expandafter{\ACCUM}%
\edef\temp{every row \ro\space column \col/.style}%
\toks1={#5}%
\xdef\ACCUM{\the\toks0 \temp={\the\toks1},}%
}%
}%
\message{setting \meaning\ACCUM^^J}%
\expandafter\pgfplotstableset\expandafter{\ACCUM}%
}

\begin{document}

1 & 2 & 3 & 4\\%
5 & 6 & 7 & 8\\%
9 & 10 & 11 & 12\\%
}\mytable

\pgfplotstableset{
outline/.style={postproc cell content/.style={@cell content=\fbox{##1}}},
vblue/.style={postproc cell content/.style={@cell content={\color{blue}\vrule width 2pt height 1ex\relax}\,##1}},
vred/.style= {postproc cell content/.style={@cell content={\color{red} \vrule width 2pt height 2ex\relax}\,##1}}
}

\pgfplotstableeach(0-0,1-2,{vred})
\pgfplotstableeach(0-0,0-0,{vblue})

\pgfplotstabletypeset[
debug,
column name={},
every row 2 column 1/.style={outline},
every row 1 column 0/.style={vred},
every row no 0/.style={after row={\rule{0pt}{2em}}}
]\mytable

\end{document}


If you want the lines to run together like this:

Just delete the height component of the rules:

  vblue/.style={postproc cell content/.style={@cell content={\color{blue}\vrule width 2pt\relax}\,##1}},
vred/.style= {postproc cell content/.style={@cell content={\color{red} \vrule width 2pt\relax}\,##1}}

-
That's brilliant @DavidCarlisle thank you. For my education could you explain what the new code is doing? I don't quite understand why it works, especially the last backslash. Thanks. –  Tahnoon Pasha Oct 31 '12 at 21:30
the \, is just a thin space to separate the rule you could replace it by \hspace{1cm} the {\color...} group before that is a coloured rule and ##1 is (apparently) the original cell contents which must go through two levels of macro definition internally hence requiring a doubled #. The main point is that it is too late to change the cell preamble with multicolumn so you need to put the vrule in the cell content and space it "by hand" to separate it from the digits in the cell. –  David Carlisle Oct 31 '12 at 21:34