
Quando executo child.tex
, a tabela é criada com a formatação correta.
Quando executo main.tex
, com \input{child.tex}
, a tabela é child.tex
criada com formatação errada.
child.tex
código de:Erro: Não está no modo par externo: tabela dentro do 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}
E em main.tex
:
\documentclass[12pt,a4paper]{article}
a lot of usepackage
\begin{document}
\input{child.tex}
\end{document}
Como posso limpar o formato main.tex
interno child.tex
?
Responder1
Você podenãotenha dois \documentclass
comandos \begin{document}
e \end{document}
em um código TeX!
Por favor, veja o seguinte MWE (o pacote filecontents
é usado apenas para ter ambos os códigos TeX em um MWE de compilação, você faznão precisapara usar filecontents
em seu código!) e veja os comentários no código para 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}
fornecendo o pdf resultante:
Você obtém a mesma saída seguindo os dois arquivos.
Primeiro 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}
e em segundo lugar main.tex
:
\documentclass[%
12pt,a4paper,
x11names,table
]{article}
\usepackage{tcolorbox}
\usepackage[skip=1ex]{caption}
\begin{document}
\input{child.tex}
\end{document}
Por favor, faça um favor a nós e a você mesmo e leia a documentação do pacote, filecontents
por exemplo, digitando texdoc filecontents
em seu terminal/console e pressione e depois enter ... Este pacote é muito útil para construir MWE para fins de teste, como no seu caso ...