2

I am trying to create table as below, in Texmaker.

enter image description here.

here i am facing following issues.

  1. To wrap text the column headers from 4 to 6 and align it center.
  2. Hspace on paragraph [row 3 last column] is not working
  3. Last multirow contains a element from its earlier row.

screen shot below. issues are highlighted in red box

enter image description here

Below is the complete code... Please help me to resolve these issues.


\documentclass[12pt,a4paper,titlepage]{report}
\usepackage{array}
\usepackage{booktabs, multicol, multirow}
\usepackage{color, textcomp, listings}
\usepackage{rotating}
\usepackage[table]{xcolor}
\usepackage{pbox}

\begin{document}
% Table generated by Excel2LaTeX from sheet 'All Exp Table'
\begin{table}[!htbp]
  \centering
      \renewcommand\baselinestretch{1}\normalsize
      \renewcommand{\arraystretch}{1.2}
    \begin{tabular}{|c|c|c|m{.5 cm}|m {.5 cm}|m{.5 cm}|m {10.5 cm}|}
\hline
    {\begin{sideways} {\centering { Rule No} } \end{sideways}}& {\begin{sideways} {\centering { F\_offsetFlag } } \end{sideways}} & {\begin{sideways} {\centering { B\_offsetFlag } } \end{sideways}} &      \multicolumn{1}{m {.5 cm}}{\begin{sideways} { F\_offsetDiff Relation  MaxBlkSize} \end{sideways}} & 
\multicolumn{1}{m {.5 cm}}{\begin{sideways} { B\_offsetDiff (Relation) MaxBlkSize} \end{sideways}} &
\multicolumn{1}{m {.5 cm}}{\begin{sideways} { F\_offsetDiff (Relation) B\_offsetDiff } \end{sideways}} &  {\textbf{Action}} \\     \hline
    1     & F     & F     & $<$     &  & =     & \pbox{10 cm}{writeBlockAndUpdateOffsets(f\_buf,f\_hash,null);} \\ \hline
    2     & F     & F     & =     & {} & $>$     & \multicolumn{1}{l} { \pbox{10 cm}{If (hasBlockHashOnHBase(next\_b\_hash)) \\ \hspace{1 cm} byte[] buf = Arrays.copyOfRange(f\_buf, 0, (int)(b\_offset-offset)); \\ \hspace{1 cm} recordBlockAndUpdateOffsets(buf,null,null); \\
Else \\ WriteBlockAndUpdateOffsets(f\_buf,f\_hash,null); } }\\ \hline
    3     & F     & F     &       & = & =     & \multicolumn{1}{l}{\multirow{2}[4]{*}{writeBlockAndUpdateOffsets(b\_buf,b\_hash,null);}} \\ \cline{1-6}
    4     & F     & F     &       & {=} & $>$     & \multicolumn{1}{l}{} \\ \hline
    5     & F     & T     &       & {$<$} & =     & \pbox{10 cm}{byte[] buf = Arrays.copyOfRange(b\_buf, (maxBlockSize-lastBlkSize), b\_buf.length); \\
recordSuperBlockAndUpdateOffsets (buf,null,b\_hash+","+(maxBlockSize-lastBlkSize)+","+buf.length);} \\ \hline
    6     & F     & T     &       & {$<$} &       & \pbox{10 cm}{If (offset==0)\\
   IncrementBlockAndUpdateOffsets(b\_hash,b\_BlkSize);\\
Else\\
   byte[] buf = Arrays.copyOfRange(b\_buf, (maxBlockSize-lastBlkSize), b\_buf.length);\\
   recordSuperBlockAndUpdateOffsets(buf,null,b\_hash+","+ (maxBlockSize-lastBlkSize)+","+buf.length); } \\ \hline

    9     & T     & F     & $<$     & {} & =     & \multicolumn{1}{l}{\multirow{2}[4]{*}{incrementBlockAndUpdateOffsets(f\_hash,f\_BlkSize);}} \\ \cline{1-6}
    10    & T     & F     & =     & {} &       & \multicolumn{1}{l}{} \\ \hline
    11    & T     & F     & =     & {} & =     & \multicolumn{1}{l}{\multirow{2}[4]{10 cm}{{byte[] buf = Arrays.copyOfRange(b\_buf, 0, (maxBlockSize-lastBlkSize));\\ recordBlockAndUpdateOffsets(buf,null,null);\\ incrementBlockAndUpdateOffsets(f\_hash,f\_BlkSize);}}} \\ \cline{1-6}
    12    & T     & F     & $>$     & {} &       & \multicolumn{1}{l}{} \\ \hline
    13    & T     & T     & $<$     & {} & =     & \multicolumn{1}{l}{\multirow{2}[4]{*}{incrementBlockAndUpdateOffsets(f\_hash,f\_BlkSize);}} \\ \cline{1-6}
    14    & T     & T     & =     & {} & $>$     & \multicolumn{1}{l}{} \\ \hline
    \end{tabular}%
\caption{}
  \label{tab:ImplLogic2}%
\end{table}%
\end{document}
4

There are many questions here.

First a comment: when you use \multicolumn remember to include any rules that are needed, e.g. write \multicolumn{1}{c|}{...} instead of a plain c. Withouth the | you vertical lines will have holes.

