使用 datatool 包每五行添加一个空行

使用 datatool 包每五行添加一个空行

您知道如何使用\DTLforeach命令在每个 5 的倍数处插入一个空行吗?

请测试这个最小代码:

\documentclass{minimal}
\usepackage[utf8]{inputenc}
\usepackage{datatool}
\DTLnewdb{myDB}
\DTLnewrow{myDB}
\DTLnewdbentry{myDB}{Fst}{1}\DTLnewdbentry{myDB}{Snd}{0,995025}\DTLnewdbentry{myDB}{Trd}{0,990099}
\DTLnewrow{myDB}
\DTLnewdbentry{myDB}{Fst}{2}\DTLnewdbentry{myDB}{Snd}{1,985099}\DTLnewdbentry{myDB}{Trd}{1,970395}
\DTLnewrow{myDB}
\DTLnewdbentry{myDB}{Fst}{3}\DTLnewdbentry{myDB}{Snd}{2,970248}\DTLnewdbentry{myDB}{Trd}{2,940985}
\DTLnewrow{myDB}
\DTLnewdbentry{myDB}{Fst}{4}\DTLnewdbentry{myDB}{Snd}{3,950496}\DTLnewdbentry{myDB}{Trd}{3,901966}
\DTLnewrow{myDB}
\DTLnewdbentry{myDB}{Fst}{5}\DTLnewdbentry{myDB}{Snd}{4,925866}\DTLnewdbentry{myDB}{Trd}{4,853431}
\DTLnewrow{myDB}
\DTLnewdbentry{myDB}{Fst}{6}\DTLnewdbentry{myDB}{Snd}{5,896384}\DTLnewdbentry{myDB}{Trd}{5,795476}
\DTLnewrow{myDB}
\DTLnewdbentry{myDB}{Fst}{7}\DTLnewdbentry{myDB}{Snd}{6,862074}\DTLnewdbentry{myDB}{Trd}{6,728195}
\DTLnewrow{myDB}
\DTLnewdbentry{myDB}{Fst}{8}\DTLnewdbentry{myDB}{Snd}{7,822959}\DTLnewdbentry{myDB}{Trd}{7,651678}
\DTLnewrow{myDB}
\DTLnewdbentry{myDB}{Fst}{9}\DTLnewdbentry{myDB}{Snd}{8,779064}\DTLnewdbentry{myDB}{Trd}{8,566018}
\DTLnewrow{myDB}
\DTLnewdbentry{myDB}{Fst}{10}\DTLnewdbentry{myDB}{Snd}{9,730412}\DTLnewdbentry{myDB}{Trd}{9,471305}
\DTLnewrow{myDB}
\DTLnewdbentry{myDB}{Fst}{11}\DTLnewdbentry{myDB}{Snd}{10,677027}\DTLnewdbentry{myDB}{Trd}{10,367628}

\begin{document}
        \begin{tabular}{crr}
            \DTLforeach{myDB}{\one=Fst,\two=Snd,\three=Trd}
            {\one & \two & \three \\}
        \end{tabular}
\end{document}

答案1

而不是使用空白\addlinespacebooktabs

\documentclass{article}
\usepackage{datatool}
\usepackage{booktabs}

\DTLnewdb{myDB}
\DTLnewrow{myDB}
\DTLnewdbentry{myDB}{Fst}{1}\DTLnewdbentry{myDB}{Snd}{0,995025}\DTLnewdbentry{myDB}{Trd}{0,990099}
\DTLnewrow{myDB}
\DTLnewdbentry{myDB}{Fst}{2}\DTLnewdbentry{myDB}{Snd}{1,985099}\DTLnewdbentry{myDB}{Trd}{1,970395}
\DTLnewrow{myDB}
\DTLnewdbentry{myDB}{Fst}{3}\DTLnewdbentry{myDB}{Snd}{2,970248}\DTLnewdbentry{myDB}{Trd}{2,940985}
\DTLnewrow{myDB}
\DTLnewdbentry{myDB}{Fst}{4}\DTLnewdbentry{myDB}{Snd}{3,950496}\DTLnewdbentry{myDB}{Trd}{3,901966}
\DTLnewrow{myDB}
\DTLnewdbentry{myDB}{Fst}{5}\DTLnewdbentry{myDB}{Snd}{4,925866}\DTLnewdbentry{myDB}{Trd}{4,853431}
\DTLnewrow{myDB}
\DTLnewdbentry{myDB}{Fst}{6}\DTLnewdbentry{myDB}{Snd}{5,896384}\DTLnewdbentry{myDB}{Trd}{5,795476}
\DTLnewrow{myDB}
\DTLnewdbentry{myDB}{Fst}{7}\DTLnewdbentry{myDB}{Snd}{6,862074}\DTLnewdbentry{myDB}{Trd}{6,728195}
\DTLnewrow{myDB}
\DTLnewdbentry{myDB}{Fst}{8}\DTLnewdbentry{myDB}{Snd}{7,822959}\DTLnewdbentry{myDB}{Trd}{7,651678}
\DTLnewrow{myDB}
\DTLnewdbentry{myDB}{Fst}{9}\DTLnewdbentry{myDB}{Snd}{8,779064}\DTLnewdbentry{myDB}{Trd}{8,566018}
\DTLnewrow{myDB}
\DTLnewdbentry{myDB}{Fst}{10}\DTLnewdbentry{myDB}{Snd}{9,730412}\DTLnewdbentry{myDB}{Trd}{9,471305}
\DTLnewrow{myDB}
\DTLnewdbentry{myDB}{Fst}{11}\DTLnewdbentry{myDB}{Snd}{10,677027}\DTLnewdbentry{myDB}{Trd}{10,367628}

\newcounter{jjhenry}
\newcommand{\possiblyaddspace}{%
  \noalign{\stepcounter{jjhenry}\ifnum\value{jjhenry}=5 \setcounter{jjhenry}{0}\fi}%
  \ifnum\value{jjhenry}=0 \addlinespace\fi
}

\begin{document}

\setcounter{jjhenry}{0}
\begin{tabular}{crr}
  \DTLforeach{myDB}{\one=Fst,\two=Snd,\three=Trd}
    {\one & \two & \three \\ \possiblyaddspace}
\end{tabular}

\end{document}

当计数器达到值 5 时,将重置为 0。

在此处输入图片描述

相关内容