9

Can you suggest me any additional codes that would make the following table prettier possibly including features such as:

  1. centering the table cell texts vertically
  2. Alllow more padding in the cell

Many thanks!

\documentclass[]{article}
\begin{document}
\begin{center}
\begin{tabular}{|l | c | c | c | c | c |}
\hline
Question & $1$ & $2$ & $3$ & $4$ & $5$\\ \hline
Marks & $x$ & $x$ & $x$ & $y$ & $z$ \\ \hline
\end{tabular}
\end{center}
\end{document}

proudced table

7

As "pretty" is a subjetive term, first think in the type of publication: in formal documents always use as few as possible horizontal rules using booktabs, avoid vertical lines and ... that is all (in many cases).

In some cases, some additional vertical and horizontal padding can be controlled with \arraystretch and \tabcolsep, respectively.

For non so serious publications... well, there are many possibilities to make "pretty" tables, where you can even use the evil vertical rules, dashed or dotted lines,, add backgrounds, color, exagerated paddings or even use a non tabular environment to cause some visual effect. Of course you can mix these options in endless combinations to make it even more jazzy/striking/flaboyant/gaudy. Be imaginative. Some examples:

mwe

\documentclass[]{article}
\usepackage{fancybox, tcolorbox, xcolor, booktabs}
\parskip2em
\begin{document}
\centering

\begin{tabular}{p{2cm}cccccc}
\toprule
Question\dotfill & 1 & 2 & 3 & 4 & 5\\
Marks\dotfill    & $x$ & $x$ & $x$ & $y$ & $z$ \\ 
\bottomrule
\end{tabular}

\[
\left[\begin{array}{cccccc}
\mathrm{Questions} &  1 & 2 & 3 & 4 & 5\\\specialrule{.1em}{.3em}{.3em}
\mathrm{Marks} & x & x & x & y & x
\end{array}\right]\]


\ovalbox{\sffamily
\tabcolsep1.5em % horizonal  padding
\begin{tabular}{l|ccccc}
Questions & 1 & 2 & 3 & 4 & 5\\[.5ex]
Marks    & x & x & x & y & x
\end{tabular}
}

\tcbox[left=0mm,right=0mm,top=0mm,bottom=0mm,boxsep=0mm,
toptitle=0.5mm,bottomtitle=0.5mm,colback=blue!05, 
title filled, title = ~  My table ]{%
\renewcommand{\arraystretch}{2}% verticall padding
\begin{tabular}{l|ccccc}
Questions & 1 & 2 & 3 & 4 & 5\\\hline
Marks    & x & x & x & y & x
\end{tabular}
}

\end{document}
10

My main recommendations would be to (i) get rid of all vertical lines, (ii) omit all \hline directives, and (iii) use a single \midrule instruction to separate the header row from the content row(s). You'll get a much more "open" look of the table, and I would argue that the openness enhances legibility.

In addition, since most of the table appears to consist of math-mode material, one could employ an array environment instead of a tabular environment to afford a drastic reduction in the number of $ symbols one needs to enter.

enter image description here

\documentclass{article}
\usepackage{booktabs,array}
\begin{document}
\begin{center}
-- before --

\medskip
\begin{tabular}{|l | c | c | c | c | c |}
\hline
Question & $1$ & $2$ & $3$ & $4$ & $5$\\ \hline
Marks & $x$ & $x$ & $x$ & $y$ & $z$ \\ \hline
\end{tabular}

\bigskip\bigskip
-- after -- 

\medskip
\setlength\arraycolsep{6pt} % default is "5pt"
$\begin{array}{ >{$}l<{$} ccccc }
Question & 1 & 2 & 3 & 4 & 5\\
\midrule
Marks & x & x & x & y & z 
\end{array}$
\end{center}

\end{document}
9

Use the package booktabs (and have a look at the nice documentation).

\documentclass{article}
\usepackage{booktabs}
\begin{document}
\begin{center}
\begin{tabular}{l  c  c  c  c  c }
\toprule
Question & $1$ & $2$ & $3$ & $4$ & $5$\\ \midrule
Marks & $x$ & $x$ & $x$ & $y$ & $z$ \\ 
\bottomrule
\end{tabular}
\end{center}
\end{document} 

to obtain enter image description here

I use it in all my docs and I try to always follow the nice advice contained in the manual.

8

Here are two other solutions, that show vertical rules can be used — parsimoniously:

\documentclass{article}
\usepackage{amsmath}
\usepackage{booktabs,array, boldline}
\usepackage[math]{cellspace}
\setlength\extrarowheight{2pt}
\setlength\cellspacebottomlimit{5pt}

\begin{document}

\[ \setlength\arraycolsep{6pt} %
\begin{array}{ @{}>{ \text\bgroup}Sr<{\egroup} V{2}*{5}{c}}
Question & 1 & 2 & 3 & 4 & 5\\
\hlineB{2}
Marks & x & x & x & y & z
\end{array} \]
\vskip 1cm
\[ \setlength\arraycolsep{6pt} %
\begin{array}{ @{}>{ \text\bgroup}Sr<{\egroup} V{3}*{5}{c}}
Question & 1 & 2 & 3 & 4 & 5\\
\hlineB{2}
Marks & x & x & x & y & z
\end{array} \]
\end{document} 

enter image description here

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.