0

I'm trying to change the longtable environment to always produce this row as a first row of cells:

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

What I'm trying to achieve is shown below, using the tabular environment instead of 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}

I have checked longtable.dtx and believe here is where the magic happens (lines 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

How can I and where should I add my line here? And as part of what argument? I tried \def\newpage{...\<mycode>}, but that wouldn't fly so well.

  • could you upload a draft of how will table look after? and also i don't think it's a good option to modify long table.dtx, i think is better just to define your special table with newcommand inside your own pack i.e. myTable.sty – Jared Lo May 6 '14 at 19:20
  • @JaredLo I want the table to look exactly the way the tabular looks in my OP, except I want to do it automated with longtable, instead of tabular. I don't want to redefine longtable.dtx, I just want to maybe "hack" it to include that extra cell row. – 1010011010 May 6 '14 at 19:21
2

Package longtable supports to specify a headers and footer part, see the documentation.

Usually the space between two rows can be enlarged by the optional argument of \\. In this case the space gets first consumed by the large descenders of the text cells, therefore the example first ends the line and forbids a line break by \\*. Then it adds the space via \noalign and \vskip and adds a penalty to allow the linebreak. At a page break the space gets below the entry and not at the top of the new page.

An alternative is length \extrarowheight. This space is added above each row, unfortunately it also affects the row in the header.

In the text columns the example uses \RaggedRight of package raggedright that allows hyphenation to smooth the ragging a bit. For justification the column width seems a little to small for me.

\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}

Page 1

Page 2

  • Precisely what I wanted. I didn't find anything in the documentation on the usage of headers and footers in longtable, though? The search function within the manual didn't find any matches for "head" either... – 1010011010 May 6 '14 at 21:31
  • 1
    I have fixed the example, it wasn't too "precise". \endhead and friends are described in section "3 Captions and Headings". – Heiko Oberdiek May 6 '14 at 21:34
0

Try this:

\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}

enter image description here

I don't know if you also want that the "tile row" automatic appears when long table computes a pagebreak

  • Obviously this is a solution, I was trying to circumvent a macro altogether and just redefine \newpage based on \section input. – 1010011010 May 6 '14 at 20:09
  • inside longtable.dtx define the same command \tabpageskip \def\newpage{\noalign{\break}} – Jared Lo May 6 '14 at 20:14
  • What I actually intended to do is to just use \newpage in the longtable environment and have this first line automatically added as a first row to the table. (without the use of a macro) – 1010011010 May 6 '14 at 20:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.