[Tex/LaTex] Table does not fit within predefined margin and text does not wrap

multicolumnmultirowtables

I have a table where I needed multirow and multicolumns as part of my data representation. I am facing 2 problems at this moment:

  1. My table does not fit within the predefined margin [picture attached]
  2. If I try to fit the table within margin, the texts does not wrap

enter image description here

As you can see, the width of the page should be 6.97 inches. But my table goes beyond that.

Here is my original code that I am trying.

\begin{table*}
   \centering
   \caption{Results of Real Experiment}
   %\hskip-4.0cm
   \begin{tabular}{|c|c|c|c|c|}
       \hline
       \multirow{2}{*}{Sent Data} &
       \multirow{2}{*}{Settings} &
       \multirow{2}{*}{Functional logic}  &
       \multicolumn{2}{c|}{Received data}  \\
       \cline{4-5}
        & & & Valid Receiver & Intruder \\
        \hline
        \multirow{6}{*}{00001111} & \multirow{3}{*}{Without Titanium      Coating} & Fixed & 11110000 or 10110111 & 1111000 or 10110111 \\
       \cline{3-5}
       & & Deterministic Function & 00101110 or 10110111 & 00101110 or       10110111 \\
       \cline{3-5}
       & & Non-deterministic Function & 11110101 & 10101010 \\
       \cline{2-5}
       & \multirow{3}{*}{With Titanium Coating} & Fixed & 10110111 &      11110000 \\
       \cline{3-5}
       & & Deterministic Function & 10110111 & 00101110 \\
       \cline{3-5}
       & & Non-deterministic Function & 10110111 & Undefined Sequence \\
       \hline
     \end{tabular}
   \label{tab_results}
\end{table*}

I have tried changing the width of certain columns, and that produced problem 2. The texts do not wrap. Here is what I tried.

\begin{tabular}{|c|p{2.5cm}|c|p{3cm}|p{3cm}|}

I have kept rest of the code unchanged. Here is how it looked. Although it fits within the margin, but the spacing is untidy and not within the standards. The texts of adjacent columns overlap and does not wrap within the column.

enter image description here

I am using TexStudio. Any help and suggestions are greatly appreciated. Thanks!

Best Answer

I suggest you the following measures: - use makecell packages for typing multirow cells content - make shorter text in the third column (to omit word "Function" (is it realy neccessary?) - if you still have problems width table width, use smaller font size, for example \small.

With this you can obtain:

enter image description here

Complete code:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}

\usepackage{makecell,multirow}
\usepackage[margin=25mm]{geometry}

\usepackage[active,floats,tightpage]{preview}
\setlength\PreviewBorder{1em}

\begin{document}
\begin{table}[h]
   \centering
   \renewcommand{\arraystretch}{1.2}
 \caption{Results of Real Experiment}
   %\hskip-4.0cm
   \begin{tabular}{|c|c|c|c|c|}
       \hline
\multirowcell{2}{Sent Data} 
    &   \multirowcell{2}{Settings} 
        &   \multirowcell{2}{Functional logic}  
            &   \multicolumn{2}{c|}{Received data}  \\
            \cline{4-5}
    &   &   &   Valid Receiver  &   Intruder        \\
    \hline
\multirowcell{6}{00001111}
    &   \multirowcell{3}{Without\\ Titanium\\ Coating}
        &   Fixed   &   11110000 or 10110111    &   11110000 or 10110111    \\
    \cline{3-5}
    &   &   Deterministic
                    &   00101110 or 10110111    &   00101110 or 10110111    \\
    \cline{3-5}
    &   &    Non-deterministic
                    &   11110101                &   10101010                \\
    \cline{2-5}
    &   \multirowcell{3}{With\\ Titanium\\ Coating}
        &   Fixed   & 10110111                  &   11110000                \\
    \cline{3-5}
    &   &   Deterministic Function
                    &   10110111                &   00101110                \\
    \cline{3-5}
    &   &   Non-deterministic
                    &   10110111                &   Undefined Sequence      \\
    \hline
\end{tabular}
   \label{tab_results}
\end{table}
\end{document}

Since I use one column document, I omit figure*, which is necessary at two column document. Table width is 155mm. Check is this what you like to have.