2

When I run child.tex, then table created with right formatting.

When I run main.tex, with \input{child.tex}, then table in child.tex created with wrong formatting.

child.tex code from: Error: Not in outer par mode: table inside tcolorbox

\documentclass[12pt,a4paper,
               x11names,table]{article}
\usepackage{tcolorbox}
\usepackage[skip=1ex]{caption}

\begin{document}

\begin{tcolorbox}[colback=gray!5!white,colframe=gray!75!black,title=\large{In the next lines I'm trying to insert the same in a box}]
\centering
\begin{tabular}{|c|c|c|c|}
  \hline
  % after \\: \hline or \cline{col1-col2} \cline{col3-col4} ...
  a& b & T/F & dif\\ \hline
1 & 2 & False & -1\\
2 & 4 & False & -2\\
  \hline
\end{tabular}\\
\captionof{figure}{Caption Table}\label{tab:table-out}
    \end{tcolorbox}
\end{document}

And in main.tex:

\documentclass[12pt,a4paper]{article}
a lot of usepackage
\begin{document}
\input{child.tex}
\end{document}

enter image description here

How can I clear format of main.tex inside child.tex?

1
  • 3
    No \documentclass, \begin{document} and \end{document} and calls for packages in child.tex and you can compile ! – Mensch Aug 5 '19 at 4:45
6

You can not have two \documentclass, \begin{document} and \end{document} commands in one TeX code!

Please see the following MWE (package filecontents is only used to have both TeX codes in one compiling MWE, you do not need to use filecontents in your code!) and please see the comments in code for main.tex:

\RequirePackage{filecontents}
\begin{filecontents}{child.tex}
\begin{tcolorbox}[colback=gray!5!white,colframe=gray!75!black,title=\large{In the next lines I'm trying to insert the same in a box}]
\centering
\begin{tabular}{|c|c|c|c|}
  \hline
  % after \\: \hline or \cline{col1-col2} \cline{col3-col4} ...
  a& b & T/F & dif\\ \hline
1 & 2 & False & -1\\
2 & 4 & False & -2\\
  \hline
\end{tabular}\\
\captionof{figure}{Caption Table}\label{tab:table-out}
\end{tcolorbox}
\end{filecontents}


% your code main.tex following % <===========================================
\documentclass[%
  12pt,a4paper,
  x11names,table
]{article}

\usepackage{tcolorbox} % all needed packages for child.tex have to be called here!
\usepackage[skip=1ex]{caption}

\begin{document}
\input{child.tex} % only code for environment tcolorbox
\end{document}

giving you the resulting pdf:

resulting pdf

You get the same output with following both files.

First child.tex:

\begin{tcolorbox}[colback=gray!5!white,colframe=gray!75!black,title=\large{In the next lines I'm trying to insert the same in a box}]
\centering
\begin{tabular}{|c|c|c|c|}
  \hline
  % after \\: \hline or \cline{col1-col2} \cline{col3-col4} ...
  a& b & T/F & dif\\ \hline
1 & 2 & False & -1\\
2 & 4 & False & -2\\
  \hline
\end{tabular}\\
\captionof{figure}{Caption Table}\label{tab:table-out}
\end{tcolorbox}

and second main.tex:

\documentclass[%
  12pt,a4paper,
  x11names,table
]{article}

\usepackage{tcolorbox}
\usepackage[skip=1ex]{caption}

\begin{document}
\input{child.tex}
\end{document}

Please do us and yourself a favour and read the documentation of package filecontents for example by typing texdoc filecontents in your terminal/console and press then enter ... This package is very helpful for building MWE for testing purposes like in your case ...

2
  • thank for your comment. I use and can create this table. But some error like ibb.co/tx49XJJ . And how can i remove this line "ilecontents Child.tex" thanks – latexforti Aug 5 '19 at 5:16
  • 1
    @latexforti Please see my updated answer ... – Mensch Aug 5 '19 at 5:32

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.