4

Creating a table using tabulary I am confronted with the problem that the lines of my table are too small, resulting in that the formulas touch the borders of the table. The code I used is given below.

\documentclass{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{tabulary}
\usepackage{booktabs}
\usepackage{tabularx}

\begin{document}

\centering
\begin{tabulary}{18cm}{R|L L L}
\toprule
\hline
Mean squared error & MSE &= &$\frac{1}{n}\sum_{t=1}^{n}e_t^2$   \\
\hline
Root mean squared error & RMSE &= &$\sqrt{\frac{1}{n}\sum_{t=1}^{n}e_t^2}$ \\
\hline
Mean absolute error & MAE &= &$\frac{1}{n}\sum_{t=1}^{n}|e_t|$ \\
\hline
Mean absolute percentage error & MAPE &= &$\frac{100\%}{n}\sum_{t=1}^{n}\left |\frac{e_t}{y_t}\right|$\\
\hline\bottomrule
\end{tabulary}
\end{document}

How can I increase vertical space in my table so that it looks appropriate?

enter image description here

  • Even if an answer has been accepted, I suggest also to try taking a look at this answer. – alandella Apr 8 '14 at 18:07
2

Don't use \hline and also remove the vertical rule that adds no information and simply interrupts the flow of reading.

\documentclass{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{tabulary}
\usepackage{booktabs}
\usepackage{amsmath}

\begin{document}

\centering
\begin{tabulary}{18cm}{L R @{} >{${}}c<{{}$} @{} L}
\toprule
Mean squared error & MSE &= &$\displaystyle\frac{1}{n}\sum_{t=1}^{n}e_t^2$   \\
\midrule
Root mean squared error & RMSE &= &$\displaystyle\sqrt{\frac{1}{n}\sum_{t=1}^{n}e_t^2}$ \\
\midrule
Mean absolute error & MAE &= &$\displaystyle\frac{1}{n}\sum_{t=1}^{n}|e_t|$ \\
\midrule
Mean absolute percentage error & MAPE &= &$\displaystyle\frac{100\%}{n}\sum_{t=1}^{n}\left |\frac{e_t}{y_t}\right|$\\
\bottomrule
\end{tabulary}
\end{document}

enter image description here

I'm not sure you really need tabulary: this gives exactly the same result.

\documentclass{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{array}
\usepackage{booktabs}
\usepackage{amsmath}

\begin{document}

\centering
\begin{tabular}{l r @{} >{${}}c<{{}$} @{} l}
\toprule
Mean squared error & MSE &= &$\displaystyle\frac{1}{n}\sum_{t=1}^{n}e_t^2$   \\
\midrule
Root mean squared error & RMSE &= &$\displaystyle\sqrt{\frac{1}{n}\sum_{t=1}^{n}e_t^2}$ \\
\midrule
Mean absolute error & MAE &= &$\displaystyle\frac{1}{n}\sum_{t=1}^{n}|e_t|$ \\
\midrule
Mean absolute percentage error & MAPE &= &$\displaystyle\frac{100\%}{n}\sum_{t=1}^{n}\left |\frac{e_t}{y_t}\right|$\\
\bottomrule
\end{tabular}
\end{document}
  • Thanks! How can I increase the width of the table, for example, so that it adopts to the width of the page? – DatamineR Apr 8 '14 at 16:11
  • @JohnnyB Don't do it. There's no reason (except following bad practice with word processors) for expanding a table beyond its natural width. – egreg Apr 8 '14 at 16:12
2

Without tabulary (works also with tabulary

\documentclass{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{array,booktabs}
\usepackage{amsmath}

\begin{document}

{\def\arraystretch{2.5}
\begin{tabular}{@{} l r @{} >{${}}c<{{}$} @{} l @{}}
\toprule
Mean squared error & MSE &= &$\dfrac{1}{n}\sum\limits_{t=1}^{n}e_t^2$   \\
\midrule
Root mean squared error & RMSE &= &$\sqrt{\dfrac{1}{n}\sum\limits_{t=1}^{n}e_t^2}$ \\
\midrule
Mean absolute error & MAE &= &$\dfrac{1}{n}\sum\limits_{t=1}^{n}|e_t|$ \\
\midrule
Mean absolute percentage error & MAPE &= &$\dfrac{100\%}{n}\sum\limits_{t=1}^{n}\left |\frac{e_t}{y_t}\right|$\\
\bottomrule
\end{tabular}}

\end{document}

enter image description here

0

The cellspace package ensures a minimal spacing between the top of a cell and the bottom of the above cell and independantly between the bottom of the cell and the top of the below cell. So you can have better vertical spacing of cells and contents of cells vertically centred, which is not the case if you play with \arraystretch. Makecell allows for horizontal lines of varying thickness, with the Xhline command.

In addition I simplified the original code (1 column less): \documentclass{scrartcl} \usepackage[utf8]{inputenc} \usepackage{tabulary} \usepackage{booktabs} \usepackage{amsmath}

\usepackage{cellspace}
\setlength{\cellspacetoplimit}{6pt}
\setlength{\cellspacebottomlimit}{6pt}

\usepackage{makecell}
\newcommand*{\topdblline}{\Xhline{0.15ex}\\[-2.6ex]\hline}
\newcommand*{\botdblline}{\hline\\[-2.6ex]\Xhline{0.15ex}}

\begin{document}

\centering
\begin{tabulary}{18cm}{L @{\qquad}R @{${}={}$} >{$\displaystyle}SL<{$}}%{L R @{} >{${}}c<{{}$} @{} SL}
\topdblline
Mean squared error & MSE  & \frac{1}{n}\sum_{t=1}^{n}e_t^2    \\
\hline
Root mean squared error & RMSE & \sqrt{\frac{1}{n}\sum_{t=1}^{n}e_t^2}  \\
\hline
Mean absolute error & MAE &  \frac{1}{n}\sum_{t=1}^{n}|e_t|  \\
\hline
Mean absolute percentage error & MAPE & \frac{100\%}{n}\sum_{t=1}^{n}\left |\frac{e_t}{y_t}\right| \\
\botdblline
\end{tabulary}

\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.