[Tex/LaTex] Automatic break line after multicolumn

line-breakingmacrosmulticolumntables

Is there a way to put \\ after multicolumn automatically, each time it appears in the code? Pseudocode would look like this:

\newcommand{\commandThatAddsBreaklines}
if(thereIsAMulticolumn == true)
    add '\\' after \multicolumn{}{}{a very long text that doesn´t even fit in my table}

I would like to know if it is even possible to do something like this, maybe someone has a idea. My code looks like this:

\documentclass[a4paper,12pt,oneside]{scrbook}
\usepackage[dutch]{babel}  %Quotes won't work without babel
\usepackage[utf8]{inputenc}   %This is very important!
\usepackage[T1]{fontenc}

\usepackage{graphicx}
\usepackage[pdfborder={0 0 0}, breaklinks=true, pdftex=true, raiselinks=true]{hyperref}
\usepackage{tabularx}
\newcolumntype{Y}{>{\raggedright}X}

\begin{document}
\section{Description}
\begin{tabularx}{\linewidth}{YY}\hline
\multicolumn{2}{c}{a very very very long text that doesn´t even fit in my table, so it must be a way to make the table automatically break the line}\\
\end{tabularx}
\end{document}

I am also looking for a way to fit the column into my table. It would be nice if someone could provide me some help with it, thanks in advance.

Best Answer

enter image description here

\documentclass[a4paper,12pt,oneside]{scrbook}
\usepackage[dutch]{babel}  %Quotes won't work without babel
%\usepackage[utf8]{inputenc}   %This is very important!
\usepackage[T1]{fontenc}


\usepackage{graphicx}
\usepackage[pdfborder={0 0 0}, breaklinks=true, pdftex=true, raiselinks=true]{hyperref}
\usepackage{tabularx}
\newcolumntype{Y}{>{\raggedright\arraybackslash}X}

\let\oldmc\multicolumn
\def\multicolumn#1#2#3{%
\oldmc{#1}{>{\hsize=\dimexpr#1\hsize+#1\tabcolsep+#1\tabcolsep-2\tabcolsep\relax\centering}X}{#3}\tabularnewline}

\begin{document}
\section{Description}

\noindent
\begin{tabularx}{\linewidth}{YY}\hline
\multicolumn{2}{c}{a very very very long text that doesn´t even fit in my table, so it must be a way to make the table automatically break the line}
\end{tabularx}
\end{document}