main.tex 與輸入 child.tex 之間的衝突

main.tex 與輸入 child.tex 之間的衝突

當我運行時child.tex,然後使用正確的格式建立表格。

當我運行main.tex, with 時\input{child.tex},然後child.tex創建的表格格式錯誤。

child.tex代碼來自:錯誤:不在外部模式: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}

並在main.tex

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

在此輸入影像描述

如何清除main.tex裡面的格式child.tex

答案1

你可以不是一個 TeX 程式碼中有兩個\documentclass,\begin{document}和指令!\end{document}

請參閱以下MWE(包filecontents僅用於在一個編譯 MWE 中包含兩個 TeX 程式碼,您可以不需要在您的程式碼中使用filecontentsmain.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}

給你產生的pdf:

產生的pdf文件

透過追蹤這兩個文件,您會得到相同的輸出。

第一的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}

第二main.tex

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

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

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

請幫我們和您自己一個忙,閱讀包的文檔,filecontents例如通過texdoc filecontents在終端/控制台中輸入,然後按Enter ...這個包對於構建用於測試目的的MWE 非常有幫助,就像您的情況一樣. ..

相關內容