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!

Stefan Pinnow
  • 29,535
A.joh
  • 3
  • 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 – David Carlisle 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
  • @A.joh why doesn't it solve the problem? I posted the result of those changes as an answer, isn't that the output you wanted? – David Carlisle Jun 18 '19 at 11:28

1 Answers1

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}
David Carlisle
  • 757,742
  • 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