1

This refers to my following question.

Setting single row height with multirow

\documentclass[11pt,table,a5paper]{article}
\usepackage{array,ragged2e}
\usepackage{graphicx}
\usepackage[framemethod=TikZ]{mdframed}
\usepackage{lipsum}
\usepackage[top=2cm, bottom=2cm, outer=1cm, inner=2.1cm,twoside,  headsep=26pt]{geometry}
\usepackage{ifthen}
\usepackage{wrapfig}
\usepackage{comment}
\usepackage{parskip}
\usepackage{framed}
\usepackage{sidecap}
\usepackage{longtable}
\usepackage{multirow}
\begin{document}
\newcommand{\nsr}{\rule[-1.3cm]{0pt}{2.2cm}} 
\newcommand{\dsr}{\rule[-3.5cm]{0pt}{4cm}} 
\small
{\renewcommand{\arraystretch}{1.8}\begin{longtable}   {|p{2.7cm}|p{1.0cm}|p{2.4cm}|p{1.0cm}|p{1.3cm}|p{0.8cm}|} 
\hline 
\rowcolor{green} \textbf{ \textcolor{white}{ColA}} &\textbf{     \textcolor{white}{ColB}} &\textbf{ \textcolor{white}{ColC}}  &\textbf{    \textcolor{white}{ColD}} &\textbf{ \textcolor{white}{ColE}} &\textbf{ \textcolor{white}{ColF}} \\ 
\endfirsthead 
\rowcolor{green} \textbf{ \textcolor{white}{ColA}} &\textbf{  \textcolor{white}{ColB}} &\textbf{ \textcolor{white}{ColC}}  &\textbf{  \textcolor{white}{ColD}} &\textbf{ \textcolor{white}{ColE}} &\textbf{  \textcolor{white}{ColF}} \\  
\endhead 
\hline 
\rowcolor[RGB]{243,182,185} 
\dsr  Brainy Person  & \dsr  3.38&  \multirow{1}{*}{\parbox{2.5cm}  {\textcolor{black}{This is Very first line,~\\ 
~\\ 
This is Second line,~\\ 
~\\ 
This is IIIrd line,}}} 
&\dsr2.36 & \dsr 0.62 & \dsr 18 \\\cline{1-2} \cline{4-6}  
\hline 
\nsr  Kingestionisation Quesiton Queeneinsteen  & \nsr  1.46&  \multirow{3}  {*}{\parbox{2.5cm}{\textcolor{black}{This is First line~\\ 
~\\  
This is Second line,~\\ 
 ~\\ 
This is Third line~\\ 
~\\ 
This is Fourth line}}} 
 & \nsr 1.02 & \nsr 0.62 & \nsr  13 \\\cline{1-2} \cline{4-6} 
\nsr  Foolish Perosn  & \nsr  1.16 &   
& \nsr 0.81 & \nsr 0.62 & \nsr  45 \\\cline{1-2} \cline{4-6} 
\nsr  Attacking Person Rob & \nsr  1.02 &   
& \nsr 0.71 & \nsr 0.52 & \nsr  31 \\\cline{1-2} \cline{4-6} 
\hline 
\rowcolor{red} 
Datset 
& 24 
& \multicolumn{2}{c|}{Normal Value} 
& 23
& 342 \\ 
\hline 
\end{longtable}}
\end{document}

https://i.stack.imgur.com/5KtKX.png

In the above example, names in first column gets wrapped in one cell but every name (First, Second and Last name are far apart.i.e separated by multiline). How can I fix this?

1 Answer 1

1

Normally the argument to \multirow is set ragged right. However, you have packed the text inside a \parbox, which will try to spread the text to the given width. Instead of using \parbox make use of the width argument of \multirow. The syntax is

\multirow{nrows}{width}{text}

You have use width=* which says use the natural width of text, but put text=\parbox{2.5cm}{....}. Instead you can write

\multirow{nrows}{2.5cm}{....}

This fixes the issues in your middle column.

In the first column, the problem is the rules you are adding, your commands \nsr or \dsr. These occur in the first line of text in a paragraph, and so are adding depth to that line, pushing it away from the next line of the paragraph. My guess is that you have placed these rules to help space out the table. In your case it is only necessary to have them at one point in the row, so just add them to say the final column that will not have multiple lines.

If you wish to colour the rows then you need to put the \multirow in its bottom row and specify a negative nrows. Additionally, since you rows are unusually high/deep you will have to add an adjustment:

\multirow{nrows}{width}[adjust]{test}

There will also be problems with colours of the rules. You can use the \hhline suggestion from Cellcolor overwrites partial horizontal lines (\cline).

Sample output

\documentclass[11pt,table,a5paper]{article}

\usepackage{array,ragged2e}
\usepackage[framemethod=TikZ]{mdframed}
\usepackage[top=2cm, bottom=2cm, outer=1cm, inner=2.1cm, twoside, headsep=26pt]{geometry}
\usepackage{longtable}
\usepackage{multirow}

\begin{document}

