Suppose a) you are preparing a LaTeX manual and you wanted to exemplify a table and its source code side by side and b) you thought about using tcolorbox
because of its features for handling similar situations (source code and its compiled result side by side or on top of each other etc.) with its listings
library.
The following works fine:
\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{listings,skins,xparse}
\begin{document}
\begin{tcblisting}{}
\begin{tabular}{lll}
\hline
texto & texto & texto\\
\hline
texto & texto & texto\\
\hline
\end{tabular}
\end{tcblisting}
\end{document}
However, if I wrap tabular
inside a table
environment, the compiled result doesn't show up (only the code):
\begin{tcblisting}{}
\begin{table}
\begin{tabular}{lll}
\hline
texto & texto & texto\\
\hline
texto & texto & texto\\
\hline
\end{tabular}
\end{table}
\end{tcblisting}
Of course my goal is not letting the table float: my goal is just to optimize space and appearance by showing the aforementioned elementary table example side by side with its visual output inside a tcolorbox
, as one can do with showexpl
:
\documentclass{article}
\usepackage[utf8]{inputenc}
\setlength{\belowcaptionskip}{2pt}
\usepackage{showexpl}
\begin{document}
\begin{LTXexample}
\begin{table}
\caption{A table}
\centering
\begin{tabular}{lll}
\hline
texto & texto & texto\\
\hline
texto & texto & texto\\
\hlin
\end{tabular}
\end{table}
\end{LTXexample}
\end{document}
Is there a way to make this work with tcolorbox
? If yes, how?
\begin{tcblisting}{listing only}
it works fine.minipages
or showing the code and then the actual table afterwards.table
, not thetabular
environment.