我试图让表格的效果显示“下页继续”和“结束”,就像这样这里。
我正在调用longtable
保存在 data.dat 文件中的内容(如下所示)。您能帮我将表格的最后一行改为这样的格式吗:
这是我的代码:
\documentclass{article}
\usepackage{pgfplotstable}
\usepackage{booktabs}
\usepackage{longtable}
\begin{document}
\pgfplotstableset{
begin table=\begin{longtable},
end table=\end{longtable},
}
\pgfplotstabletypeset[col sep=space,
header=true,
columns={theta1,r2v,r3v,x,y}, % display specified columns
columns/theta1/.style={fixed,fixed zerofill,precision=0,column type=r,column name={$\theta_1$}},
columns/r2v/.style={column type=l,precision=6,dec sep align,column name={$r_{2v}$}},
columns/r3v/.style={fixed,fixed zerofill,precision=1,column type=r,column name={$r_{3v}$}},
columns/x/.style={column type=l,precision=5,dec sep align,column name={$x$}},
columns/y/.style={column type=l,precision=5,dec sep align,column name={$y$}},
% requires booktabs to place horiz rules
every head row/.style={before row=\toprule, after row=\midrule\endhead},
every last row/.style={after row=
\multicolumn{2}{c}%
{{\bfseries Table \thetable\ Continued from previous page}} \\
\toprule
%
\midrule \multicolumn{2}{r}{{Continued on next page}} \\ \bottomrule
\endfoot
%
\midrule
\multicolumn{2}{r}{{Concluded}} \\ \bottomrule
\endlastfoot
}%
%
]{data.dat}
\end{document}
这是 data.dat 文件:
theta1 r2v r3v x y
73.32513 0.08109 0.32216 1.07136 1.58646
81.52127 0.39714 0.18930 1.12726 1.54498
11.42881 0.15561 0.40579 2.00083 -0.25418
82.20383 0.26427 0.26641 0.98759 1.65272
56.91233 0.08282 0.17536 1.39728 1.09515
8.77864 0.30099 0.46950 2.07209 -0.48038
25.06484 0.13149 0.43797 2.02329 0.26017
49.21934 0.32704 0.27508 1.78136 0.81424
86.17562 0.34461 0.31124 0.95389 1.75653
86.83997 0.37408 0.29352 0.96191 1.74816
14.18518 0.22527 0.10387 1.73510 -0.29920
87.35335 0.04191 0.15062 0.60779 1.62930
86.14503 0.11449 0.23546 0.72013 1.69588
43.68381 0.45667 0.11524 1.82554 0.43447
72.02524 0.07619 0.42215 1.13327 1.65837
12.76977 0.41291 0.09738 1.76232 -0.52640
37.95852 0.26917 0.11296 1.74265 0.39662
82.41620 0.49807 0.08535 1.18931 1.44604
71.29866 0.03909 0.11383 1.02021 1.36372
86.35432 0.22134 0.21785 0.81945 1.67413
59.01666 0.05333 0.15555 1.32064 1.14392
3.21405 0.48095 0.46169 2.01803 -0.85916
76.42164 0.00232 0.21510 0.88239 1.55644
84.05939 0.38746 0.09241 1.03807 1.49802
61.08616 0.40865 0.45244 1.73304 1.27895
68.19661 0.43435 0.48987 1.59916 1.50884
66.88192 0.04222 0.21943 1.16654 1.37700
35.30043 0.19989 0.05556 1.67229 0.33875
58.99301 0.12994 0.12903 1.37311 1.08118
15.40680 0.40003 0.20436 1.88439 -0.40392
63.54415 0.21571 0.29745 1.43481 1.29929
2.86496 0.45532 0.13111 1.68131 -0.86237
24.92307 0.09092 0.30142 1.88300 0.23440
4.15543 0.13190 0.35561 1.90078 -0.48544
8.74186 0.07277 0.11087 1.68263 -0.31065
74.11120 0.06803 0.05871 0.96481 1.35119
62.53458 0.43465 0.14834 1.58297 1.04053
28.53895 0.28985 0.15939 1.83473 0.11008
85.51998 0.27493 0.21208 0.89672 1.65209
3.10015 0.07248 0.25393 1.78677 -0.46653
39.48699 0.42652 0.04276 1.77733 0.27689
34.34026 0.31103 0.13124 1.80291 0.26160
68.89651 0.17548 0.40051 1.30693 1.53810
71.56799 0.25662 0.01461 1.18879 1.20559
16.81853 0.20090 0.46443 2.08509 -0.09151
44.07880 0.03798 0.36517 1.71079 0.92168
答案1
longtable
我修改了您给出的代码,以解决中的表头和表尾问题pgfplotstable
。我删除了列的样式,作为家庭作业交给您(请阅读 的文档pgfplotstable
!)。
要删除第一行(稍后查看结果),您可以添加empty header
。请按照这个问题。
完整的 MWE(包括.dat
带包的文件filecontents
;看到我在行后添加了一些数据0.0 0.0 0.0 0.0
;用 标记了更改% <======
):
\RequirePackage{filecontents}
\begin{filecontents*}{\jobname.dat}
theta1 r2v r3v x y
73.32513 0.08109 0.32216 1.07136 1.58646
81.52127 0.39714 0.18930 1.12726 1.54498
11.42881 0.15561 0.40579 2.00083 -0.25418
82.20383 0.26427 0.26641 0.98759 1.65272
56.91233 0.08282 0.17536 1.39728 1.09515
8.77864 0.30099 0.46950 2.07209 -0.48038
25.06484 0.13149 0.43797 2.02329 0.26017
49.21934 0.32704 0.27508 1.78136 0.81424
86.17562 0.34461 0.31124 0.95389 1.75653
86.83997 0.37408 0.29352 0.96191 1.74816
14.18518 0.22527 0.10387 1.73510 -0.29920
87.35335 0.04191 0.15062 0.60779 1.62930
86.14503 0.11449 0.23546 0.72013 1.69588
43.68381 0.45667 0.11524 1.82554 0.43447
72.02524 0.07619 0.42215 1.13327 1.65837
12.76977 0.41291 0.09738 1.76232 -0.52640
37.95852 0.26917 0.11296 1.74265 0.39662
82.41620 0.49807 0.08535 1.18931 1.44604
71.29866 0.03909 0.11383 1.02021 1.36372
86.35432 0.22134 0.21785 0.81945 1.67413
59.01666 0.05333 0.15555 1.32064 1.14392
3.21405 0.48095 0.46169 2.01803 -0.85916
76.42164 0.00232 0.21510 0.88239 1.55644
84.05939 0.38746 0.09241 1.03807 1.49802
61.08616 0.40865 0.45244 1.73304 1.27895
68.19661 0.43435 0.48987 1.59916 1.50884
66.88192 0.04222 0.21943 1.16654 1.37700
35.30043 0.19989 0.05556 1.67229 0.33875
58.99301 0.12994 0.12903 1.37311 1.08118
15.40680 0.40003 0.20436 1.88439 -0.40392
63.54415 0.21571 0.29745 1.43481 1.29929
2.86496 0.45532 0.13111 1.68131 -0.86237
24.92307 0.09092 0.30142 1.88300 0.23440
4.15543 0.13190 0.35561 1.90078 -0.48544
8.74186 0.07277 0.11087 1.68263 -0.31065
74.11120 0.06803 0.05871 0.96481 1.35119
62.53458 0.43465 0.14834 1.58297 1.04053
28.53895 0.28985 0.15939 1.83473 0.11008
85.51998 0.27493 0.21208 0.89672 1.65209
3.10015 0.07248 0.25393 1.78677 -0.46653
39.48699 0.42652 0.04276 1.77733 0.27689
34.34026 0.31103 0.13124 1.80291 0.26160
68.89651 0.17548 0.40051 1.30693 1.53810
71.56799 0.25662 0.01461 1.18879 1.20559
16.81853 0.20090 0.46443 2.08509 -0.09151
44.07880 0.03798 0.36517 1.71079 0.92168
0.0 0.0 0.0 0.0 0.0
76.42164 0.00232 0.21510 0.88239 1.55644
84.05939 0.38746 0.09241 1.03807 1.49802
61.08616 0.40865 0.45244 1.73304 1.27895
68.19661 0.43435 0.48987 1.59916 1.50884
66.88192 0.04222 0.21943 1.16654 1.37700
35.30043 0.19989 0.05556 1.67229 0.33875
58.99301 0.12994 0.12903 1.37311 1.08118
15.40680 0.40003 0.20436 1.88439 -0.40392
63.54415 0.21571 0.29745 1.43481 1.29929
2.86496 0.45532 0.13111 1.68131 -0.86237
24.92307 0.09092 0.30142 1.88300 0.23440
4.15543 0.13190 0.35561 1.90078 -0.48544
8.74186 0.07277 0.11087 1.68263 -0.31065
74.11120 0.06803 0.05871 0.96481 1.35119
62.53458 0.43465 0.14834 1.58297 1.04053
28.53895 0.28985 0.15939 1.83473 0.11008
85.51998 0.27493 0.21208 0.89672 1.65209
3.10015 0.07248 0.25393 1.78677 -0.46653
39.48699 0.42652 0.04276 1.77733 0.27689
34.34026 0.31103 0.13124 1.80291 0.26160
68.89651 0.17548 0.40051 1.30693 1.53810
71.56799 0.25662 0.01461 1.18879 1.20559
16.81853 0.20090 0.46443 2.08509 -0.09151
44.07880 0.03798 0.36517 1.71079 0.92168
\end{filecontents*}
\documentclass[12pt]{article}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.12} % <===========================================
\usepackage{booktabs}
\usepackage{longtable}
\begin{document}
\pgfplotstableset{
begin table=\begin{longtable},
end table=\end{longtable},
}
\pgfplotstabletypeset[%
col sep=space,
%columns={theta1,r2v,r3v,x,y}, % display specified columns
%columns/theta1/.style={fixed,fixed zerofill,precision=0,column type=r,
%columns/r2v/.style={column type=l,precision=6,dec sep align,
%columns/r3v/.style={fixed,fixed zerofill,precision=1,column type=r,
%columns/x/.style={column type=l,precision=5,dec sep align,
%columns/y/.style={column type=l,precision=5,dec sep align,
% requires booktabs to place horiz rules
every first row/.style={before row={% <=================================
\caption{This is a Table with Data}%
\label{tab:DataTable}\\
\toprule
\textbf{theta1} & \textbf{r2v} & \textbf{r3v} & \textbf{x} & \textbf{y} \\
\toprule
\endfirsthead % <=======================================================
\multicolumn{5}{c}{{\bfseries Table \thetable\ Continued from previous page}} \\
\toprule
\textbf{theta1} & \textbf{r2v} & \textbf{r3v} & \textbf{x} & \textbf{y} \\
\midrule
\endhead % <============================================================
\midrule \multicolumn{5}{r}{{Continued on next page}} \\ \bottomrule
\endfoot % <============================================================
\midrule
\multicolumn{5}{r}{{End of table}} \\ \bottomrule
\endlastfoot % <========================================================
}}%
]{\jobname.dat}
\end{document}
结果(第一页):
第二页:
对我的第一个代码进行一些修改,你就可以得到你在评论中要求的对齐方式。为什么我必须使用&&
而不是,&
我说不上来。我想这需要对代码进行更深入的研究,了解标题是如何构建的。也许可以向软件包维护者提问...
在下面的 MWE 中,我省略了filecontents
部分(请从第一个代码中复制它)并查看标记的变化:
\documentclass[12pt]{article}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.12} % <===========================================
\usepackage{booktabs}
\usepackage{array} % <==================================================
\usepackage{longtable}
\begin{document}
\pgfplotstableset{
begin table=\begin{longtable},
end table=\end{longtable},
%outfile={testtable.tex} % to check the resulting table code
}
\pgfplotstabletypeset[%
header=has colnames, % true|false|has colnames
col sep=space,
columns={theta1,r2v,r3v,x,y}, % display specified columns
columns/theta1/.style={fixed,fixed zerofill,precision=0,column type=r,column name={$\theta_1$}},
columns/r2v/.style={column type=l,precision=6,dec sep align,column name={$r_{2v}$}},
columns/r3v/.style={fixed,fixed zerofill,precision=1,column type=r,column name={$r_{3v}$}},
columns/x/.style={column type=l,precision=5,dec sep align,column name={$x$}},
columns/y/.style={column type=l,precision=5,dec sep align,column name={$y$}},
% requires booktabs to place horiz rules
every head row/.style={output empty row}, % <===========================
every head row/.append style={before row={% <===========================
\caption{The caption}\label{tab:DataTable}\\%
\toprule
\multicolumn{1}{c}{\textbf{theta1}} && \multicolumn{1}{c}{\textbf{r2v}} && \multicolumn{1}{c}{\textbf{r3v}} & \multicolumn{1}{c}{\textbf{x}} && \multicolumn{1}{c}{\textbf{y}} \\
\midrule
\endfirsthead
\multicolumn{5}{c}{{\bfseries \tablename\ \thetable{} -- continued from previous page}} \\
\toprule
\multicolumn{1}{c}{\textbf{theta1}} && \multicolumn{1}{c}{\textbf{r2v}} && \multicolumn{1}{c}{\textbf{r3v}} & \multicolumn{1}{c}{\textbf{x}} && \multicolumn{1}{c}{\textbf{y}} \\
\midrule
\endhead
\midrule \multicolumn{5}{r}{{Continued on next page}} \\ \bottomrule
\endfoot % <============================================================
\midrule
\multicolumn{5}{r}{{End of table}} \\ \bottomrule
\endlastfoot % <========================================================
},
}%
]{\jobname.dat}
\end{document}
得到结果页面 1:
第 2 页: