4

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}
2
  • 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
  • 2
    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
8

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:

enter image description here

5

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

enter image description here

\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}
2

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} 

enter image description here

1

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

enter image description here

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

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.