0

I ran into a problem with the \include/\input command. I want to generate a table based on the child document somedoc.tex, which looks as follow

$$12.67$$ & $$6.18$$ & $$5.00$$ & $$60.33$$ \\
$$12.80$$ & $$0.00$$ & $$0.00$$ & $$64.22$$ \\
$$0.83$$ & $$22.88$$ & $$18.02$$ & $$16.32$$   

My code is

\documentclass{article}
\usepackage{amsfonts}
\usepackage{booktabs}
\usepackage{siunitx}
\begin{document}

\begin{table}
\center \small
\begin{tabular}{SSSS} \toprule      
{col1} & {col3} & {col3} & {col4} \\ \midrule

\include{"somedoc.tex"}

\\ \bottomrule 
\end{tabular}
\raggedright 
\end{table} 


\end{document}

The weird thing is that I can easily generate the document when I put in the text from the child-document directly. However, when I include it via \include/\input it makes an error. So, how should I include the text as a child-document?

In advance, thanks for the answer!

6
  • Not so sure if this is the right way to do it, look at pgfplotstable it might be better. See e.g this post for some example
    – BambOo
    Jun 18 '19 at 10:56
  • I'm not sure that I understand how pgfplotstable will solve this?
    – A.joh
    Jun 18 '19 at 11:06
  • 1
    you should not have $ (or $$) around the numbers if you are including them in an S column, you can not use \include in a table (it always forces a new page at the start and end of inclusion) It is possible to use \input but doing that in a tabular requires some care, \center should never be used as a command, you meant \centering Jun 18 '19 at 11:17
  • @A.joh pgfplotstable is able to read data from files, and you can customize column headers and so on. Which seems to be fairly what you want to do, isn't it ?
    – BambOo
    Jun 18 '19 at 11:18
  • @DavidCarlisle: You are totally right! However, that will not solve the problem
    – A.joh
    Jun 18 '19 at 11:27
2

enter image description here


12.67 & 6.18 & 5.00 & 60.33 \\
12.80 & 0.00 & 0.00 & 64.22 \\
0.83 & 22.88 & 18.02 & 16.32

\documentclass{article}
\usepackage{amsfonts}
\usepackage{booktabs}
\usepackage{siunitx}
\begin{document}

\begin{table}
\centering \small
\begin{tabular}{SSSS} \toprule      
{col1} & {col3} & {col3} & {col4} \\ \midrule
\relax\input{"somedoc.tex"}
\\ \bottomrule 
\end{tabular}

\end{table} 


\end{document}
2
  • Why is it necessary to use "\relax" before "\input"?
    – Sveinung
    Jun 18 '19 at 11:38
  • @David Carlisle: You are totally right! "\relax" is a solution to the case above. I marked this as a solution. Thanks for your answer. It is appreciated a lot!
    – A.joh
    Jun 18 '19 at 11:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.