您能帮我修复这个 pgfplot 中的倾斜标题吗?由于某种原因,“k”和“z”标题合并了。谢谢。
这是我的代码:
\documentclass{book}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.12}
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{filecontents}
\begin{filecontents}{dataa.dat}
k z xbar Pkp1 Kkp1
1 12.0000 10.0000 0.2222 0.1111
2 17.7735 15.7735 1.3846 0.6923
3 21.1068 19.1068 0.5306 0.2653
4 23.0313 21.0313 0.9703 0.4851
5 24.1424 22.1424 0.6801 0.3401
6 24.7839 22.7839 0.8474 0.4237
7 25.1543 23.1543 0.7422 0.3711
8 25.3682 23.3682 0.8050 0.4025
\end{filecontents}%
\begin{document}
%%% Code from Dr. Christian ------ for not using headers.----------------------
\pgfkeysifdefined{/pgfplots/table/output empty row/.@cmd}{
% upcoming releases offer this more convenient option:
\pgfplotstableset{
empty header/.style={
every head row/.style={output empty row},
}
}
}{
% versions up to and including 1.5.1 need this:
\pgfplotstableset{
empty header/.style={
typeset cell/.append code={%
\ifnum\pgfplotstablerow=-1 %
\pgfkeyssetvalue{/pgfplots/table/@cell content}{}%
\fi
}
}
}
}
\pgfplotstableset{
begin table=\begin{longtable},
end table=\end{longtable},
}
\pgfplotstableset{
% #1 = row index
% #2 = row style keys
row style/.style 2 args={
every row #1 column 0/.style={#2},
every row #1 column 1/.style={#2},
every row #1 column 2/.style={#2},
every row #1 column 3/.style={#2},
every row #1 column 4/.style={#2},
every row #1 column 5/.style={#2},
every row #1 column 6/.style={#2},
every row #1 column 7/.style={#2},
every row #1 column 8/.style={#2},
every row #1 column 9/.style={#2},
every row #1 column 10/.style={#2},
}
}
\pgfplotstabletypeset[col sep=space,
empty header,
columns/k/.style={dec sep align,fixed zerofill,precision=0},
rows/z/.style={fixed zerofill,precision=5},
%columns={theta1,r2v,r3v,x,y}, % display specified columns
%columns/theta1/.style={precision=6,dec sep align,column name={$\theta_1$}},
%columns/r2v/.style={precision=6,dec sep align,column name={$r_{2v}$}},
%columns/r3v/.style={column type=1,precision=6,dec sep align,column name={$r_{3v}$}},
%columns/x/.style={column type=1,precision=5,dec sep align,column name={$x$}},
%columns/y/.style={column type=1,precision=5,dec sep align,column name={$y$}},
every first row/.append style={before row={%
\caption{This is a Table with Data}%
\label{tab:DataTable}\\\toprule
$k$ & $z$ & $\hat{x}_{k+1}$ & $P_{k+1}$ & $K_{k+1}$ \\ \toprule
\endfirsthead
%
\multicolumn{5}{c}%
{{\bfseries Table \thetable\ Continued from previous page}} \\
\toprule
%
$k$ & $z$ & $\hat{x}_{k+1}$ & $P_{k+1}$ & $K_{k+1}$ \\ \toprule
\endhead
%
\midrule \multicolumn{5}{r}{{Continued on next page}} \\ \bottomrule
\endfoot
%
\midrule
\multicolumn{5}{r}{{End of Table}} \\ \bottomrule
\endlastfoot
}},%
%
]{dataa.dat}
\end{document}
答案1
您需要在定义中添加一个与号:
every first row/.append style={before row={%
\caption{This is a Table with Data}%
\label{tab:DataTable}\\\toprule
& $k$ & $z$ & $\hat{x}_{k+1}$ & $P_{k+1}$ & $K_{k+1}$ %< -- on begging is added `&`
\\ \toprule
\endfirsthead
%
\multicolumn{5}{c}%
{{\bfseries Table \thetable\ Continued from previous page}} \\
\toprule
%
$k$ & $z$ & $\hat{x}_{k+1}$ & $P_{k+1}$ & $K_{k+1}$ \\ \toprule
\endhead
%
\midrule \multicolumn{5}{r}{{Continued on next page}} \\ \bottomrule
\endfoot
%
\midrule
\multicolumn{5}{r}{{End of Table}} \\ \bottomrule
\endlastfoot
}},%
为什么有必要这么做,我仍然不知道。
编辑: Paul Gessler 在他的评论中指出了一件有趣的事情:尽管列号中含有所有必要的 & 符号,但它们的位置却不对。解决奇怪行为的方法是将 & 符号添加到前面k
。