TransWikia.com

inside colorbox, input{table.tex} fails with caption but succeeds without caption

TeX - LaTeX Asked on January 8, 2021

Please note that these table.tex and caption_table.tex are generated via pandas.DataFrame.to_latex() with actual command given in the comments of each table.

An acceptable solution would omit any manual editing of these tables.

MWE 1. (no caption, working):

$ pdflatex test.tex

test.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}

table.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}

output:

enter image description here

MWE 2. (with caption, compiler error):

$ pdflatex test_caption.tex

test_caption.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}

caption_table.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}

test_caption.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

One Answer

The "not in outer par mode" error means that you have used the table (or other floating environment such as figure) inside some box. The only purpose of a float is to mark its content as not in the main document flow, but an insert that can be repositioned and re-inserted to help with page breaking. This floating behaviour is structurally incompatible with being inside a box at a fixed point on a specific page.

The box here is from begin{tcolorbox} you can not have any floats inside it.

Searching for caption in the tcolorbox manual suggests that you could use its blend into key to merge some table environment features. But simpler, do not use table at all, just tabular and then make the caption with

captionof{table}{this is a caption}

where captionof comes from the caption or (one-line) capt-of package.

Correct answer by David Carlisle on January 8, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP