当使用 \DTLdisplaylongdb 显示数据工具数据库时 - 如何获取表头顶部的水平规则?

当使用 \DTLdisplaylongdb 显示数据工具数据库时 - 如何获取表头顶部的水平规则?

当显示数据工具数据库时\DTLdisplaylongdb- 如何获取表头顶部的水平规则?

无论我如何尝试,都会出现有关 ! 放错 \noalign 的错误消息。

(除此之外我想知道该Underfull \vbox (badness 10000)消息的原因。

\documentclass{article}
\usepackage{datatool,longtable}

%===============================================================
\DTLnewdb{MyDataBase}%
\DTLaddcolumn{MyDataBase}{columnA}%
\DTLsetheader{MyDataBase}{columnA}{First Column}%
\DTLaddcolumn{MyDataBase}{columnB}%
\DTLsetheader{MyDataBase}{columnB}{Second Column}%
%---------------------------------------------------------------
\DTLnewrow{MyDataBase}
\DTLnewdbentry{MyDataBase}{columnA}{Row 1 Col A}
\DTLnewdbentry{MyDataBase}{columnB}{Row 1 Col B}
%---------------------------------------------------------------
\DTLnewrow{MyDataBase}
\DTLnewdbentry{MyDataBase}{columnA}{Row 2 Col A}
\DTLnewdbentry{MyDataBase}{columnB}{Row 2 Col B}
%===============================================================

\begin{document}

\begingroup
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%This doesn't work out but yields  ! Misplaced \noalign.
%\renewcommand{\dtldisplaystarttab}{\hline}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\renewcommand\dtldisplayafterhead{\hline}%
\renewcommand\dtldisplaystartrow{\hline}%
\renewcommand{\dtldisplayendtab}{\tabularnewline\hline}%
\renewcommand{\dtlbeforecols}{|}%
\renewcommand{\dtlaftercols}{|}%
\renewcommand{\dtlbetweencols}{|}%
\renewcommand\dtlheaderformat[1]{\textbf{#1}\hfil\null}%
\DTLdisplaylongdb{MyDataBase}
\endgroup

\end{document}

在此处输入图片描述

Comsole 输出:

pdflatex-dev test.tex
This is pdfTeX, Version 3.14159265-2.6-1.40.21 (TeX Live 2020) (preloaded format=pdflatex-dev)
 restricted \write18 enabled.
entering extended mode
(./test.tex
LaTeX2e <2021-05-01> pre-release-1 (develop 2021-2-27 branch)
L3 programming layer <2021-02-18>
(/usr/local/texlive/2020/texmf-dist/tex/latex-dev/base/article.cls
Document Class: article 2020/11/23 v1.4m Standard LaTeX document class
(/usr/local/texlive/2020/texmf-dist/tex/latex-dev/base/size10.clo))
(/usr/local/texlive/2020/texmf-dist/tex/latex/datatool/datatool.sty
(/usr/local/texlive/2020/texmf-dist/tex/latex/xkeyval/xkeyval.sty
(/usr/local/texlive/2020/texmf-dist/tex/generic/xkeyval/xkeyval.tex
(/usr/local/texlive/2020/texmf-dist/tex/generic/xkeyval/xkvutils.tex
(/usr/local/texlive/2020/texmf-dist/tex/generic/xkeyval/keyval.tex))))
(/usr/local/texlive/2020/texmf-dist/tex/latex-dev/base/ifthen.sty)
(/usr/local/texlive/2020/texmf-dist/tex/latex/xfor/xfor.sty)
(/usr/local/texlive/2020/texmf-dist/tex/latex/substr/substr.sty)
(/usr/local/texlive/2020/texmf-dist/tex/latex/etoolbox/etoolbox.sty)
(/usr/local/texlive/2020/texmf-dist/tex/latex/datatool/datatool-base.sty
(/usr/local/texlive/2020/texmf-dist/tex/latex-dev/amsmath/amsmath.sty
For additional information on amsmath, use the `?' option.
(/usr/local/texlive/2020/texmf-dist/tex/latex-dev/amsmath/amstext.sty
(/usr/local/texlive/2020/texmf-dist/tex/latex-dev/amsmath/amsgen.sty))
(/usr/local/texlive/2020/texmf-dist/tex/latex-dev/amsmath/amsbsy.sty)
(/usr/local/texlive/2020/texmf-dist/tex/latex-dev/amsmath/amsopn.sty))
(/usr/local/texlive/2020/texmf-dist/tex/latex/datatool/datatool-fp.sty
(/usr/local/texlive/2020/texmf-dist/tex/latex/fp/fp.sty
`Fixed Point Package', Version 0.8, April 2, 1995 (C) Michael Mehlich
(/usr/local/texlive/2020/texmf-dist/tex/latex/fp/defpattern.sty)
(/usr/local/texlive/2020/texmf-dist/tex/latex/fp/fp-basic.sty)
(/usr/local/texlive/2020/texmf-dist/tex/latex/fp/fp-addons.sty)
(/usr/local/texlive/2020/texmf-dist/tex/latex/fp/fp-snap.sty)
(/usr/local/texlive/2020/texmf-dist/tex/latex/fp/fp-exp.sty)
(/usr/local/texlive/2020/texmf-dist/tex/latex/fp/fp-trigo.sty)
(/usr/local/texlive/2020/texmf-dist/tex/latex/fp/fp-pas.sty)
(/usr/local/texlive/2020/texmf-dist/tex/latex/fp/fp-random.sty)
(/usr/local/texlive/2020/texmf-dist/tex/latex/fp/fp-eqn.sty)
(/usr/local/texlive/2020/texmf-dist/tex/latex/fp/fp-upn.sty)
(/usr/local/texlive/2020/texmf-dist/tex/latex/fp/fp-eval.sty)))))
(/usr/local/texlive/2020/texmf-dist/tex/latex-dev/tools/longtable.sty)
(/usr/local/texlive/2020/texmf-dist/tex/latex/l3backend/l3backend-pdftex.def)
(./test.aux)
Underfull \vbox (badness 10000) detected at line 45
[1{/usr/local/texlive/2020/texmf-var/fonts/map/pdftex/updmap/pdftex.map}]
(./test.aux) )
(see the transcript file for additional information)</usr/local/texlive/2020/te
xmf-dist/fonts/type1/public/amsfonts/cm/cmbx10.pfb></usr/local/texlive/2020/tex
mf-dist/fonts/type1/public/amsfonts/cm/cmr10.pfb>
Output written on test.pdf (1 page, 22819 bytes).
Transcript written on test.log.

答案1

根据Ulrike Fischer 的评论可以通过修补来修复\DTLdisplaylongdb

\documentclass{article}
\usepackage{datatool,longtable,etoolbox}

\makeatletter
\expandafter\patchcmd\expandafter{\csname\string\DTLdisplaylongdb\endcsname}%
         {\@dtl@resetdoamp\dtldisplaystarttab}%
         {\dtldisplaystarttab\@dtl@resetdoamp}%
         {\message{Patching succeeded.}}%
         {\message{Patching failed.}}%
\makeatother

%===============================================================
\DTLnewdb{MyDataBase}%
\DTLaddcolumn{MyDataBase}{columnA}%
\DTLsetheader{MyDataBase}{columnA}{First Column}%
\DTLaddcolumn{MyDataBase}{columnB}%
\DTLsetheader{MyDataBase}{columnB}{Second Column}%
%---------------------------------------------------------------
\DTLnewrow{MyDataBase}
\DTLnewdbentry{MyDataBase}{columnA}{Row 1 Col A}
\DTLnewdbentry{MyDataBase}{columnB}{Row 1 Col B}
%---------------------------------------------------------------
\DTLnewrow{MyDataBase}
\DTLnewdbentry{MyDataBase}{columnA}{Row 2 Col A}
\DTLnewdbentry{MyDataBase}{columnB}{Row 2 Col B}
%===============================================================

\begin{document}

\begingroup
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%This does work out after patching:
\renewcommand{\dtldisplaystarttab}{\hline}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\renewcommand\dtldisplayafterhead{\hline}%
\renewcommand\dtldisplaystartrow{\hline}%
\renewcommand{\dtldisplayendtab}{\tabularnewline\hline}%
\renewcommand{\dtlbeforecols}{|}%
\renewcommand{\dtlaftercols}{|}%
\renewcommand{\dtlbetweencols}{|}%
\renewcommand\dtlheaderformat[1]{\textbf{#1}\hfil\null}%
\DTLdisplaylongdb{MyDataBase}
\endgroup

\end{document}

在此处输入图片描述

相关内容