從包含多個表的其他文件在主文件中產生表

從包含多個表的其他文件在主文件中產生表

我想為表創建一個單獨的文件,以便主乳膠文件不會變得混亂。我知道我可以在新文件中定義表,並使用 input{Tables.tex} 在主文件中添加相同的文件。但是,我不確定如何使用主文件中的表格標籤來請求/生成(而不是引用)表格?任何建議,將不勝感激。謝謝。

答案1

這是包含表格的檔案tables.tex

\newcommand{\firsttable}{% no arguments
\begin{table}[htbp]
\begin{center}
\begin{tabular}{|ccc|}
\hline
This & is & a \\
stupid & table. & \\
\hline
\end{tabular}
\caption{First}
\end{center}
\end{table}}

\newcommand{\secondtable}{% no arguments
\begin{table}[htbp]
\begin{center}
\fbox{\begin{tabular}{ccc}
This & is & another \\
stupid & table.
\end{tabular}}
\caption{Second}
\end{center}
\end{table}}

這是主要文件

\documentclass{article}
\usepackage{lipsum}

\input{tables}% file containing cammands

\begin{document}
\lipsum[1]
\firsttable
\lipsum[2]
\secondtable
\lipsum[3]
\end{document}

注意:在將文字中的表格轉換為命令之前,先調試它們會更容易。

答案2

我所做的(使用threeparttable)是將整個 Threeparttable 放入 table.tex 檔中。這包括標題。我總是把它放在\label裡面\caption——我從來沒有遇到過這樣的問題,它可以讓我忘記。標籤與檔案名稱相同,因此可以輕鬆進行交叉引用。

我的主 .tex 檔包括:

\begin{table}
  \input{table.tex}
\end{table}
This is some text that refers to table~\ref{tab_table}.

而我的表格檔案有 \caption{\label{tab_table}This is a table} \begin{tabular} ... \end{tabular}

在裡面。

其行為就如同在\input主文件中的位置輸入了 table.tex 的全部內容一樣。

有多種工具可用於產生表格,而無需鍵入或記住所有語法 - 但這些工具不受使用的影響\input。例如,您的編輯器可能包含某些內容,或有一個 openoffice 外掛程式。

相關內容