在 colorbox 中,输入{table.tex} 失败并带有标题,但没有标题则成功

在 colorbox 中,输入{table.tex} 失败并带有标题,但没有标题则成功

请注意,这些table.tex是通过每个表的注释中给出的实际命令caption_table.tex生成的。pandas.DataFrame.to_latex()

可接受的解决方案将省略对这些表的任何手动编辑。

MWE 1.(无标题,工作正常):

$ pdflatex test.tex

测试.tex:

\documentclass{article}
% formatting
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[most]{tcolorbox}


% figures
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}

% tables
\usepackage{pgfplotstable}
\usepackage[shortlabels]{enumitem}
\usepackage{booktabs}

% date
\usepackage[mmddyyyy]{datetime}

\begin{document}

\section*{section with table}
\begin{tcolorbox}[colback=yellow!10!white,colframe=black]
  \textit{min, max, mean, variance of all features.}
  \tcblower
  \input{table.tex}
\end{tcolorbox}

\end{document}

表格.tex:

% command to generate
% pd.DataFrame(
%     {
%         "mean":np.mean(X,axis=0),\
%         "var":np.var(X,axis=0),\
%         "max":np.max(X,axis=0),\
%         "min":np.min(X,axis=0)
%     }).to_latex(buf="table.tex")

\begin{tabular}{lrrrr}
\toprule
{} &         mean &           var &        max &        min \\
\midrule
0  &   241.601104 &  8.349917e+01 &    253.000 &  193.50000 \\
1  &   227.376571 &  9.262559e+01 &    249.000 &  152.50000 \\
2  &   241.554150 &  3.528634e+01 &    252.500 &  214.25000 \\
3  &   232.826768 &  9.762573e+01 &    252.500 &  152.50000 \\
4  &  3089.923365 &  1.565151e+07 &  31048.000 &   10.00000 \\
5  &   928.259020 &  3.081762e+06 &  13630.000 &    0.00000 \\
6  &   138.093830 &  4.439517e+05 &   9238.000 &    0.00000 \\
7  &     3.248579 &  8.219485e+00 &    125.170 &    0.00000 \\
8  &     6.498653 &  6.405048e+00 &     19.167 &    0.87589 \\
9  &     2.097139 &  4.363440e+00 &     13.230 &    0.00000 \\
10 &     4.217660 &  4.086372e+00 &     66.761 &    0.00000 \\
11 &     2.691718 &  2.198778e+00 &     73.902 &    0.00000 \\
12 &    10.271590 &  4.046462e+02 &    975.040 &    0.99049 \\
13 &     5.781481 &  3.406521e+03 &    797.200 & -999.90000 \\
\bottomrule
\end{tabular}

输出:

在此处输入图片描述

MWE 2.(带标题,编译器错误):

$ pdflatex test_caption.tex

测试标题.tex:

\documentclass{article}
% formatting
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[most]{tcolorbox}


% figures
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}

% tables
\usepackage{pgfplotstable}
\usepackage[shortlabels]{enumitem}
\usepackage{booktabs}

% date
\usepackage[mmddyyyy]{datetime}

\begin{document}

\section*{section with table}
\begin{tcolorbox}[colback=yellow!10!white,colframe=black]
  \textit{min, max, mean, variance of all features.}
  \tcblower
  \input{caption_table.tex}
\end{tcolorbox}

\end{document}

标题表.tex:

% command to generate
% pd.DataFrame(
%     {
%         "mean":np.mean(X,axis=0),\
%         "var":np.var(X,axis=0),\
%         "max":np.max(X,axis=0),\
%         "min":np.min(X,axis=0)
%     }).to_latex(buf="caption_table.tex",\
%                 caption="this is a caption")


\begin{table}
\centering
\caption{this is a caption}
\begin{tabular}{lrrrr}
\toprule
{} &         mean &           var &        max &        min \\
\midrule
0  &   241.601104 &  8.349917e+01 &    253.000 &  193.50000 \\
1  &   227.376571 &  9.262559e+01 &    249.000 &  152.50000 \\
2  &   241.554150 &  3.528634e+01 &    252.500 &  214.25000 \\
3  &   232.826768 &  9.762573e+01 &    252.500 &  152.50000 \\
4  &  3089.923365 &  1.565151e+07 &  31048.000 &   10.00000 \\
5  &   928.259020 &  3.081762e+06 &  13630.000 &    0.00000 \\
6  &   138.093830 &  4.439517e+05 &   9238.000 &    0.00000 \\
7  &     3.248579 &  8.219485e+00 &    125.170 &    0.00000 \\
8  &     6.498653 &  6.405048e+00 &     19.167 &    0.87589 \\
9  &     2.097139 &  4.363440e+00 &     13.230 &    0.00000 \\
10 &     4.217660 &  4.086372e+00 &     66.761 &    0.00000 \\
11 &     2.691718 &  2.198778e+00 &     73.902 &    0.00000 \\
12 &    10.271590 &  4.046462e+02 &    975.040 &    0.99049 \\
13 &     5.781481 &  3.406521e+03 &    797.200 & -999.90000 \\
\bottomrule
\end{tabular}
\end{table}

