将 csvsimple 包生成的表格插入到另一个不使用该包的 tex 文档中

将 csvsimple 包生成的表格插入到另一个不使用该包的 tex 文档中

我不确定标题是否清楚地描述了这个问题。

我有一个 latex 文档,它使用 csvsimple 包从大型数据文件中读取一些列并制作一个漂亮的表格。它运行良好,但现在我想将论文提交给一个不允许我使用该包的期刊 :-(

我想知道是否有一种方法可以获取处理后的表格并将其插入到不使用该包的文档中,即类似于不允许使用 bibtex 的情况,然后您可以剪切并粘贴 bibtex 在文档中生成的 bbl 文件。

答案1

对于小表格,Ulrike 建议的方法更方便:用您的表格制作一个独立文档,然后插入输出 .pdf \includegraphics

对于长表,也许下面的方法可以帮助(当然,如果您愿意,也可以将其应用于短表)。

由于您没有提供 MWE,我完全发明了表格,您必须根据您的需要对其进行调整。

使用选项outfile={...}pgfplotstable包允许从 .csv 创建表代码。例如,以下代码创建mytable.tex

\documentclass{article}
\usepackage{pgfplotstable} 
\usepackage{array}
\usepackage{siunitx}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
\renewcommand{\arraystretch}{1.4}
\newcolumntype{U}{S[table-format=7, table-column-width=4em]}
\usepackage{longtable}
\usepackage{booktabs}
\usepackage{caption}
\captionsetup{labelfont=bf, textfont=bf, labelsep=endash, 
    justification=centering}
\usepackage{filecontents}
\begin{filecontents*}{mydata.csv}
    number,description
    12342,I have used \texttt{siunitx} for the first column and centered the second column only to show the various possibilities
    2345365,{Of course, you have to set the columns according to your needs}
    557484,Some long long long long long long long long long long long long long long long long long long long long long long long long long long long long text
    12342,Some text
    2345365,Some text
    557484,Some long long long long long long long long long long long long long long long long long long long long long long long long long long long long text
    12342,Some text
    2345365,Some text
    557484,Some long long long long long long long long long long long long long long long long long long long long long long long long long long long long text
    12342,Some text
    2345365,Some text
    557484,Some long long long long long long long long long long long long long long long long long long long long long long long long long long long long text    
    12342,Some text
    2345365,Some text
    557484,Some long long long long long long long long long long long long long long long long long long long long long long long long long long long long text
    12342,Some text
    2345365,Some text
    557484,Some long long long long long long long long long long long long long long long long long long long long long long long long long long long long text
    12342,Some text
    2345365,Some text
    557484,Some long long long long long long long long long long long long long long long long long long long long long long long long long long long long text
    12342,Some text
    2345365,Some text
    557484,Some long long long long long long long long long long long long long long long long long long long long long long long long long long long long text
    12342,Some text
    2345365,Some text
    557484,Some long long long long long long long long long long long long long long long long long long long long long long long long long long long long text    
    12342,Some text
    2345365,Some text
    557484,Some long long long long long long long long long long long long long long long long long long long long long long long long long long long long text    
\end{filecontents*}

\begin{document}
    \pgfplotstabletypeset[
        begin table=\begin{longtable},
        end table=\end{longtable},
        outfile={mytable.tex}, % table code
        col sep=comma,
        string type,
        columns/number/.style={
            column name={\multicolumn{1}{U}{\textbf{No}}}, 
            column type={U}
        },
        columns/description/.style={
            column name={\textbf{Description}}, 
            column type={C{.7\textwidth}}
        },
        every head row/.style={before row=\midrule, after row=\midrule},
        %every last row/.style={after row=\midrule},
        every head row/.append style={before row={% 
                \caption{My caption}\label{tab:mylab}\\
                \toprule
                \endfirsthead
                \multicolumn{2}{l}{{\dots continued from previous page}}\\
                \toprule
                \multicolumn{1}{U}{\textbf{No}} & \multicolumn{1}{C{.7\textwidth}}{\textbf{Description}} \\ 
                \midrule
                \endhead
                \midrule
                \multicolumn{2}{r}{{\dots continued on next page}} \\ 
                \endfoot %
                \bottomrule 
                \endlastfoot % 
            }
        }
        ]{mydata.csv}

\end{document}

这是mytable.tex

\begin {longtable}{UC{.7\textwidth }}%
\caption {My caption}\label {tab:mylab}\\ \toprule \endfirsthead \multicolumn {2}{l}{{\dots continued from previous page}}\\ \toprule \multicolumn {1}{U}{\textbf {No}} & \multicolumn {1}{C{.7\textwidth }}{\textbf {Description}} \\ \midrule \endhead \midrule \multicolumn {2}{r}{{\dots continued on next page}} \\ \endfoot \bottomrule \endlastfoot \multicolumn {1}{U}{\textbf {No}}&\textbf {Description}\\\midrule %
12342&I have used \texttt {siunitx} for the first column and centered the second column only to show the various possibilities\\%
2345365&Of course, you have to set the columns according to your needs\\%
557484&Some long long long long long long long long long long long long long long long long long long long long long long long long long long long long text\\%
12342&Some text\\%
2345365&Some text\\%
557484&Some long long long long long long long long long long long long long long long long long long long long long long long long long long long long text\\%
12342&Some text\\%
2345365&Some text\\%
557484&Some long long long long long long long long long long long long long long long long long long long long long long long long long long long long text\\%
12342&Some text\\%
2345365&Some text\\%
557484&Some long long long long long long long long long long long long long long long long long long long long long long long long long long long long text\\%
12342&Some text\\%
2345365&Some text\\%
557484&Some long long long long long long long long long long long long long long long long long long long long long long long long long long long long text\\%
12342&Some text\\%
2345365&Some text\\%
557484&Some long long long long long long long long long long long long long long long long long long long long long long long long long long long long text\\%
12342&Some text\\%
2345365&Some text\\%
557484&Some long long long long long long long long long long long long long long long long long long long long long long long long long long long long text\\%
12342&Some text\\%
2345365&Some text\\%
557484&Some long long long long long long long long long long long long long long long long long long long long long long long long long long long long text\\%
12342&Some text\\%
2345365&Some text\\%
557484&Some long long long long long long long long long long long long long long long long long long long long long long long long long long long long text\\%
12342&Some text\\%
2345365&Some text\\%
557484&Some long long long long long long long long long long long long long long long long long long long long long long long long long long long long text\\%
\end {longtable}%

现在您可以mytable.tex在主文档中输入:

\documentclass{article}
\usepackage{array}
\usepackage{siunitx}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
\renewcommand{\arraystretch}{1.4}
\newcolumntype{U}{S[table-format=7, table-column-width=4em]}
\usepackage{longtable}
\usepackage{booktabs}
\usepackage{caption}
\captionsetup{labelfont=bf, textfont=bf, labelsep=endash, 
    justification=centering}
\begin{document}
    \input{mytable.tex}
\end{document}

结果是:

在此处输入图片描述 在此处输入图片描述

答案2

如果问题是您无法提交带有包含数据的辅助文件的论文,则可以使用filecontents包将两个文件合并为一个。

您只能提交一个类似于以下内容的文件:

\documentclass{article}
\usepackage{filecontents}
\usepackage{csvsimple}
\usepackage{booktabs}
\usepackage{lmodern}

\begin{filecontents*}{mydata.csv}
land,group,amount
Bayern,A,1700
Baden-Württemberg,A,2300
Sachsen,B,1520
Thüringen,A,1900
Hessen,B,2100
\end{filecontents*}

\begin{document}
This is your paper contents.
\csvautobooktabular{mydata.csv}
\end{document}

数据包含在filecontents环境内的序言中。这意味着在处理您的文档时,mydata.csv将自动创建一个包含您的 cvs 数据的新文件,然后使用csvsimple命令进行处理。

在此处输入图片描述

注意:数据和命令取自csvsimple文档。

相关内容