# How to change the dimension of a table to fit a fraction?

It's a stupid question but I'm not able to solve it. In this very simple example i would like to understand how to change the dimension of the table in order to have a better look expecially for the last element \frac{5x}{3}. I tried with displaystyle but it not worked. Thank you.

\documentclass[11pt]{article}
\usepackage{array}
\newcolumntype{C}{>{\displaystyle}c}
\begin{document}

$\begin{array}{|C|C|C|C|C|} \hline x & 1 & 2 & 3 & 4 \\ \hline f(x) & x^2 & x^4+2 & 15 & \frac{5x}{3} \\ \hline \end{array}$

\end{document}

• your first math expression is just $\displaystyle{{$ so has two mismatched {the syntax would be $\displaystyle f(x)$ but it only applies to that expression. – David Carlisle Nov 27 '17 at 22:53
• I've taken the liberty of editing your code, both to make it compilable and to make it easier to read. – Mico Nov 27 '17 at 22:59

with use of makecell package you can define gapes above and below cell content. for example:

\documentclass[11pt]{article}
\usepackage{array, makecell}  % <---
\newcolumntype{C}{>{\displaystyle}c}
\setcellgapes{5pt}            % <---
\begin{document}

$\makegapedcells % <--- \begin{array}{|C|C|C|C|C|} \hline x & 1 & 2 & 3 & 4 \\ \hline f(x) & x^2 & x^4+2 & 15 & \frac{5x}{3} \\ \hline \end{array}$

\end{document}


which gives:

Adding \mathstrut directives in both the numerator and the denominator of the final fraction may achieve your formatting objective(s).

\documentclass[11pt]{article}
\usepackage{array}
\newcolumntype{C}{>{\displaystyle}c}
\setlength\extrarowheight{2pt}

\begin{document}
$\begin{array}{|C|C|C|C|C|} \hline x & 1 & 2 & 3 & 4 \\ \hline f(x) & x^2 & x^4+2 & 15 & \frac{5x\mathstrut}{3\mathstrut} \\ \hline \end{array}$
\end{document}


Another solution with cellspace; which defines minimal vertical padding at the top and bottom of cells in columns prefixed with the letter S:

\documentclass[11pt]{article}
\usepackage{array}
\usepackage[math]{cellspace}
\setlength{\cellspacetoplimit}{4pt}
\setlength{\cellspacebottomlimit}{4pt}
\newcolumntype{C}{>{$\displaystyle}Sc<{$}}

\begin{document}

$\begin{array}{|*{5}{C|}} \hline x & 1 & 2 & 3 & 4 \\ \hline f(x) & x^2 & x^4+2 & 15 & \frac{5x}{3} \\ \hline \end{array}$

\end{document}


I have added, instead, only the package mathtools and the command \dfrac+\strut. It works fine an I have used few code.

\documentclass[11pt]{article}
\usepackage{array, mathtools}
\newcolumntype{C}{>{\displaystyle}c}
\begin{document}

$\begin{array}{|C|C|C|C|C|} \hline x & 1 & 2 & 3 & 4 \\ \hline f(x) & x^2 & x^4+2 & 15 & \dfrac{\strut 5x}{\strut 3} \\ \hline \end{array}$

\end{document}