测试标题.log:

LaTeX Font Info:    Checking defaults for OML/cmm/m/it on input line 21.
LaTeX Font Info:    ... okay on input line 21.
LaTeX Font Info:    Checking defaults for OMS/cmsy/m/n on input line 21.
LaTeX Font Info:    ... okay on input line 21.
LaTeX Font Info:    Checking defaults for OT1/cmr/m/n on input line 21.
LaTeX Font Info:    ... okay on input line 21.
LaTeX Font Info:    Checking defaults for T1/cmr/m/n on input line 21.
LaTeX Font Info:    ... okay on input line 21.
LaTeX Font Info:    Checking defaults for TS1/cmr/m/n on input line 21.
LaTeX Font Info:    ... okay on input line 21.
LaTeX Font Info:    Checking defaults for OMX/cmex/m/n on input line 21.
LaTeX Font Info:    ... okay on input line 21.
LaTeX Font Info:    Checking defaults for U/cmr/m/n on input line 21.
LaTeX Font Info:    ... okay on input line 21.
 ABD: EveryShipout initializing macros
(/usr/share/texlive/texmf-dist/tex/context/base/mkii/supp-pdf.mkii
[Loading MPS to PDF converter (version 2006.09.02).]
\scratchcounter=\count339
\scratchdimen=\dimen296
\scratchbox=\box77
\nofMPsegments=\count340
\nofMParguments=\count341
\everyMPshowfont=\toks48
\MPscratchCnt=\count342
\MPscratchDim=\dimen297
\MPnumerator=\count343
\makeMPintoPDFobject=\count344
\everyMPtoPDFconversion=\toks49
) (/usr/share/texlive/texmf-dist/tex/latex/epstopdf-pkg/epstopdf-base.sty
Package: epstopdf-base 2020-01-24 v2.11 Base part for package epstopdf

(/usr/share/texlive/texmf-dist/tex/latex/grfext/grfext.sty
Package: grfext 2019/12/03 v1.3 Manage graphics extensions (HO)

(/usr/share/texlive/texmf-dist/tex/generic/kvdefinekeys/kvdefinekeys.sty
Package: kvdefinekeys 2019-12-19 v1.6 Define keys (HO)
))
(/usr/share/texlive/texmf-dist/tex/latex/kvoptions/kvoptions.sty
Package: kvoptions 2019/11/29 v3.13 Key value format for package options (HO)

(/usr/share/texlive/texmf-dist/tex/generic/kvsetkeys/kvsetkeys.sty
Package: kvsetkeys 2019/12/15 v1.18 Key value parser (HO)
))
Package epstopdf-base Info: Redefining graphics rule for `.eps' on input line 4
85.
Package grfext Info: Graphics extension search list:
(grfext)             [.pdf,.png,.jpg,.mps,.jpeg,.jbig2,.jb2,.PDF,.PNG,.JPG,.JPE
G,.JBIG2,.JB2,.eps]
(grfext)             \AppendGraphicsExtensions on input line 504.

(/usr/share/texlive/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg
File: epstopdf-sys.cfg 2010/07/13 v1.3 Configuration of (r)epstopdf for TeX Liv
e
))
\c@lstlisting=\count345
Package caption Info: Begin \AtBeginDocument code.
Package caption Info: End \AtBeginDocument code.


Package pgfplots Warning: running in backwards compatibility mode (unsuitable t
ick labels; missing features). Consider writing \pgfplotsset{compat=1.16} into 
your preamble.
 on input line 21.

(/usr/share/texlive/texmf-dist/tex/latex/fmtcount/fc-english.def
File: fc-english.def 2016/01/12
)
(./caption_table.tex

! LaTeX Error: Not in outer par mode.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.2 \centering
              
? 
! Undefined control sequence.
\caption@ORI@xfloat ... \global \setbox \@currbox 
                                                  \color@vbox \normalcolor \...
l.2 \centering
              
? 
! Missing number, treated as zero.
<to be read again> 
                   \vbox 
l.2 \centering
              
? 
) [1

答案1

“不在外部 par 模式”错误意味着您在某个框内使用了table(或其他浮动环境,例如figure)。浮动的唯一目的是将其内容标记为不在主文档流中,而是一个可以重新定位和重新插入的插入内容,以帮助分页。这种浮动行为在结构上与位于特定页面固定点的框内不兼容。

这里的盒子是这样的,\begin{tcolorbox}里面不能有任何浮子。

在 tcolorbox 手册中搜索caption建议你可以使用它的blend into键来合并一些table环境功能。但更简单的是,table根本不要使用,只需tabular然后用

\captionof{table}{this is a caption}

\captionof其中来自或caption(单行)capt-of包。

相关内容