我看了这篇文章多列未对齐但它并没有真正解决我的问题。我有下面的代码,它应该生成一个表格,第一行是蓝线,其他两行是红线。
下表中应有一条蓝线和一条连续的红线,且所有数字均对齐。
有人能告诉我我做错了什么吗?我认识到垂直线的严重缺陷,但在最终输出中,这将呈现财务信息,我认为用颜色编码的边线清楚地将流入与流出区分开会很有用。
如果有人能帮助解决Misplaced \omit
错误,那将非常有帮助
\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}
\pgfplotstableread[row sep=\\,col sep=&,header=false]{%
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}
答案1
内容插入单元格太晚,因为\multicolumn
内容之前必须没有不可扩展的标记。因此,如下所示:
\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}
\pgfplotstableread[row sep=\\,col sep=&,header=false]{%
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}
如果您希望这些行像这样连在一起:
只需删除规则的高度部分:
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}}