0

I have multiple tables that need to be formatted exactly the same. Titles and such will need to update, but I think I can handle that. What I'm stumbling on is that \input isn't working how I want it to. Here's my main file MWE:

\documentclass[]{article}
\usepackage{tabularx}
\usepackage{multicol}
\begin{document}
\section{}
\input{tablebegin}
\input{tableend}
\end{document}

Here's my tablebegin.tex file:

\begin{table}[ht]
    \centering
    %   \begin{threeparttable}
    \caption{Table Caption}
    \scriptsize% to fit on page
    \begin{tabularx}{5in}{ cccccccccccc }
        \multicolumn{12}{ c }{\textbf{Table Title}}\\ \hline 
        &1&2&3&4&56&7&8&9&10&11&12\\

And here's the table end file:

\end{tabularx}
\end{table}

In TexStudio I'm getting the following error:

File ended while scanning use of \TX@get@body. \input{tablebegin}

This is probably bad practice, but I'm trying to keep the table formatting separate from the tables. My goal is to have about 20 tablemid files that will be encapsulated by tablebegin and tableend. That way if I want to adjust the table formatting I can do it in one place. I am probably approaching this completely wrong, so I'm open to any suggestions.

Matt P
  • 41
  • Unrelated to the error message itself, but please be a war that using tabularx without at leas one flexible width X type column does not really make sense. – leandriis Jan 19 '21 at 20:45
  • Why don't you set up a new environment? – NBur Jan 19 '21 at 20:54
  • Thanks leandriis, I'll look into eliminating that. I was using an X initially, I believe but edited the table quite a bit. I'll edit the production table to remove that. NBur, maybe that's what I need to do. I'm not a LaTeX pro by any means, but I'll see what I can run down on setting one up that handles my needs. If I figure it out, and it solves the problem, I'll post it back here for anyone who may stumble across this thread. – Matt P Jan 19 '21 at 21:05
  • 1
    Thanks leandriis, eliminating the tabularx seems to get it to work. NBur, I found this link https://tex.stackexchange.com/questions/447128/how-to-create-a-new-environment-including-a-table-environment-and-tabularx-envir where they've created a new environment with settings. That may be the correct solution because the table settings could just be edited in the main document, thus not requiring 2 extra files. It just seems cleaner than what I was trying to do. I'll have to play with it tomorrow when I get a chance. It's so good to get some help on this because I was lost. Thanks again! – Matt P Jan 19 '21 at 21:14

2 Answers2

1

You can scan the file content to a macro and then use this macro.

\def\scanfile#1\to#2{%
   \everyeof={\eof!}%
   \expandafter\scanfileA\input{#1}%
   \everyeof={}%
   \let#2=\filecontent
}
\long\def\scanfileA#1\eof!{\def\filecontent{#1}}

Now, you can do, for example:

\scanfile{tableA.tex}\to\macroA
\scanfile{tableB.tex}\to\macroB
etc.

Finally, if the files are only part of tables then you can do:

\caption{Table Caption}
\begin{tabularx}{5in}{ cccccccccccc }
\macroA
\end{tabularx}

Note: If you are using LaTeX then you must use \@@input primitive in the \scanfile macro, no \input macro. So, the appropriate line is:

\expandafter\scanfileA\@@input{#1}%

and you must set catcode of @ to 11 when reading the macro body.

wipet
  • 74,238
0

NBur's suggestion is the correct answer to this question. Here's a better example than I posted in response to him that will work for my situation: https://stackoverflow.com/questions/1390064/how-to-create-a-selfdefined-table-environment-with-the-caption-at-the-end-of-the

Matt P
  • 41