TeX - LaTeX Asked by Anthony Hauser on December 28, 2020
How can I do to put a tabularx object inside a box?
Here is my code:
documentclass[11pt,a4paper]{article}
usepackage[utf8]{inputenc}
usepackage[english]{babel}
usepackage{amsmath}
usepackage{amsfonts}
usepackage{amssymb}
usepackage{tcolorbox}
usepackage{tabularx}
begin{document}
begin{tcolorbox}[colback=blue!5!white,colframe=blue!75!black,title=Title] Text
tcblower
begin{table}
caption{textbf{Title of the table.}}
fontsize{7}{9}selectfont
centering
renewcommand{arraystretch}{1.5}
begin{tabularx}{textwidth}{bb}
hline
textbf{Model} & textbf{Description}
hline
A & B
C & E
hline
end{tabularx}
label{table2}
end{table}
end{tcolorbox}
end{document}
The error message is:
LaTeX Error: Not in outer par mode.
Because it’s not possible to write a table inside a box. Even when I remove the table environment and only keep the tabularx environment I get the same error. Isn’t it possible to write a table inside a box?
The table environment always wants to be the outermost defined but will appear inside the box nevertheless:
documentclass[11pt,a4paper]{article} usepackage[utf8]{inputenc} usepackage[english]{babel} usepackage{amsmath} usepackage{amsfonts} usepackage{amssymb} usepackage{tcolorbox} usepackage{tabularx}
begin{document}
begin{table}
begin{tcolorbox}[colback=blue!5!white,colframe=blue!75!black,title=Title] Text
tcblower
fontsize{7}{9}selectfont
centering
renewcommand{arraystretch}{1.5}
begin{tabularx}{textwidth}{ll}
hline
textbf{Model} & textbf{Description}
hline
A & B
C & E
hline
end{tabularx}
caption{textbf{Title of the table.}}
label{table2}
end{tcolorbox}
end{table}
end{document}
Edit: Also note that tabularx
usually only takes {l}
and/or {X}
without more complex definitions of alignment/width.
Correct answer by Plergux on December 28, 2020
A table
is a floating environment which usually contains a tabular
. What I suppose you want is just a tabular
with a caption
which can be easily written forgetting the external table
environment. In this case the caption
can be written with the captionof
command from capt-of
package.
documentclass[11pt,a4paper]{article}
usepackage[utf8]{inputenc}
usepackage[english]{babel}
usepackage{amsmath}
usepackage{amsfonts}
usepackage{amssymb}
usepackage{tcolorbox}
usepackage{tabularx}
usepackage{capt-of}
begin{document}
begin{tcolorbox}[colback=blue!5!white,colframe=blue!75!black,title=Title] Text
tcblower
captionof{table}{textbf{Title of the table.}}label{table2}
fontsize{7}{9}selectfont
centering
renewcommand{arraystretch}{1.5}
begin{tabularx}{textwidth}{lX}
hline
textbf{Model} & textbf{Description}
hline
A & B
C & E
hline
end{tabularx}
end{tcolorbox}
end{document}
Answered by Ignasi on December 28, 2020
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP