# Inputing data for a tabular environment leads to a weird extra space [duplicate]

I'm writing a table and I'm trying to import its contents from an external file. Curiously, I found out that when importing the contents TeX seems to add a weird space to the last entry. This does not occur when I copy the contents from the external file and paste them directly on the document. How can I fix this behavior?

MWE:

\documentclass[margin=0.1cm]{standalone}

\begin{filecontents*}{data.tex}
01 & 02 & 03 & 04 & 05\\06 & 07 & 08 & 09 & 10\\11 & 12 & 13 & 14 & 15\\16 & 17 & 18 & 19 & 20\\21 & 22 & 23 & 24 & 25
\end{filecontents*}

\begin{document}

\begin{tabular}{c|c|c|c|c}
\input{data.tex}
\end{tabular}

\begin{tabular}{c|c|c|c|c}
01 & 02 & 03 & 04 & 05\\06 & 07 & 08 & 09 & 10\\11 & 12 & 13 & 14 & 15\\16 & 17 & 18 & 19 & 20\\21 & 22 & 23 & 24 & 25
\end{tabular}

\end{document}


The result of the MWE is shown below. The left table is inputted, and the right one is typed directly. Notice how 25 has different alignments in each case.

This happens due to the handling of \input{…} (with LaTeX from 2020-10-01 AFAIK there is even extra hook code after the end of an \input) and because, you have an extra space token: the end of line after \input{…}. To avoid this, comment the end of line after \input{…}:

\documentclass[margin=0.1cm]{standalone}

\begin{filecontents*}{data.tex}
01 & 02 & 03 & 04 & 05\\06 & 07 & 08 & 09 & 10\\11 & 12 & 13 & 14 & 15\\16 & 17 & 18 & 19 & 20\\21 & 22 & 23 & 24 & 25
\end{filecontents*}

\begin{document}

\begin{tabular}{c|c|c|c|c}
\input{data.tex}% <-- this percent is needed
\end{tabular}

\begin{tabular}{c|c|c|c|c}
01 & 02 & 03 & 04 & 05\\06 & 07 & 08 & 09 & 10\\11 & 12 & 13 & 14 & 15\\16 & 17 & 18 & 19 & 20\\21 & 22 & 23 & 24 & 25
\end{tabular}

\end{document}


Note: This would not happen with plainTeX's \input …, because in this case the space token (of the end-of-line) would be the end of the filename. But this would, e.g., not support filenames with spaces.