在 longtable 中使用 newpage 时包含额外的行

在 longtable 中使用 newpage 时包含额外的行

我正在尝试改变longtable环境以始终将此行作为第一行单元格:

\begin{tabular}
\textcolor{blue}{\textbf{R}} code & Syntax & Gebruik & Is vector & Link \\
\\
\hline
\end{tabular}

我想要实现的目标如下所示,使用环境tabular而不是longtable

\documentclass{ltxdoc}
\usepackage{xcolor}
\usepackage{geometry}

\newcommand{\tabpageskip}{
                        \end{tabular}%
                        \newpage%
                        \noindent  \begin{tabular}[h]{l p{5cm} p{5cm} c c} 
                        \textcolor{blue}{\textbf{R}} code & Syntax & Gebruik & Is vector ? & Link \\%
                        \\%
                        \hline%
                        }%

\begin{document}


\noindent \begin{tabular}[h]{l p{5cm} p{5cm} c c} 
\textcolor{blue}{\textbf{R}} code & Syntax & Gebruik & Is vector & Link \\
\\
\hline
\\
\texttt{?} & \texttt{?\textcolor{blue}{<commando>}} & {Het opzoeken van \textcolor{blue}{\textbf{R}} commando's} && {$\leftarrow$} 
\\
\\
\texttt{apropos()} & \texttt{\textcolor{blue}{apropos(}"\textcolor{cyan}{<commando>}"\textcolor{blue}{)}} & {(Deel van een) commando opzoeken} &  & {$\leftarrow$} \\
\\
\\
\texttt{as.table()} & \texttt{\textcolor{blue}{as.table(}\textcolor{cyan}{<array>}\textcolor{red}{)}} & {\textbf{\textcolor{blue}{R}} vertellen dat je de gegevens als een tabel wil lezen: read \texttt{as.table()}!} & $\surd$ & {$\leftarrow$} \\
\\
\\
\texttt{barplot()} & {\texttt{\textcolor{blue}{barplot(}\textcolor{cyan}{<functie>},} \texttt{\textcolor{green}{col=c(}\textcolor{red}{"<kleur>",...}\textcolor{green}{)}\textcolor{blue}{)}}} & {Barplot maken (histogram, maar dan kolommen {apart}) Verschillende kleuren\label{anchor.kleurspec} instellen met de \textbf{engelse} namen, bijv.: \texttt{"brown"}} &  &  \\
\\
\\
\texttt{binom.test()} & {\texttt{\textcolor{blue}{binom.test(}\textcolor{cyan}{<tabel>},}  \texttt{\textcolor{green}{p=<waarde>}\textcolor{blue}{)}}} & {Gesorteerde data tabel onderwerpen aan binomiaal test Hypothetische kans op succes (nulhypothese)} & $\surd$ & {$\leftarrow$} \\
\\
\\
\texttt{c()} & \texttt{\textcolor{blue}{c(}\textcolor{cyan}{<getal>},\textcolor{cyan}{ <getal>},\textcolor{red}{...}\textcolor{blue}{)}} & {Handmatig een array maken. Voor langere getallen, gebruik \texttt{array()}} & $\surd$ & {$\leftarrow$} \\
\tabpageskip
\\
\texttt{colSums()} & {\texttt{\textcolor{blue}{colSums(}\textcolor{cyan}{<functie>}\textcolor{blue}{)}}} & {Optellen van kolommen van een matrix. Voor rijen, gebruik: {\texttt{rowSums()}$\rightarrow$}} & $\surd$ &  \\ 
\\
\\
\texttt{dbinom()} & {\texttt{\textcolor{blue}{dbinom(}\textcolor{cyan}{<getal>},} \texttt{\textcolor{green}{size=<waarde>},}  \texttt{\textcolor{red}{prob=<waarschijnlijkheid>}\textcolor{blue}{)}}} & {Kans op deze waarde bij zovaak proberen kans op succes} & $\surd$ & {$\leftarrow$} \\ 
\\
\\
\texttt{expand.grid()} & {\texttt{\textcolor{blue}{expand.grid(}}  \texttt{\textcolor{cyan}{<getal>}:\textcolor{green}{<getal>},\textcolor{red}{...}\textcolor{blue}{)}}} & {Aftellen meerdere dobbelstenen Minimale en maximale getal voor je `dobbelsteen'} &  & {$\leftarrow$} \\
\\
\\
\texttt{file.choose()} & \texttt{\textcolor{blue}{file.choose(}"\textcolor{cyan}{<bestand>}"\textcolor{blue}{)}} & {Bestanden laden in \textcolor{blue}{\textbf{R}}} && {$\leftarrow$} \\
\\
\\
\texttt{help()} & \texttt{\textcolor{blue}{help(}\textcolor{cyan}{<commando>}\textcolor{blue}{)}} & {Het opzoeken van \textcolor{blue}{\textbf{R}} commando's} && {$\leftarrow$} \\
\\
\\
\texttt{hist()} & {\texttt{\textcolor{blue}{hist(}\textcolor{cyan}{<functie>},}  \texttt{\textcolor{green}{breaks=}\textcolor{red}{<getal>},} \texttt{\textcolor{violet}{freq=}\textcolor{purple}{<logische waarde>}\textcolor{blue}{)}} } & {Histogram tekenen  Grootte van de balkjes aangeven, zie {$\leftarrow$}  \texttt{\textcolor{purple}{TRUE}}: plot de frequenties en \texttt{\textcolor{purple}{FALSE}}: plot verhouding tot geheel} & & {$\leftarrow$} \\
\\
\\
\texttt{layout()} &  \texttt{\textcolor{blue}{layout(}\textcolor{cyan}{<matrix>}\textcolor{blue}{)}} & {Aanpassen van je grafische interface met de vorm van deze matrix} & & {$\leftarrow$} \\
\end{tabular}
\end{document}

我检查过longtable.dtx并且相信奇迹就在这里发生(第 63-74 行):

\let\LT@@tabarray\@tabarray
\let\LT@@hl\hline
\def\@tabarray{%
\let\hline\LT@@hl
\let\multicolumn\LT@mcol
\LT@@tabarray}%
\let\\\LT@tabularcr\let\tabularnewline\\%
\def\newpage{\noalign{\break}}%
\def\pagebreak{\noalign{\ifnum`}=0\fi\@testopt{\LT@no@pgbk-}4}%
\def\nopagebreak{\noalign{\ifnum`}=0\fi\@testopt\LT@no@pgbk4}%
\let\hline\LT@hline \let\kill\LT@kill\let\caption\LT@caption
\@tempdima\ht\strutbox
\let\@endpbox\LT@endpbox

我该如何以及应该在哪里添加我的代码?作为什么论点的一部分?我试过了\def\newpage{...\<mycode>},但效果不太好。

答案1

包裹longtable支持指定页眉和页脚部分,请参阅文档

通常,两行之间的间距可以通过可选参数 来扩大\\。在这种情况下,空间首先被文本单元格的大下行字符所占用,因此示例首先通过 结束行并禁止换行。然后它通过和\\*添加空格,并添加惩罚以允许换行。在分页符处,空格位于条目下方,而不是新页面的顶部。\noalign\vskip

另一种方法是使用 length \extrarowheight。此空格被添加到每行上方,不幸的是它也会影响标题中的行。

在文本列中,示例使用允许连字符\RaggedRight的包来raggedright稍微平滑乱码。对于对齐,列宽对我来说似乎有点小。

\documentclass{ltxdoc}
\usepackage{geometry}
\usepackage{xcolor}
\usepackage{longtable}
\usepackage{ragged2e}
\usepackage{array}

\newcommand*{\tabsep}{3ex}
\newcommand*{\TS}{\noalign{\vskip\tabsep}\pagebreak[1]}

\begin{document}

\begin{longtable}[h]{l >{\RaggedRight}p{5cm} >{\RaggedRight}p{5cm} c c} 
\textcolor{blue}{\textbf{R}} code & Syntax & Gebruik & Is vector & Link
\\*\TS
\hline
\TS
\endhead
\texttt{?} & \texttt{?\textcolor{blue}{<commando>}} & {Het opzoeken van \textcolor{blue}{\textbf{R}} commando's} && {$\leftarrow$}
\\*\TS
\texttt{apropos()} & \texttt{\textcolor{blue}{apropos(}"\textcolor{cyan}{<commando>}"\textcolor{blue}{)}} & {(Deel van een) commando opzoeken} &  & {$\leftarrow$}
\\*\TS
\texttt{as.table()} & \texttt{\textcolor{blue}{as.table(}\textcolor{cyan}{<array>}\textcolor{red}{)}} & {\textbf{\textcolor{blue}{R}} vertellen dat je de gegevens als een tabel wil lezen: read \texttt{as.table()}!} & $\surd$ & {$\leftarrow$}
\\*\TS
\texttt{barplot()} & {\texttt{\textcolor{blue}{barplot(}\textcolor{cyan}{<functie>},} \texttt{\textcolor{green}{col=c(}\textcolor{red}{"<kleur>",...}\textcolor{green}{)}\textcolor{blue}{)}}} & {Barplot maken (histogram, maar dan kolommen {apart}) Verschillende kleuren\label{anchor.kleurspec} instellen met de \textbf{engelse} namen, bijv.: \texttt{"brown"}} &  &
\\*\TS
\texttt{binom.test()} & {\texttt{\textcolor{blue}{binom.test(}\textcolor{cyan}{<tabel>},}  \texttt{\textcolor{green}{p=<waarde>}\textcolor{blue}{)}}} & {Gesorteerde data tabel onderwerpen aan binomiaal test Hypothetische kans op succes (nulhypothese)} & $\surd$ & {$\leftarrow$}
\\*\TS
\texttt{c()} & \texttt{\textcolor{blue}{c(}\textcolor{cyan}{<getal>},\textcolor{cyan}{ <getal>},\textcolor{red}{...}\textcolor{blue}{)}} & {Handmatig een array maken. Voor langere getallen, gebruik \texttt{array()}} & $\surd$ & {$\leftarrow$}
\\*\TS
\texttt{colSums()} & {\texttt{\textcolor{blue}{colSums(}\textcolor{cyan}{<functie>}\textcolor{blue}{)}}} & {Optellen van kolommen van een matrix. Voor rijen, gebruik: {\texttt{rowSums()}$\rightarrow$}} & $\surd$ & 
\\*\TS
\texttt{dbinom()} & {\texttt{\textcolor{blue}{dbinom(}\textcolor{cyan}{<getal>},} \texttt{\textcolor{green}{size=<waarde>},}  \texttt{\textcolor{red}{prob=<waarschijnlijkheid>}\textcolor{blue}{)}}} & {Kans op deze waarde bij zovaak proberen kans op succes} & $\surd$ & {$\leftarrow$}
\\*\TS
\texttt{expand.grid()} & {\texttt{\textcolor{blue}{expand.grid(}}  \texttt{\textcolor{cyan}{<getal>}:\textcolor{green}{<getal>},\textcolor{red}{...}\textcolor{blue}{)}}} & {Aftellen meerdere dobbelstenen Minimale en maximale getal voor je `dobbelsteen'} &  & {$\leftarrow$}
\\*\TS
\texttt{file.choose()} & \texttt{\textcolor{blue}{file.choose(}"\textcolor{cyan}{<bestand>}"\textcolor{blue}{)}} & {Bestanden laden in \textcolor{blue}{\textbf{R}}} && {$\leftarrow$}
\\*\TS
\texttt{help()} & \texttt{\textcolor{blue}{help(}\textcolor{cyan}{<commando>}\textcolor{blue}{)}} & {Het opzoeken van \textcolor{blue}{\textbf{R}} commando's} && {$\leftarrow$}
\\*\TS
\texttt{hist()} & {\texttt{\textcolor{blue}{hist(}\textcolor{cyan}{<functie>},}  \texttt{\textcolor{green}{breaks=}\textcolor{red}{<getal>},} \texttt{\textcolor{violet}{freq=}\textcolor{purple}{<logische waarde>}\textcolor{blue}{)}} } & {Histogram tekenen  Grootte van de balkjes aangeven, zie {$\leftarrow$}  \texttt{\textcolor{purple}{TRUE}}: plot de frequenties en \texttt{\textcolor{purple}{FALSE}}: plot verhouding tot geheel} & & {$\leftarrow$}
\\*\TS
\texttt{layout()} &  \texttt{\textcolor{blue}{layout(}\textcolor{cyan}{<matrix>}\textcolor{blue}{)}} & {Aanpassen van je grafische interface met de vorm van deze matrix} & & {$\leftarrow$}
\end{longtable}
\end{document}

第 1 页

第2页

答案2

尝试这个:

\documentclass{article}
\usepackage{color}
\usepackage{geometry}
\usepackage{longtable}
\usepackage{multicol}

\newcommand{\tabpageskip}{

                        \newpage%

{\textcolor{blue}{\textbf{R}}} code & Syntax & Gebruik & Is vector & Link \\
\\
\hline

                        }%

\begin{document}


\begin{longtable}{ccccc}
\tabpageskip\\
a&b&C&D&E\\
a&b&C&D&E\\
a&b&C&D&E\\
a&b&C&D&E\\
a&b&C&D&E\\
a&b&C&D&E\\
a&b&C&D&E\\
a&b&C&D&E\\
a&b&C&D&E\\
a&b&C&D&E\\
a&b&C&D&E\\
a&b&C&D&E\\
a&b&C&D&E\\
\tabpageskip\\
a&b&C&D&E\\
a&b&C&D&E\\
a&b&C&D&E\\
a&b&C&D&E\\
a&b&C&D&E\\
a&b&C&D&E\\
a&b&C&D&E\\
a&b&C&D&E\\
a&b&C&D&E\\
a&b&C&D&E\\
a&b&C&D&E\\
a&b&C&D&E\\
a&b&C&D&E\\
\caption{Longtable}
\end{longtable}

\end{document}

在此处输入图片描述

我不知道你是否也希望当长表计算分页符时自动出现“平铺行”

相关内容