For the rotated labels, it is best to treat them all the same. Your first 6 columns can all be of type c. Now the label needs to be centered in a box and rotated. It is easiest to make all these boxes of one fixed width before rotation, so the same centering is being applied. So my suggestion is to create a commond to do all of this and introduce a length you can adjust. The following command \sidewaysc can be used simply as \sidewaysc{Text\\ text}:

\newlength{\sidewaysclen}
\setlength{\sidewaysclen}{6em}

\newcommand{\sidewaysc}[1]{\raisebox{\dimexpr-0.5\sidewaysclen}{%
  \begin{sideways}\begin{minipage}{\sidewaysclen}%
    \centering #1\end{minipage}\end{sideways}}}

The sideways environment rotates the box about a corner, for your table it is best to move it down via the \raisebox so that it is centered on the line.

The missing \hspaces are due to the enclosing enviroment implicitly used. It is essentialy a paragraph, and if you specify a line break in a paragraph, LaTeX will ignore the space at the beginning of the next line. There several ways around this. If you pack the material up in a \parbox and specify \raggedright then the \hspaces will be honoured. I suggest you use \quad and \qquad for these spaces, they are equal to \hspace{1em} and \hspace{2em}, but easier to use consistently. Incidentally a \multirow with a specified width already packs its argument this way with \raggedright (at least in the default set-up), so such spacing is honoured there. In the example below I have introduced a length variable to specify the width of the final column and used each time I need to specify a \parbox or \multirow width in that column.

Finally, the "repeated" text at the bottom is a \multirow overlapping the next row of the table. The \multirow command does nothing to provide the need vertical space, so you should widen the corresponding rows, e.g. by using \\[dimension]. In your case you want to do this evenly on two consecutive rows, \\[4ex] seems about right.

Sample output

\documentclass[12pt,a4paper]{report}

\usepackage{array}
\usepackage{multirow}
\usepackage{rotating}
\usepackage{adjustbox}

\newlength{\sidewaysclen}
\setlength{\sidewaysclen}{6em}
\newcommand{\sidewaysc}[1]{\raisebox{\dimexpr-0.5\sidewaysclen}{%
  \begin{sideways}\begin{minipage}{\sidewaysclen}%
    \centering #1\end{minipage}\end{sideways}}}
\newlength{\finalcolwd}

\begin{document}

\begin{table}[htp]
  \centering
  \renewcommand\baselinestretch{1}\normalsize
  \renewcommand{\arraystretch}{1.2}
  \setlength{\sidewaysclen}{6em}
  \setlength{\finalcolwd}{8.8cm}
  \begin{adjustbox}{center}
  \begin{tabular}{|c|c|c|c|c|c|m{\finalcolwd}|}
    \hline
    \sidewaysc{Rule No}&\sidewaysc{F\_offsetFlag}&
    \sidewaysc{B\_offsetFlag}&
    \sidewaysc{F\_offsetDiff\\ Relation\\ MaxBlkSize}& 
    \sidewaysc{B\_offsetDiff\\ (Relation)\\ MaxBlkSize}&
    \sidewaysc{F\_offsetDiff\\ (Relation)\\ B\_offsetDiff}&
    \multicolumn{1}{c|}{\textbf{Action}}
    \\ \hline
    1     & F     & F     & $<$     &  & =     &
    writeBlockAndUpdateOffsets(f\_buf,f\_hash,null);
    \\ \hline
    2     & F     & F     & =     &  & $>$     & 
    \parbox{\finalcolwd}{\raggedright\strut
    If (hasBlockHashOnHBase(next\_b\_hash))\\
      \quad  byte[] buf = Arrays.copyOfRange(f\_buf, 0,\\
      \qquad (int)(b\_offset-offset));\\
      \quad  recordBlockAndUpdateOffsets(buf,null,null); \\
      Else\\
      \quad  WriteBlockAndUpdateOffsets(f\_buf,\\
      \qquad f\_hash,null);\strut}
    \\ \hline
    3     & F     & F     &       & = & =     &
    \multirow{2}{*}{writeBlockAndUpdateOffsets(b\_buf,b\_hash,null);}
    \\ \cline{1-6} 
    4     & F     & F     &       & = & $>$     &
    \\ \hline
    11    & T     & F     & =     &  & = &
    \multirow{2}{\finalcolwd}[-3pt]{%
      byte[] buf = Arrays.copyOfRange(b\_buf, 0,\\
      \quad (maxBlockSize-lastBlkSize));\\
      recordBlockAndUpdateOffsets(buf,null,null);\\
      incrementBlockAndUpdateOffsets\\
      \quad (f\_hash,f\_BlkSize);}
    \\[4ex] \cline{1-6}
    12    & T     & F     & $>$     &  &       &
    \\[4ex] \hline
    13    & T     & T     & $<$     &  & =     &
    \multirow{2}{\finalcolwd}{%
      incrementBlockAndUpdateOffsets\\
      \quad(f\_hash,f\_BlkSize);} 
    \\ \cline{1-6}
    14    & T     & T     & =     &  & $>$     & \\ \hline
  \end{tabular}
  \end{adjustbox}
  \caption{Example table}
  \label{tab:ImplLogic2}%
\end{table}%
\end{document}

The table is wide, so I have put it in an adjust box, so that it sticks out evenly in to both margins.

1
  • Thank you, Thank You, Thank You... I was trying to solve this by posting in stackOverflow and stackExchange Finally i got the complete solution for all the questions. Once again Thanks a lot... – Krishnaprasad Sep 14 '13 at 10:21

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.