Remove space after \include{} table

longtablespacingtables

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!

Best Answer

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}