Is tcolorbox compatible with tabular, tabularx?

Some combination betwen tcolorbox, listing and tabularx tabular do not compile.

Is it possible to solve problem between tabular tabularx and tcolorbox and tabularx and listing?

Is tcolorbox compatible with tabular, tabularx?

Below is a MWE

\documentclass{book}
%mwe_clisting3

\usepackage{ae,lmodern} % ou seulement l'un, ou l'autre, ou times etc.
\usepackage[english,french]{babel}
\usepackage[utf8]{inputenc}
%%% Note that this is font encoding (determines what kind of font is used), not input encoding. 
\usepackage[T1]{fontenc}
\usepackage[cyr]{aeguill}


\usepackage{tikz}
\tikzset{coltria/.style={fill=red!15!white}}
\usepackage{tcolorbox}
\usepackage{multirow}
\usepackage{tabularx}
\usepackage{longtable}
\tcbuselibrary{listings,breakable,skins,documentation,xparse}
\lstdefinestyle{Clst}{     
	numbers=left, 
	numberstyle=\small, 
	numbersep=8pt, 
	frame = none, 
	language=C, 
	framexleftmargin=5pt,			 % la marge à  gauche du code
	% test pour améliorer la présentation du code
	upquote=true,
	columns=flexible,
	basicstyle=\ttfamily,
	basicstyle=\small, % ==> semble optimal \tiny est vraiment trop petit
	% provoque une erreur texcsstyle=*\color{blue},
	commentstyle=\color{green},    % comment style
	keywordstyle=\color{blue},       % keyword style
	rulecolor=\color{black},         % if not set, the frame-color may be changed on line-breaks within not-black text (e.g. comments (green here))
	showspaces=false,                % show spaces everywhere adding particular underscores; it overrides 'showstringspaces'		
	showtabs=false,                  % show tabs within strings adding particular underscores
	stringstyle=\color{cyan},     % string literal style
	numbers=none, 
	tabsize=4,
	% pour couper les lignes trop longues
	breaklines,
	breakindent=1.5em, %?indente?de?3?caracteres?vers?la?droite
}
\newtcblisting{Clisting}[2][]{empty,breakable,leftrule=5mm,left=2mm,
	%frame style={fill,top color=red!75!black,bottom color=red!75!black,middle color=red},
	frame style={fill,top color=green!75!black,bottom color=green!75!black,middle color=green},
	listing only,
	listing engine=listings, 
	listing options={style=Clst,tabsize=4,breaklines,
		breakindent=1.5em,columns=fullflexible},
	%		keywordstyle=\color{red}},
	colback=yellow!15!white,
	% code for unbroken boxes:
	frame code={\path[tcb fill frame] (frame.south west)--(frame.north west)
		--([xshift=-5mm]frame.north east)--([yshift=-5mm]frame.north east)
		--([yshift=5mm]frame.south east)--([xshift=-5mm]frame.south east)--cycle; },
	interior code={\path[tcb fill interior] (interior.south west)--(interior.north west)
		--([xshift=-4.8mm]interior.north east)--([yshift=-4.8mm]interior.north east)
		--([yshift=4.8mm]interior.south east)--([xshift=-4.8mm]interior.south east)
		--cycle; },
	attach boxed title to top center={yshift=-2mm},
	title=\fcolorbox{black}{black}{\red{#2}},
	% code for the first part of a break sequence:
	skin first is subskin of={emptyfirst}{%
		frame code={\path[tcb fill frame] (frame.south west)--(frame.north west)
			--([xshift=-5mm]frame.north east)--([yshift=-5mm]frame.north east)
			--(frame.south east)--cycle;
			\path[coltria] ([xshift=2.5mm,yshift=1mm]frame.south west) -- +(120:2mm)
			-- +(60:2mm)-- cycle; },
		interior code={\path[tcb fill interior] (interior.south west|-frame.south)
			--(interior.north west)--([xshift=-4.8mm]interior.north east)
			--([yshift=-4.8mm]interior.north east)--(interior.south east|-frame.south)
			--cycle; },
	},%
	% code for the middle part of a break sequence:
	skin middle is subskin of={emptymiddle}{%
		frame code={\path[tcb fill frame] (frame.south west)--(frame.north west)
			--(frame.north east)--(frame.south east)--cycle;
			\path[coltria] ([xshift=2.5mm,yshift=-1mm]frame.north west) -- +(240:2mm)
			-- +(300:2mm) -- cycle;
			\path[coltria] ([xshift=2.5mm,yshift=1mm]frame.south west) -- +(120:2mm)
			-- +(60:2mm) -- cycle;
		},
		interior code={\path[tcb fill interior] (interior.south west|-frame.south)
			--(interior.north west|-frame.north)--(interior.north east|-frame.north)
			--(interior.south east|-frame.south)--cycle; },
	},
	% code for the last part of a break sequence:
	skin last is subskin of={emptylast}{%
		frame code={\path[tcb fill frame] (frame.south west)--(frame.north west)
			--(frame.north east)--([yshift=5mm]frame.south east)
			--([xshift=-5mm]frame.south east)--cycle;
			\path[coltria] ([xshift=2.5mm,yshift=-1mm]frame.north west) -- +(240:2mm)
			-- +(300:2mm) -- cycle;
		},
		interior code={\path[tcb fill interior] (interior.south west)
			--(interior.north west|-frame.north)--(interior.north east|-frame.north)
			--([yshift=4.8mm]interior.south east)--([xshift=-4.8mm]interior.south east)
			--cycle; },#1}}

\begin{document}

\begin{lstlisting} [xleftmargin=5 pt,frame=single]
g_action_map_add_action (
G_ACTION_MAP (app), 
G_ACTION (new_action));
g_action_map_add_action (
G_ACTION_MAP (app), 
G_ACTION (open_action));
\end{lstlisting}

\begin{Clisting} {title}
g_action_map_add_action (
G_ACTION_MAP (app), 
G_ACTION (new_action));
g_action_map_add_action (
G_ACTION_MAP (app), 
G_ACTION (open_action));
\end{Clisting}
 first table ok with tabular

\begin{tabular}{|p{4cm}| p{10cm}|}
	\hline
	\textbf{Questions}& 	\textbf{Réponses}\\ 
	\hline	
	text&
	text
	\begin{lstlisting} [xleftmargin=5 pt]
	g_action_map_add_action (
	G_ACTION_MAP (app), 
	G_ACTION (new_action));
	g_action_map_add_action (
	G_ACTION_MAP (app), 
	G_ACTION (open_action));
	\end{lstlisting}\\
	\hline	
\end{tabular}
\bigskip

second table no ok with tcolobox

\begin{tabular}{|p{4cm}| p{10cm}|}
	\hline
	\textbf{Questions}& 	\textbf{Réponses}\\ 
	\hline	
	text&
	text
	
%	\begin{Clisting} {titre}
%	g_action_map_add_action (
%	G_ACTION_MAP (app), 
%	G_ACTION (new_action));
%	g_action_map_add_action (
%	G_ACTION_MAP (app), 
%	G_ACTION (open_action));
%	\end{Clisting}
\\
	\hline	
\end{tabular}
\bigskip

thirth table no ok with listing

\noindent\begin{tabularx}{\linewidth}{|p{6cm}| X |}
	\hline
	\textbf{Questions}& 	\textbf{Réponses}\\ 
	\hline	
	text&  text
	 
%	\begin{lstlisting} [xleftmargin=5 pt]
%	g_action_map_add_action (
%	G_ACTION_MAP (app), 
%	G_ACTION (new_action));
%	g_action_map_add_action (
%	G_ACTION_MAP (app), 
%	G_ACTION (open_action));
%	\end{lstlisting}
\\
		\hline	
\end{tabularx}
\bigskip

fourth table no ok with tcolorbox


\noindent\begin{tabular}{|p{6cm}| p{10cm} |}
	\hline
	\textbf{Questions}& 	\textbf{Réponses}\\ 
	\hline	
	text&  text
	
	%	\begin{Clisting} {titre}
	%	g_action_map_add_action (
	%	G_ACTION_MAP (app), 
	%	G_ACTION (new_action));
	%	g_action_map_add_action (
	%	G_ACTION_MAP (app), 
	%	G_ACTION (open_action));
	%	\end{Clisting}
	\\
	\hline	
\end{tabular}
\bigskip
\end{document}

A lot of error appear after compiling with pdflatex, xelatex, etc...

Answers

The syntax \red is simply wrong. If replaced with proper syntax, e.g. \color{red} it compiles fine:

\documentclass{book}
%mwe_clisting3

\usepackage{ae,lmodern} % ou seulement l'un, ou l'autre, ou times etc.
\usepackage[english,french]{babel}
\usepackage[utf8]{inputenc}
%%% Note that this is font encoding (determines what kind of font is used), not input encoding. 
\usepackage[T1]{fontenc}
\usepackage[cyr]{aeguill}


\usepackage{adjustbox}

\usepackage{tikz}
\tikzset{coltria/.style={fill=red!15!white}}
\usepackage{tcolorbox}
\usepackage{multirow}
\usepackage{tabularx}
\usepackage{longtable}
\tcbuselibrary{listings,breakable,skins,documentation,xparse}
\lstdefinestyle{Clst}{     
    numbers=left, 
    numberstyle=\small, 
    numbersep=8pt, 
    frame = none, 
    language=C, 
    framexleftmargin=5pt,            % la marge à  gauche du code
    % test pour améliorer la présentation du code
    upquote=true,
    columns=flexible,
    basicstyle=\ttfamily,
    basicstyle=\small, % ==> semble optimal \tiny est vraiment trop petit
    % provoque une erreur texcsstyle=*\color{blue},
    commentstyle=\color{green},    % comment style
    keywordstyle=\color{blue},       % keyword style
    rulecolor=\color{black},         % if not set, the frame-color may be changed on line-breaks within not-black text (e.g. comments (green here))
    showspaces=false,                % show spaces everywhere adding particular underscores; it overrides 'showstringspaces'        
    showtabs=false,                  % show tabs within strings adding particular underscores
    stringstyle=\color{cyan},     % string literal style
    numbers=none, 
    tabsize=4,
    % pour couper les lignes trop longues
    breaklines,
    breakindent=1.5em, %?indente?de?3?caracteres?vers?la?droite
}
\newtcblisting{Clisting}[2][]{empty,breakable,leftrule=5mm,left=2mm,
    %frame style={fill,top color=red!75!black,bottom color=red!75!black,middle color=red},
    frame style={fill,top color=green!75!black,bottom color=green!75!black,middle color=green},
    listing only,
    listing engine=listings, 
    listing options={style=Clst,tabsize=4,breaklines,
        breakindent=1.5em,columns=fullflexible},
    %       keywordstyle=\color{red}},
    colback=yellow!15!white,
    % code for unbroken boxes:
    frame code={\path[tcb fill frame] (frame.south west)--(frame.north west)
        --([xshift=-5mm]frame.north east)--([yshift=-5mm]frame.north east)
        --([yshift=5mm]frame.south east)--([xshift=-5mm]frame.south east)--cycle; },
    interior code={\path[tcb fill interior] (interior.south west)--(interior.north west)
        --([xshift=-4.8mm]interior.north east)--([yshift=-4.8mm]interior.north east)
        --([yshift=4.8mm]interior.south east)--([xshift=-4.8mm]interior.south east)
        --cycle; },
    attach boxed title to top center={yshift=-2mm},
    title=\fcolorbox{black}{black}{\color{red}{#2}},
    % code for the first part of a break sequence:
    skin first is subskin of={emptyfirst}{%
        frame code={\path[tcb fill frame] (frame.south west)--(frame.north west)
            --([xshift=-5mm]frame.north east)--([yshift=-5mm]frame.north east)
            --(frame.south east)--cycle;
            \path[coltria] ([xshift=2.5mm,yshift=1mm]frame.south west) -- +(120:2mm)
            -- +(60:2mm)-- cycle; },
        interior code={\path[tcb fill interior] (interior.south west|-frame.south)
            --(interior.north west)--([xshift=-4.8mm]interior.north east)
            --([yshift=-4.8mm]interior.north east)--(interior.south east|-frame.south)
            --cycle; },
    },%
    % code for the middle part of a break sequence:
    skin middle is subskin of={emptymiddle}{%
        frame code={\path[tcb fill frame] (frame.south west)--(frame.north west)
            --(frame.north east)--(frame.south east)--cycle;
            \path[coltria] ([xshift=2.5mm,yshift=-1mm]frame.north west) -- +(240:2mm)
            -- +(300:2mm) -- cycle;
            \path[coltria] ([xshift=2.5mm,yshift=1mm]frame.south west) -- +(120:2mm)
            -- +(60:2mm) -- cycle;
        },
        interior code={\path[tcb fill interior] (interior.south west|-frame.south)
            --(interior.north west|-frame.north)--(interior.north east|-frame.north)
            --(interior.south east|-frame.south)--cycle; },
    },
    % code for the last part of a break sequence:
    skin last is subskin of={emptylast}{%
        frame code={\path[tcb fill frame] (frame.south west)--(frame.north west)
            --(frame.north east)--([yshift=5mm]frame.south east)
            --([xshift=-5mm]frame.south east)--cycle;
            \path[coltria] ([xshift=2.5mm,yshift=-1mm]frame.north west) -- +(240:2mm)
            -- +(300:2mm) -- cycle;
        },
        interior code={\path[tcb fill interior] (interior.south west)
            --(interior.north west|-frame.north)--(interior.north east|-frame.north)
            --([yshift=4.8mm]interior.south east)--([xshift=-4.8mm]interior.south east)
            --cycle; },#1}
            }

\begin{document}

\begin{lstlisting} [xleftmargin=5 pt,frame=single]
g_action_map_add_action (
G_ACTION_MAP (app), 
G_ACTION (new_action));
g_action_map_add_action (
G_ACTION_MAP (app), 
G_ACTION (open_action));
\end{lstlisting}

\begin{Clisting} {title}
g_action_map_add_action (
G_ACTION_MAP (app), 
G_ACTION (new_action));
g_action_map_add_action (
G_ACTION_MAP (app), 
G_ACTION (open_action));
\end{Clisting}
 first table ok with tabular

\begin{tabular}{|p{4cm}| p{10cm}|}
    \hline
    \textbf{Questions}&     \textbf{Réponses}\\ 
    \hline  
    text&
    text
    \begin{lstlisting} [xleftmargin=5 pt]
    g_action_map_add_action (
    G_ACTION_MAP (app), 
    G_ACTION (new_action));
    g_action_map_add_action (
    G_ACTION_MAP (app), 
    G_ACTION (open_action));
    \end{lstlisting}\\
    \hline  
\end{tabular}
\bigskip

second table no ok with tcolobox

\begin{tabular}{|p{4cm}| p{10cm}|}
    \hline
    \textbf{Questions}&     \textbf{Réponses}\\ 
    \hline  
    text&
    text

   \begin{Clisting} {titre}
   g_action_map_add_action (
   G_ACTION_MAP (app), 
   G_ACTION (new_action));
   g_action_map_add_action (
   G_ACTION_MAP (app), 
   G_ACTION (open_action));
   \end{Clisting}
\\
    \hline  
\end{tabular}
\bigskip

thirth table no ok with listing

\noindent\begin{tabularx}{\linewidth}{|p{6cm}| X |}
    \hline
    \textbf{Questions}&     \textbf{Réponses}\\ 
    \hline  
    text&  text

   \begin{lstlisting}[xleftmargin=5 pt]^^J
   g_action_map_add_action (^^J
   G_ACTION_MAP (app), ^^J
   G_ACTION (new_action));^^J
   g_action_map_add_action (^^J
   G_ACTION_MAP (app), ^^J
   G_ACTION (open_action));^^J
   \end{lstlisting}
\\
        \hline  
\end{tabularx}
\bigskip

fourth table no ok with tcolorbox


\noindent\begin{tabular}{|p{6cm}| p{10cm} |}
    \hline
    \textbf{Questions}&     \textbf{Réponses}\\ 
    \hline  
    text&  text

       \begin{Clisting} {titre}
       g_action_map_add_action (
       G_ACTION_MAP (app), 
       G_ACTION (new_action));
       g_action_map_add_action (
       G_ACTION_MAP (app), 
       G_ACTION (open_action));
       \end{Clisting}
    \\
    \hline  
\end{tabular}
\bigskip
\end{document}

enter image description here

Posted on by samcarter_is_at_topanswers.xyz