
我正在編寫一個表,並嘗試從外部文件導入其內容。奇怪的是,我發現導入內容時 TeX 似乎在最後一個條目中添加了一個奇怪的空格。當我從外部文件複製內容並將其直接貼上到文件上時,不會發生這種情況。我該如何解決這個問題?
微量元素:
\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}
答案1
發生這種情況是由於處理\input{…}
(據我所知,從 2020-10-01 開始使用 LaTeX,在 的末尾甚至有額外的鉤子代碼\input
)並且因為,你有一個額外的空格標記:在 後的行尾\input{…}
。為了避免這種情況,請在以下行尾註記\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}
注意:對於 plainTeX 來說不會發生這種情況\input …
,因為在這種情況下,(行尾的)空格標記將是檔案名稱的末尾。但這例如不支援帶空格的檔名。