Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am terrible at LaTeX tables. I managed to produce a table, but it looks so basic. How do I make it fancier?

Here is the table's code:

\begin{table}
    \begin{tabular}{|l|l|l|l|l|}
         \hline
             Models    & A  & B  & C  & D  \\ \hline
             Model $X$ & X1 & X2 & X3 & X4 \\ \hline
             Model $Y$ & Y1 & Y2 & Y3 & Y4 \\
         \hline
    \end{tabular}
\end{table}
share|improve this question
2  
Wellcome to TeX SX! Please provide a Minimal Working Example (MWE). It is easier for people to run your document and help you. –  zunbeltz Jan 16 '13 at 8:51
    
I never try to make anything look fancy. I hope to always listen carefully to the information that I want to get across, and let it tell me how it needs to be presented. The only thing I don't like about your table are the vertical bars and horizontal bars, which don't really help. Use spacing instead of bars perhaps, like ` \[3pt ` instead of ` \\ ` on the first line, and get rid of ` \hline ` and ` | `. –  Benjamin McKay Jan 22 '13 at 10:21
add comment

4 Answers 4

up vote 18 down vote accepted

Besides using booktabs, you can use either colortbl or xcolor (with the option [table] to color the tables.

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{booktabs}
 \begin{document}

\begin{tabular}{*5l}    \toprule
\emph{name} & \emph{foo} &&&  \\\midrule
Models    & A  & B  & C  & D  \\ 
\rowcolor{blue!50} Model $X$ & X1 & X2 & X3 & X4\\ 
\rowcolor{green!50} Model $Y$ & Y1 & Y2 & Y3 & Y4\\\bottomrule
 \hline
\end{tabular}
\end{document}

enter image description here

Another method is somewhat automatic:

\rowcolors{<starting row>}{<first color>}{<second color>}

MWE:

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{booktabs}
 \begin{document}

\rowcolors{3}{green!25}{yellow!50}
\begin{tabular}{ *5l }    \toprule
\emph{name} & \emph{foo} &&&  \\\midrule
Models    & A  & B  & C  & D  \\ 
Model $X$ & X1 & X2 & X3 & X4\\ 
Model $Y$ & Y1 & Y2 & Y3 & Y4\\\bottomrule
 \hline
\end{tabular}
\end{document}

enter image description here

Refer to the documentation of xcolor at texdoc.net for more details.

share|improve this answer
1  
Thank you @Harish. It works in a separate document, but does not work in my own document even though I added the packages. It says "! LaTeX Error: Option clash for package xcolor". Any idea why? –  Günal Jan 16 '13 at 9:41
2  
@Günal To prevent that add \PassOptionsToPackage{table}{xcolor} before \documentclass{article} and remove \usepackage[table]{xcolor}. This happens because some package you are using (may be tikz?) also loads xcolor but with different or no options. refer to this answer: tex.stackexchange.com/a/52978/11232 for some more details. –  Harish Kumar Jan 16 '13 at 9:45
    
Perfectly works. Cheers –  Günal Jan 16 '13 at 12:34
add comment

You shouldn't use vertical lines:

\documentclass{article}
\usepackage{booktabs}
 \begin{document}

\begin{tabular}{@{} *5l @{}}    \toprule
\emph{name} & \emph{foo} &&&  \\\midrule
Models    & A  & B  & C  & D  \\ 
 Model $X$ & X1 & X2 & X3 & X4\\ 
 Model $Y$ & Y1 & Y2 & Y3 & Y4\\\bottomrule
 \hline
\end{tabular}
\end{document}

enter image description here

it is a bit tricky if one has on the left and right no \tabcolsep which looks better to me, but want to color the lines:

\documentclass{article}
\usepackage{array,booktabs}
\newcolumntype{L}{@{}>{\kern\tabcolsep}l<{\kern\tabcolsep}}
\usepackage{colortbl}
\usepackage{xcolor}
 \begin{document}

\begin{tabular}{@{} l L L L @{} >{\kern\tabcolsep}l @{}}    \toprule
\emph{name} & \emph{foo} &&&  \\\midrule
Models    & A  & B  & C  & D  \\ 
\rowcolor{black!20}[0pt][0pt] Model $X$ & X1 & X2 & X3 & X4\\ 
\rowcolor{black!40}[0pt][0pt] Model $Y$ & Y1 & Y2 & Y3 & Y4\\\bottomrule
 \hline
\end{tabular}
\end{document}

enter image description here

share|improve this answer
    
Thank you @Herbert. It looks brilliant. Can you please also tell me how to paint the rows? I want the colors of the rows Model X and Model Y to be different. –  Günal Jan 16 '13 at 8:54
    
see my edited answer –  Herbert Jan 16 '13 at 9:55
add comment

Use booktabs package. The documentation discuss how to produce nicer tables.

  • Don't use vertical lines
  • Don't use unnecessary horizontal lines
  • Take out the extra space at right and left of table with @{}

You can read more in this guide

\documentclass{article}
\usepackage{booktabs}

\begin{document}
\begin{table}
\begin{tabular}{@{} l *4c @{}}
\toprule
 \multicolumn{1}{c}{Models}    & A  & B  & C  & D  \\ 
\midrule
 Model $X$ & X1 & X2 & X3 & X4 \\ 
 Model $Y$ & Y1 & Y2 & Y3 & Y4 \\
\bottomrule
 \end{tabular}
\end{table}
\end{document}

enter image description here

share|improve this answer
add comment

+1 for the other answers- you can get some fancy input by using the pgfplotstable package

screenshot

You can colour the rows if you like- see the documentation for more details.

\documentclass{article}
\usepackage{booktabs}
\usepackage{pgfplotstable}

% global settings
\pgfplotstableset{
    every head row/.style={
    before row=\toprule,after row=\midrule},
    every last row/.style={
    after row=\bottomrule},
    col sep = &,
    row sep=\\,
    string type,
}

\begin{document}

\begin{table}
\pgfplotstabletypeset{
 Models    & A  & B  & C  & D  \\ 
 Model $X$ & X1 & X2 & X3 & X4 \\ 
 Model $Y$ & Y1 & Y2 & Y3 & Y4 \\
 Model $Z$ & Z1 & Z2 & Z3 & Z4 \\
}
\end{table}

\end{document}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.