1

I want to obtain a table like the one in my attachment. Then I tried to use \hhline to draw horizontal lines. But I still have a problem about breaking lines automatically.

The one that I want to have enter image description here

The bad one enter image description here

\documentclass[12pt, a4paper,twoside]{article}
\usepackage{multirow,booktabs}
\usepackage{colortbl,multirow,hhline,mathtools}
\usepackage{makecell}
\begin{document}

\definecolor{c1}{rgb}{0.30980, 0.50588, 0.73725}
\definecolor{c2}{rgb}{0.82353, 0.87843, 0.92941}


\setlength{\arrayrulewidth}{1pt}
\setlength{\extrarowheight}{1.0pt}
\begin{table}[H]   % added on 12172013 for caption and label
\centering
\caption{Table}
\label{tb32b}
\arrayrulecolor{white}
\begin{tabular}{|p{4.5em}|p{7cm}|p{3.8cm}|l|}
\rowcolor{c1}
\multirow{4}*{\textcolor{white}{Measure}} 
        & \multicolumn{2}{l|}{\multirow{4}*{\textcolor{white}{Description}}} & 
                                           \multirow{4}*{\textcolor{white}{NO.}}  \\
\hline 
\arrayrulecolor{white}

\rowcolor{c2}
\multirow{4}*{\parbox[t]{4.5em}{Orientation-based}}  &  \multicolumn{2}{p{11.25cm}|}{The first orientater of empty bins in the rose plot.}   & \multirow{2}*{$M_8$}    \\
\hhline{|>{\arrayrulecolor{c2}}-|>{\arrayrulecolor{white}}-|>{\arrayrulecolor{white}}-|>{\arrayrulecolor{white}}-|}% \hhline hack
\rowcolor{c2}
 & \multicolumn{2}{p{11.25cm}|}{The second one is defined  in  the orientations of the delta points.}      & \multirow{2}*{$M_9$} \\
\hline

\rowcolor{c2}
\multirow{4}{4.5em}{Pair-based} & Equ1 &  \multirow{4}*{\parbox[t]{3.8cm}{The first orid measure is the number of empty bins in the rose plot, The first orased measure is the number of empty bins in the rose plot.}}  & \multirow{4}*{$M_{10\_13}$} \\
\hhline{|>{\arrayrulecolor{c2}}-|>{\arrayrulecolor{white}}-|>{\arrayrulecolor{c2}}-|>{\arrayrulecolor{c2}}-|}% \hhline hack


\rowcolor{c2}
& Equ2 & & \\
\hhline{|>{\arrayrulecolor{c2}}-|>{\arrayrulecolor{white}}-|>{\arrayrulecolor{c2}}-|>{\arrayrulecolor{c2}}-|}% \hhline hack


\rowcolor{c2}
& Equ3 & & \\
\hhline{|>{\arrayrulecolor{c2}}-|>{\arrayrulecolor{white}}-|>{\arrayrulecolor{c2}}-|>{\arrayrulecolor{c2}}-|}% \hhline hack


\rowcolor{c2}
&  Equ4 & & \\
\hline

\end{tabular}
\end{table}
\end{document}
  • 1
    As your images do not relate to the supplied input it isn't at all clear which part of the example you want to change. latex can not break the made up word sdafdsafasdfdsafasdfdsfasdfdsafdsafdsafasdfdsafasdfasdfsadfasdfsadfsadfasdfdsafdsafdsafdasfdsafdsafasdfasdfsadafdas presumably your real example has word spaces or something that may be hyphenated? – David Carlisle Feb 3 '14 at 16:55
  • I want to make three grids of the whole table work, the 1st two grids are rows 2 and 3 of the 1st column. And another one is just column 3 of the last row. – user18441 Feb 3 '14 at 17:18
  • The idea of the example (and images) is that they should help anyone offering to provide an answer to test their code against your expectations. Just providing an unrelated image and code that generates an error ! Undefined control sequence. l.3 \definecolor doesn't really make it easy for anyone to help you. – David Carlisle Feb 3 '14 at 17:22
2

You clearly never ran your posted example, it has numerous errors in the preamble before the table even starts. However fixing that, the main issue is that the * form doesn't do line breaking you need to specify a width as for p columns. Also as you want the text to be over the colour not under it, you need to add it to the last row spanned, not the first:

enter image description here

\documentclass[12pt, a4paper,twoside]{memoir}

\usepackage{colortbl,multirow,hhline,mathtools}
\definecolor{c1}{rgb}{0.30980, 0.50588, 0.73725}
\definecolor{c2}{rgb}{0.82353, 0.87843, 0.92941}
\begin{document}
\setlength{\arrayrulewidth}{1pt}
\setlength{\extrarowheight}{1.0pt}
\begin{table}[H]   % added on 12172013 for caption and label
\centering
\caption{Table}
\label{tb32b}
%\arrayrulecolor{white}
\begin{tabular}{|p{4.5em}|p{7cm}|p{3.8cm}|l|}
\rowcolor{c1}
\multirow{4}{4.5em}{\textcolor{white}{Measure}} 
        & \multicolumn{2}{l|}{\multirow{4}{*}{\textcolor{white}{Description}}} & 
                                           \multirow{4}{*}{\textcolor{white}{NO.}}  \\
\hline 
\arrayrulecolor{white}

\rowcolor{c2}
 &  \multicolumn{2}{p{11.25cm}|}{The first orientation-based medfadadfd  empty bins in the rose plot.}   & \multirow{2}{*}{$M_8$}    \\
\hhline{|>{\arrayrulecolor{c2}}-|>{\arrayrulecolor{white}}-|>{\arrayrulecolor{white}}-|>{\arrayrulecolor{white}}-|}% \hhline hack
\rowcolor{c2}
\multirow{-3}{4.5em}{Orientation-based}  & \multicolumn{2}{p{11.25cm}|}{The second one is definesfa e in  the orientatisdafasdf points.}      & \multirow{2}{*}{$M_9$} \\
\hline

\rowcolor{c2}
& Equ1 &  & \multirow{4}{*}{$M_{10\_13}$} \\
\hhline{|>{\arrayrulecolor{c2}}-|>{\arrayrulecolor{white}}-|>{\arrayrulecolor{c2}}-|>{\arrayrulecolor{c2}}-|}% \hhline hack

\rowcolor{c2}
& Equ2 & & \\
\hhline{|>{\arrayrulecolor{c2}}-|>{\arrayrulecolor{white}}-|>{\arrayrulecolor{c2}}-|>{\arrayrulecolor{c2}}-|}% \hhline hack

\rowcolor{c2}
& Equ3 & & \\
\hhline{|>{\arrayrulecolor{c2}}-|>{\arrayrulecolor{white}}-|>{\arrayrulecolor{c2}}-|>{\arrayrulecolor{c2}}-|}% \hhline hack

\rowcolor{c2}
\multirow{-4}{4.5em}{Pair-based} &  Equ4 &    & \\
\rowcolor{c2}&&&\\
\rowcolor{c2}&&&\\
\rowcolor{c2}&&&\\
\rowcolor{c2}&&
\multirow{-8}{3.8cm}{sd afd safasd fd safasd fd sfasd fd safd safd safasd fd safasd fasd fsad fasd fsad fsad fasd fd safd safd safd asfd safd safasd fasd fsad afdas}
&\\
\hline

\end{tabular}
\end{table}

\end{document}
  • Thanks David. Instead of using \multirow{-3}, is there any other solution? I want the 3rd column of the last row to occupy the whole 4 lines. – user18441 Feb 3 '14 at 17:49
0

You can use the makecell package. It has a \multirowcellcommand that allows line breaks. It has the same syntax as \multirow.

Or, if you want to type a whole paragraph with automatic line breaks, this should work:

\multirow{nb lines}{*}{\parbox{parwidth}{My text}}
  • I tried to use \parbox but I obtained a strange result, as the updated attachment. – user18441 Feb 3 '14 at 18:04
  • Actually, the 3 words in the first line disappeared. – user18441 Feb 3 '14 at 18:06
0

I suggest you to avoid vertical lines in the table: they are not typographically beautiful. Your code is quite messy: I write a code that you can use as a base to fix the table more orderly. You can improve it by adding colors.

\documentclass[12pt, a4paper,twoside]{article}
\usepackage{multirow,booktabs}
\begin{document}
\begin{table}
\centering
\begin{tabular}{cccc}
\toprule
Measure &   \multicolumn{2}{c}{Description} &   NO.  \\
\midrule
\multirow{2}*{Orientation-based}    &   \multicolumn{2}{c}{The first orientation} & $M_8$   \\
    &   \multicolumn{2}{c}{The second one is }  &   $M_9$   \\
    \midrule
\multirow{4}*{Pair-based}   &   Equ1    &   \multirow{4}*{Example of text}  & \multirow{4}*{$M_{10\_13}$}   \\
    &   Equ2    &   &   \\
    &   Equ3    &   &   \\
    &   Equ4    &   &   \\
    \bottomrule
\end{tabular}
\end{table}
\end{document}
  • Thanks very much, but I have to use white lines, for all the tables in my thesis must be consistent. And I use 'memoir' template. – user18441 Feb 3 '14 at 17:34

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.