\newcommand{\nsr}{\rule[-1.3cm]{0pt}{2.2cm}} 
\newcommand{\dsr}{\rule[-3.5cm]{0pt}{4cm}} 
{\small
\renewcommand{\arraystretch}{1.8}
\begin{longtable}{|p{2.7cm}|p{1.0cm}|p{2.4cm}|p{1.0cm}|p{1.3cm}|p{0.8cm}|} 
  \hline 
  \rowcolor{green} \textbf{\textcolor{white}{ColA}} &\textbf{\textcolor{white}{ColB}} &\textbf{\textcolor{white}{ColC}}  &\textbf{\textcolor{white}{ColD}} &\textbf{\textcolor{white}{ColE}} &\textbf{\textcolor{white}{ColF}} \\ 
  \endhead 
  \hline 
  \rowcolor[RGB]{243,182,185} 
  Brainy Person  & 3.38&
  \multirow{1}{2.5cm}{\textcolor{black}{This is Very first line\\[2ex]
  This is Second line\\[2ex]
  This is IIIrd line}} 
  &2.36 & 0.62 & \dsr 18 \\
  \hline 
  Kingestionisation Quesiton Queeneinsteen  & 1.46&
  \multirow{3}{2.5cm}{\textcolor{black}{This is First line\\[2ex] 
  This is Second line\\[2ex]
  This is Third line\\[2ex]
  This is Fourth line}}
  & 1.02 & 0.62 & \nsr  13 \\\cline{1-2} \cline{4-6} 
  Foolish Person  & 1.16 &   
  & 0.81 & 0.62 & \nsr  45 \\\cline{1-2} \cline{4-6} 
  Attacking Person Rob & 1.02 &   
  & 0.71 & 0.52 & \nsr  31 \\\cline{1-2} \cline{4-6} 
  \hline 
  \rowcolor{red} 
  Datset 
  & 24 
  & \multicolumn{2}{c|}{Normal Value} 
  & 23
  & 342 \\ 
\hline 
\end{longtable}}

\end{document}

You should beware of extra spaces that were in the code for your headings (\textbf{ Col}), these were causing bad alignment.

If you want the first column ragged right, then you can start the table format specification with {|>{\raggedright}p{2.7cm}... instead of just {p{2.7cm}....

If none of your cells are guaranteed to be single rows you could add a separate column to hold the rules.

Sample colored output

\documentclass[11pt,table,a5paper]{article}

\usepackage{array,ragged2e}
\usepackage[framemethod=TikZ]{mdframed}
\usepackage[top=2cm, bottom=2cm, outer=1cm, inner=2.1cm, twoside, headsep=26pt]{geometry}
\usepackage{longtable}
\usepackage{multirow}
\usepackage{hhline}

\begin{document}

\newcommand{\nsr}{\rule[-1.3cm]{0pt}{2.2cm}} 
\newcommand{\dsr}{\rule[-3.5cm]{0pt}{4cm}} 
{\small
\setlength{\arrayrulewidth}{1pt}
\setlength{\minrowclearance}{1pt}
\renewcommand{\arraystretch}{1.8}
\begin{longtable}{|p{2.7cm}|p{1.0cm}|p{2.4cm}|p{1.0cm}|p{1.3cm}|p{0.8cm}|} 
  \hline 
  \rowcolor{green} \textbf{\textcolor{white}{ColA}} &\textbf{\textcolor{white}{ColB}} &\textbf{\textcolor{white}{ColC}}  &\textbf{\textcolor{white}{ColD}} &\textbf{\textcolor{white}{ColE}} &\textbf{\textcolor{white}{ColF}} \\ 
  \endhead 
  \hline 
  \rowcolor[RGB]{243,182,185} 
  Brainy Person  & 3.38&
  \multirow{1}{2.4cm}[-6pt]{\textcolor{black}{This is Very first line\\[2ex]
  This is Second line\\[2ex]
  This is IIIrd line}} 
  &2.36 & 0.62 & \dsr 18 \\
  \hline
  \rowcolor{teal}
  Kingestionisation Quesiton Queeneinsteen  & 1.46&
  & 1.02 & 0.62 & \nsr  13 \\
  \hhline{-->{\arrayrulecolor{teal}}->{\arrayrulecolor{black}}|---}
  \rowcolor{teal}
  Foolish Person  & 1.16 &   
  & 0.81 & 0.62 & \nsr  45 \\
  \hhline{-->{\arrayrulecolor{teal}}->{\arrayrulecolor{black}}|---}
  \rowcolor{teal}
  Attacking Person Rob & 1.02 &   
  \multirow{-3}{2.4cm}[80pt]{\textcolor{black}{This is First line\\[2ex] 
  This is Second line\\[2ex]
  This is Third line\\[2ex]
  This is Fourth line}}
  & 0.71 & 0.52 & \nsr  31 \\\cline{1-2} \cline{4-6} 
  \hline 
  \rowcolor{red} 
  Datset 
  & 24 
  & \multicolumn{2}{c|}{Normal Value} 
  & 23
  & 342 \\ 
\hline 
\end{longtable}}

\end{document}
7
  • Still same issue.. "Kingestionisation" and "Quesiton Queene- insteen" are seperated by multilines.
    – manish
    Aug 22, 2013 at 7:15
  • I see. Answer updated. Aug 22, 2013 at 7:32
  • Thanks it works fine but i have one more issue. When i used color \rowcolor[RGB]{1,189,185} before each row only text in first row is visible but for others it is not visible. I have uploaded my code here textuploader.com/?p=6&id=MfckZ and corresponding output postimg.org/image/euojr5543.
    – manish
    Aug 22, 2013 at 7:50
  • That is a separate question. Essentially you should put the multirow in the final line, provide a negative argument and use the optional fixup arugement. Then there is a problem colouring the rules. See tex.stackexchange.com/q/65231/15925 for most of this. Aug 22, 2013 at 8:12
  • Example implementing these things now added. Aug 22, 2013 at 12:26

You must log in to answer this question.

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