3

I've created a table using R kableExtra. but would like to be able to control the Notes section of the table manually in LATEX. Thus, I use the \include{table.tex} command to bring in the outputted table. Unfortunately, if I write:

\documentclass[12pt]{article}
\usepackage{longtable}
\begin{document}
\include{table.tex}\footnotesize{Note: this is a note.}
\end{document}

I get a huge indent after the table, and on the next page only, it says "this is a note".

The table.tex file looks like so:

\begingroup\fontsize{8}{10}\selectfont

\begin{longtable}{|c|c|c|c|}
\caption{A simple longtable example}\label{tab:thetable}\\
\hline
\textbf{First entry} & \textbf{Second entry} & \textbf{Third entry} & \textbf{Fourth entry} \\
\hline
\endfirsthead
\multicolumn{4}{c}%
{\tablename\ \thetable\ -- \textit{Continued from previous page}} \\
\hline
\textbf{First entry} & \textbf{Second entry} & \textbf{Third entry} & \textbf{Fourth entry} \\
\hline
\endhead
\hline \multicolumn{4}{r}{\textit{Continued on next page}} \\
\endfoot
\hline
\endlastfoot
1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\
\end{longtable}
\endgroup{}

I have tried wrapping everything in a minipage, but because I establish my captions and labels for the table inside kableExtra, it resides in table.tex. Thus, I'm unable to reference that table, since I cannot have a table inside a minipage.

Someone please help!

2
  • 2
    Have you tried replacing \include{table.tex} with \input table?
    – Mico
    Commented Apr 6, 2022 at 5:40
  • 3
    Incidentally, \footnotesize is a switch, i.e., it does not take an argument delimited by curly braces. If you want to limit the scope of the \footnotesize directive to the sentence "Note: this is a note.", you should write {\footnotesize Note: this is a note.}.
    – Mico
    Commented Apr 6, 2022 at 5:51

3 Answers 3

5

The command \include inserts a page break both before and after its material. The command you want is \input, not \include.

A separate observation: The fontsize changing commands \tiny, \scriptsize, \footnotesize, \small, \normalsize, \large, \Large, \LARGE, \huge and Huge are switches, i.e., they do not take a curly-brace delimited argument. Thus, you should change

\footnotesize{Note: this is a note.}

to

{\footnotesize Note: this is a note.}

enter image description here

\documentclass[12pt]{article}
\begin{filecontents*}[overwrite]{table.tex}
\begingroup 
\fontsize{8}{10}\selectfont

\begin{longtable}{|c|c|c|c|}
\caption{A simple longtable in \texttt{8pt}}\label{tab:thetable}\\
\hline
\textbf{First entry} & \textbf{Second entry} & \textbf{Third entry} & \textbf{Fourth entry} \\
\hline
\endfirsthead

\multicolumn{4}{c}{%
   \tablename\ \thetable\ -- \textit{Continued from previous page}} \\
\hline
\textbf{First entry} & \textbf{Second entry} & \textbf{Third entry} & \textbf{Fourth entry} \\
\hline
\endhead

\hline \multicolumn{4}{r}{\textit{Continued on next page}} \\
\endfoot

\hline
\endlastfoot

1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\
\end{longtable}
\endgroup
\end{filecontents*}

\usepackage{longtable}
\begin{document}

Bla bla bla in \texttt{\string\normalsize\ (12pt)}.

%\include{table.tex} % <-- not good!
\input table         % <-- good
{\footnotesize Note: This note is typeset in \texttt{\string\footnotesize\  (10pt)}.}

More bla bla bla in \texttt{\string\normalsize\ (12pt)}.
\end{document}
4

Solution for your problem is given in the @Mico comment. So, here mostly off-topic solution. I would write your document on the following way:

  • main document:
\documentclass[12pt]{article}
\usepackage{tabularray}  % <--- new
\usepackage{lipsum}

\begin{document}
\lipsum[1-3]
\input{table.tex}         % <--- changed
\lipsum[4]
\end{document}
  • file for table, which use longtblr table defined in the tabularray package. Part of it is footnote, for which I assume that you like to have immediately after end of table:
\begingroup
\fontsize{8}{10}\selectfont
    \begin{longtblr}[
     caption = {A simple longtable example},
       label = {tab:thetable},
remark{Note} = {This is a note}
                    ]{
        rowhead = 1,
        hlines, vlines,
        colspec= {*4{Q[c]}},
        row{1} = {font=\bfseries}
                    }
First entry & Second entry  & Third entry   & Fourth entry  \\
1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\
\end{longtblr}
\endgroup

enter image description here

3
  • "@Nuci" ?? :-) .
    – Mico
    Commented Apr 6, 2022 at 6:37
  • @mico, sorry. Typing your name I stroke one key left from correct ones :-(. Corrected now. Thank you very much fo pointing me to this error.
    – Zarko
    Commented Apr 6, 2022 at 6:40
  • Hey, no problem! I actually thought that the typo was quite funny.
    – Mico
    Commented Apr 6, 2022 at 7:38
2

I agree whith the recomnandation to use \input instead of \include.

Nevertheless, if there are good reasons to stick with \include, likely in order to use \includeonly, you could define a version of \include that doesn't add the pagebreak as follows:

\usepackage{etoolbox} % for \patchcmd
\makeatletter
\let\includenobreak=\include
\let\@includenobreak=\@include
\patchcmd{\@includenobreak}%
  {\clearpage}{}{}{}
\patchcmd{\includenobreak}%
  {\@include}{\@includenobreak}{}{}
\makeatother

and use \includenobreak for your table or anything else.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .