6

How can I separate columns and cells with white lines. I googled and found we can put \hline and | in table definition but that produces black line.

 \documentclass{article}
 \usepackage{array,multirow}
 \begin{document}
 \begin{tabular}{|c|cc|}\hline
 \multirow{4}{*}{Foo} & 1 & 2 \\
   & 1 & 2 \\\cline{2-3}
   & 1 & 2 \\
   & 1 & 2 \\\hline
  \multirow{4}{*}{Bar} & 1 & 2 \\
     & 1 & 2 \\\cline{2-3}
     & 1 & 2 \\
     & 1 & 2 \\\hline
   \end{tabular}
\end{document}

How can I change them to white line?

4
  • Sorry I didn't understand. White line in white backgroud? Simply don't use | and \hline. If you are using colors for cells/rows/columns, then you can color them using colortbl package.
    – user11232
    Jan 16, 2013 at 4:42
  • 1
    I have deleted the biblatex tag since nowhere in your problem did I see something related to it :)
    – hpesoj626
    Jan 16, 2013 at 4:43
  • My background is blue actually.
    – manish
    Jan 16, 2013 at 4:43
  • Yes, blue background.
    – manish
    Jan 16, 2013 at 4:45

1 Answer 1

8

Use colortbl. I have used blue just to demonstrate as here background is white. You may change blue to white (\arrayrulecolor{white}) in your actual case.

 \documentclass{article}
 \usepackage{array,multirow,colortbl}
 \begin{document}
 \arrayrulecolor{blue}         %% change blue to white in your case
 \begin{tabular}{|c|cc|}\hline
 \multirow{4}{*}{Foo} & 1 & 2 \\
   & 1 & 2 \\\cline{2-3}
   & 1 & 2 \\
   & 1 & 2 \\\hline
  \multirow{4}{*}{Bar} & 1 & 2 \\
     & 1 & 2 \\\cline{2-3}
     & 1 & 2 \\
     & 1 & 2 \\\hline
   \end{tabular}
\end{document}

enter image description here

For details Refer to documentation of colortble page 5 and 6 sections 7 and 8. To get documentation run texdoc colortbl from command prompt or visit texdoc.net

Another option is to use xcolor package with [table] option:

\documentclass{article}
 \usepackage{array,multirow}
 \usepackage[table]{xcolor}
 \begin{document}
 \pagecolor{blue!40} %% just to demonstrate - remove in your file
 \arrayrulecolor{white}
 \begin{tabular}{|c|cc|}\hline
 \multirow{4}{*}{Foo} & 1 & 2 \\
   & 1 & 2 \\\cline{2-3}
   & 1 & 2 \\
   & 1 & 2 \\\hline
  \multirow{4}{*}{Bar} & 1 & 2 \\
     & 1 & 2 \\\cline{2-3}
     & 1 & 2 \\
     & 1 & 2 \\\hline
   \end{tabular}
\end{document}

enter image description here

Edit:

It works for long tables also:

\documentclass{article}
 \usepackage{array,multirow,longtable}
 % \usepackage{colortbl}
 \usepackage[table]{xcolor}
 \usepackage[textheight=10cm]{geometry} %% onlly for testing
 \begin{document}
 \pagecolor{blue} %% just to demonstrate - remove in your file
 \arrayrulecolor{white}
 \begin{tabular}{|c|cc|}\hline
 \multirow{4}{*}{Foo} & 1 & 2 \\
   & 1 & 2 \\\cline{2-3}
   & 1 & 2 \\
   & 1 & 2 \\\hline
  \multirow{4}{*}{Bar} & 1 & 2 \\
     & 1 & 2 \\\cline{2-3}
     & 1 & 2 \\
     & 1 & 2 \\\hline
   \end{tabular}
   
  
\begin{longtable}{|>{\bf\centering\arraybackslash}p{1in}| p{2in}|}
\hline
\large{Name} & \large{\textbf{Definition}}\\ \hline
\endfirsthead
\hline
\large{Name} & \large{\textbf{Definition}}\\ \hline
\endhead
\hline
\multicolumn{2}{r}{continued \ldots}
\endfoot
\hline
\endlastfoot

  Newton's first law & An object will \\ \hline
  Newton's second law & The net force \\\hline
  Newton's third law & When two bodies \\ \hline
  Linear momentum & The product of an object's \\ \hline
  Net force on a body & Is said to be equal \\ \hline
  Impulse of a force & The product of \\\hline
  Principle of conservation of momentum & In a closed system, \\
    \hline
  Perfectly elastic collision & A collision is \\ \hline
  Inelastic collision & A collision is \\ \hline
  Radian & $\pi$ radians = $180^\circ$\\ \hline
  Gravitational field strength & The gravitational force
    \\\hline
  Newton's law of gravitation & Any two point masses\\\hline
\end{longtable}
\end{document}

enter image description here

Edit:

For a query in the comment below:

You may use some thing like

\newcolumntype{M}[1]{>{\centering\arraybackslash}p{#1}} %% this needs array package
\begin{longtable}{|M{1.4cm}|M{1cm}|M{1cm}|M{3.7cm}|M{1.8cm}|M{1.8cm}|}
3
  • I am using longtable and still same pblm persists. How can i fix this?
    – manish
    Jan 16, 2013 at 6:30
  • @user15662 See the edit.
    – user11232
    Jan 16, 2013 at 6:55
  • My longtable definition: cat("\\begin{longtable}{ >{\\rule{0pt}{.5cm}} >{\\centering\\arraybackslash}p{1.4cm} >{\\centering\\arraybackslash}p{1cm}>{\\centering\\arraybackslash}p{1cm}>{\\centering\\arraybackslash}p{3.7cm}>{\\centering\\arraybackslash}p{1.8cm}>{\\centering\\arraybackslash}p{1.8cm}}","\n") , How can i put vertical bar inside it.
    – manish
    Jan 16, 2013 at 7:19

You must log in to answer this question.

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