1

I am using both multirow as well as tabularx and it works fine so far as the table size is correct and all rows and columns are nicely drawn. Yet the text breaking does not work properly. The image speaks for itself.

What am I doing wrong?

enter image description here

Thanks in advance for any tip or hint.

(Note: I did have a look at other question around the combination of tabularx and multirow, but did not find an answer that targets my problem)

\documentclass[]{scrbook}

\usepackage[a4paper]{geometry}
\usepackage{graphicx}   

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{ragged2e}
\usepackage{tabularx, multirow, booktabs, makecell}
\usepackage[flushleft]{threeparttable}




\begin{document}
\begin{table}[]
\centering
\begin{tabularx}{\textwidth}{|l|l|l|X|}
    \hline
    &Name&\multicolumn{2}{l|}{Details}\\ \hline

    \multirow{6}{*}{\rotatebox[origin=c]{90}{Attributes}} & 

    info{[}'name'{]}&\multicolumn{2}{l|}{"NAME"(string)}\\ \cline{2-4} 

    & 1  & \multicolumn{2}{X|}{"feature\_extraction" (string)}                                                                                                                                                                                \\ \cline{2-4} 
    & 2  & \multicolumn{2}{X|}{0 (integer)}   
    \\ \cline{2-4} 
    & 3  & \multicolumn{2}{X|}{long long long long long long long long text that should break and it does break but it breaks at the wrong position. Why does it break in this position. What can I do to make it break at the right position?}
    \\ \cline{2-4} 
    & 4  & \multicolumn{2}{l|}{0 (integer)}
    \\ \cline{2-4} 
    & 5 & \multicolumn{2}{l|}{0}  
    \\ \hline
    \multirow{6}{*}{\rotatebox[]{90}{Function}}  & \multirow{3}{*}{transform}      & Input       & X (\textit{numpy.array})                                                                                                                                                                                          \\ \cline{3-4} 
    &                            & Output      & Xt(\textit{numpy.array}) \\ \cline{3-4} 
    &                            & Explanation & long long long long long long long long text that should break and does break wonderfully. Everything should work out as fine as it does here.  \\ \hline
\end{tabularx}
\caption{Details of the feature extraction class}
\label{tab:feature_extraction}
\end{table} 
\end{document} 
  • It does exactly what it is suppose to. You cannot use X columns like that, note that you have two X columns, one normal one, which is the width that is used, and then you reuse it in a \multicolumn which as more space available. Sadly tabularx is not build with this in mind. – daleif Mar 5 '18 at 11:29
1

enter image description here

you need to redefine columns type to something as this:

\begin{tabularx}{\textwidth}{|l|l|
                             >{\hsize=0.2\hsize}X|
                             >{\hsize=0.8\hsize}X|}

(width of the third column had to be known in advance) and redefine width of \multicolumn cell to:

\multicolumn{2}{>{\hsize=\dimexpr\hsize+2\tabcolsep+\arrayrulewidth\relax}X|}

which now consider width of third and fourth columns (sum of their width is 0.2\hsize + 0.8\hsize=\hsize) and both \tabcolsep and \arrayrulewidth between merged cells. complete mwe:

\documentclass[]{scrbook}

\usepackage[a4paper]{geometry}
\usepackage{graphicx}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{ragged2e}
\usepackage{tabularx, multirow, booktabs, makecell}
\usepackage[flushleft]{threeparttable}

\begin{document}
\begin{table}[]
\centering
\begin{tabularx}{\textwidth}{|l|l|
                             >{\hsize=0.2\hsize}X|
                             >{\hsize=0.8\hsize}X|}
    \hline
    &Name&\multicolumn{2}{l|}{Details}\\ \hline

    \multirow{6}{*}{\rotatebox[origin=c]{90}{Attributes}} &

    info{[}'name'{]}&\multicolumn{2}{l|}{"NAME"(string)}\\ \cline{2-4}

    & 1  & \multicolumn{2}{X|}{"feature\_extraction" (string)}                                                                                                                                                                                \\ \cline{2-4}
    & 2  & \multicolumn{2}{X|}{0 (integer)}
    \\ \cline{2-4}
    & 3  &  \multicolumn{2}{>{\hsize=\dimexpr\hsize+2\tabcolsep+\arrayrulewidth\relax}X|}
            {long long long long long long long long text that should break and it does break but it breaks at the wrong position. Why does it break in this position. What can I do to make it break at the right position?}
    \\ \cline{2-4}
    & 4  & \multicolumn{2}{l|}{0 (integer)}
    \\ \cline{2-4}
    & 5 & \multicolumn{2}{l|}{0}
    \\ \hline
    \multirow{6}{*}{\rotatebox[]{90}{Function}}  & \multirow{3}{*}{transform}      & Input       & X (\textit{numpy.array})                                                                                                                                                                                          \\ \cline{3-4}
    &                            & Output      & Xt(\textit{numpy.array}) \\ \cline{3-4}
    &                            & Explanation & long long long long long long long long text that should break and does break wonderfully. Everything should work out as fine as it does here.  \\ \hline
\end{tabularx}
\caption{Details of the feature extraction class}
\label{tab:feature_extraction}
\end{table}
\end{document}
  • Why does that work? – daleif Mar 5 '18 at 11:31
  • it doesn't as i expected :-( – Zarko Mar 5 '18 at 11:32
  • @daleif, now, in corrected answer it works as i expected. however this is possible, if last two columns widths are known. – Zarko Mar 5 '18 at 11:41
  • Yes, you have to lock the third column, such that the width is now not self adjusting. But I still does not quite understand how this trick works. – daleif Mar 5 '18 at 11:54
  • @daleif, see rephrased explanation in edited answer. "trick" is that you need to define width of multicolumn cell. this is possible, if widths of merged cells are known. i'm not sure if my explanation is clear enough. – Zarko Mar 5 '18 at 12:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.