1

i have this code

\begin{table}[htbp]
  \centering
  \caption{Add caption}
    \begin{tabular}{|c|c|c|c|c|c|}
    \hline
    \multirow{3}[4]{*}{Tested Text} & \multicolumn{5}{c|}{\multirow{2}[2]{*}{         Training Text (tested text is not included)}}\\
          & \multicolumn{5}{c|}{} \\
\cline{2-6}          & BI    & IK    & MR    & MA    & TO \\
    \hline
    BI    &       &       &       &       &  \\
    \hline
    IK    &       &       &       &       &  \\
    \hline
    MR    &       &       &       &       &  \\
    \hline
    MA    &       &       &       &       &  \\
    \hline
    TO    &       &       &       &       &  \\
    \hline
    \end{tabular}%
  \label{tab:addlabelkiki}%
\end{table}%

I don't understand why last column is larger than other as shown in the figurepic?

any sugesstion

4 Answers 4

0

You can replace your code with:

\begin{table}[htbp]
  \centering
  \caption{Add caption}
    \begin{tabular}{|c|c|c|c|c|c|}
    \hline
    \multirow{3}[4]{*}{Tested Text} & \multicolumn{5}{c|}{Training Text }\\
          & \multicolumn{5}{c|}{(tested text is not included)} \\
\cline{2-6}          & BI    & IK    & MR    & MA    & TO \\
    \hline
    BI    &       &       &       &       &  \\
    \hline
    IK    &       &       &       &       &  \\
    \hline
    MR    &       &       &       &       &  \\
    \hline
    MA    &       &       &       &       &  \\
    \hline
    TO    &       &       &       &       &  \\
    \hline
    \end{tabular}%
  \label{tab:addlabelkiki}%
\end{table}%

In this way you split in two parts the sentence Training Text (tested text is not included) without wraping.

5

I am not really an expert in these matters, but since nobody else has really answered the question... Is it not that the extra width is needed for the "header" text in the \multicolumn box above?

When the table is put together, it goes through the preceding columns but because they are all empty they are just sized by the width of the two letters you have put in. It gets to the last column, and suddenly realises it needs to provide extra width to fit the remaining "header" text in. The answer given by @marchetto thus minimises the problem because you've shortened the "header" text. Equally, if you had longer text in the blank boxes, the column widths would be different. E.g.

\begin{table}[htbp]
  \centering
  \caption{Add caption}
    \begin{tabular}{|c|c|c|c|c|c|}
    \hline
    \multirow{3}[4]{*}{Tested Text} & \multicolumn{5}{c|}{\multirow{2}[2]{*}{Training Text (tested text is not included)}}\\
          & \multicolumn{5}{c|}{} \\
\cline{2-6}          & BI    & IK    & MR    & MA    & TO \\
    \hline
    BI    &     Here are  & some  & words &   in your columns &  \\
    \hline
    IK    &       &       &       &       &  \\
    \hline
    MR    &       &       &       &       &  \\
    \hline
    MA    &       &       &       &       &  \\
    \hline
    TO    &       &       &       &       &  \\
    \hline
    \end{tabular}%
  \label{tab:addlabelkiki}%
\end{table}%

You can force column widths by defining yourself some new column styles. I read how to do it somewhere on here so can't take any credit for the method, but here you go:

\documentclass[12pt, a4paper, oneside, fleqn]{report}

\usepackage{multirow} 
\usepackage{array}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}

\begin{document}

\begin{table}[htbp]
  \centering
  \caption{Add caption}
    \begin{tabular}{|c|C{1.5cm}|C{1.5cm}|C{1.5cm}|C{1.5cm}|C{1.5cm}|}
    \hline
    \multirow{3}[4]{*}{Tested Text} & \multicolumn{5}{c|}{\multirow{2}[2]{*}{Training Text (tested text is not included)}}\\
          & \multicolumn{5}{c|}{} \\
\cline{2-6}          & BI    & IK    & MR    & MA    & TO \\
    \hline
    BI    &       &       &       &       &  \\
    \hline
    IK    &       &       &       &       &  \\
    \hline
    MR    &       &       &       &       &  \\
    \hline
    MA    &       &       &       &       &  \\
    \hline
    TO    &       &       &       &       &  \\
    \hline
    \end{tabular}%
  \label{tab:addlabelkiki}%
\end{table}%

\end{document}
1

With {NiceTabular} of nicematrix (≥ 6.28a).

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

\begin{NiceTabular}{cc}[hvlines,&-in-blocks]
\Block{2-1}{Tested Text} & Training Text (tested text is not included) \\
                         & \Block{}{BI&IK&MR&MA&TO} \\
BI                       & \Block{}{  &  &  &  &  } \\
IK                       & \Block{}{  &  &  &  &  } \\
MR                       & \Block{}{  &  &  &  &  } \\
MA                       & \Block{}{  &  &  &  &  } \\
TO                       & \Block{}{  &  &  &  &  } \\
\end{NiceTabular}

\end{document}

Output of the above code

0

Today this table is simple to write ... with \tblr of tabularray package you can simple prescribe columns width and split long text into two (or more) lines. The MWE for this table is:

\documentclass{article}
\usepackage{tabularray}

\begin{document}
    \begin{table}[htbp]
    \centering
\caption{Add caption}
\label{tab:addlabelkiki}
    \begin{tblr}{hlines, vlines,
                 colspec = {c *{5}{Q[c, wd=2em]}},
                 cell{1}{1} = {r=2}{},
                 cell{1}{2} = {c=5}{}
                 }
Tested Text
    &   {Training Text\\
         (tested text is not included)} 
            &       &       &       &       \\
    & BI    & IK    & MR    & MA    & TO    \\
BI  &       &       &       &       &       \\
IK  &       &       &       &       &       \\
MR  &       &       &       &       &       \\
MA  &       &       &       &       &       \\
TO  &       &       &       &       &       \\
\end{tblr}
    \end{table}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .