多列后自动换行

多列后自动换行

有没有办法\\在代码中每次出现多列时自动将其放在后面?伪代码如下所示:

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

我想知道是否有可能做这样的事情,也许有人有主意。 我的代码如下所示:

\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}

我也在寻找一种方法来将列放入我的表中。如果有人能为我提供帮助,那就太好了,先谢谢了。

答案1

在此处输入图片描述

\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}

相关内容