[Tex/LaTex] How might one create a nice looking table in Latex

tables

I am able to create a table that looks bland. I am wondering how to create tables like the one below: enter image description here

\begin{table}[htbp]
\caption{Variable Descriptions}
\label{tab:2}
\begin{center}
\begin{tabular}{|c|c|}\hline
Variables & Descriptions\\\hline
\textit{ln(wage)} & log of wage\\
\textit{educ} & years of education\\
\textit{black} & 1 if black and 0 if not\\
\textit{hisp} & 1 if hispanic and 0 if not\\
\textit{exper} & years of experience\\
\textit{exper$^{2}$} & years of experience squared\\
\textit{married} & 1 if married and 0 if not\\
\textit{union} & 1 if belongs to a union and 0 if not\\\hline
\end{tabular}
\end{center}
\end{table}

The particular question is:

  • How might one alternate row colours between grey and white? Is there a way to create a command rather than colouring them manually?

Best Answer

Here are three versions of your table:

enter image description here

\documentclass{article}
\usepackage[table,svgnames]{xcolor} % provides the \rowcolors command 
\usepackage{caption} % for improved spacing around the caption

\usepackage{array} % enables >{...} in the coumn specifier section, used in table 2 & 3
\usepackage{booktabs} % for improved spacing around horizontal lines, used in example 3, incompatible with vertical lines, be careful if you want to to combine it with color

\usepackage[column=0]{cellspace} % for adding a small amount of space above and below each cell, only used in table 2
\setlength{\cellspacetoplimit}{2pt}
\setlength{\cellspacebottomlimit}{\cellspacetoplimit}


\begin{document}
\begin{table}[htbp]
\caption{Variable Descriptions}
\label{tab:2}
\centering % used \centering instead of the center environment since the latter adds additional white space
\rowcolors{2}{white}{lightgray} 
\begin{tabular}{|c|c|}\hline
Variables & Descriptions\\\hline
\textit{ln(wage)} & log of wage\\
\textit{educ} & years of education\\
\textit{black} & 1 if black and 0 if not\\
\textit{hisp} & 1 if hispanic and 0 if not\\
\textit{exper} & years of experience\\
\textit{exper$^{2}$} & years of experience squared\\
\textit{married} & 1 if married and 0 if not\\
\textit{union} & 1 if belongs to a union and 0 if not\\\hline
\end{tabular}
\end{table}

\begin{table}[htbp]
\caption{Variable Descriptions}
\label{tab:2}
\centering
\rowcolors{2}{white}{lightgray} 
\begin{tabular}{>{\itshape}0l0l}\hline % used >{\itshape} in order to be able to remove the repeated occurences of \textit in the first column, used l type columns instead of c columns for a cleaner look, added small vertical space above and below the rows with the help of the cellspace package, removed all vertical lines
\textup{Variables}       & Descriptions\\\hline
ln(wage)                 & log of wage\\
educ                     & years of education\\
black                    & 1 if black and 0 if not\\
hisp                     & 1 if hispanic and 0 if not\\
exper                    & years of experience\\
exper\textsuperscript{2} & years of experience squared\\
married                  & 1 if married and 0 if not\\
union                    & 1 if belongs to a union and 0 if not\\\hline
\end{tabular}
\end{table}

\begin{table}[htbp]
\caption{Variable Descriptions}
\label{tab:2}
\centering
\begin{tabular}{>{\itshape}ll}
\toprule % replaced all \hline commands with rules from the booktabs package
\textup{Variables}       & Descriptions\\
\midrule
ln(wage)                 & log of wage\\
educ                     & years of education\\
black                    & 1 if black and 0 if not\\
hisp                     & 1 if hispanic and 0 if not\\
exper                    & years of experience\\
exper\textsuperscript{2} & years of experience squared\\
married                  & 1 if married and 0 if not\\
union                    & 1 if belongs to a union and 0 if not\\
\bottomrule
\end{tabular}
\end{table}
\end{document}
Related Question