0

My MWE is:

\documentclass[14pt]{article}

\begin{document}
\begin{tabular}{|c|}
\hline
$\displaystyle \frac{f(n)}{g(n)}$ \\
\hline
\end{tabular}
\end{document}

I would like to make the row height larger so that $f(n)$ does not touch the upper horizontal line. Additional requirement is that I would like to omit using fancy packages and I want that only one particular table is affected.

4
  • maybe try this: \hline \vspace{6pt} $\displaystyle ... $ \\ \vspace{6pt} \hline (a line of whitespace is needed below each vspace)
    – Nate
    Oct 5, 2023 at 6:12
  • note article does not have a 14pt option (your example file warns about that) Oct 5, 2023 at 7:32
  • @Nate vspace in a c column will do nothing useful Oct 5, 2023 at 7:33
  • what do you count as a "fancy" pckage? array for example should almost always be used for tables, and amsmath should almost always be used for math. array would help here. Both are part of the core latex distribution, and so as fundamental as article class which you are using Oct 5, 2023 at 7:33

2 Answers 2

2

I'd define a \tabdfrac command that takes the arguments as \frac, but also an optional argument for the separation (default 3pt).

The idea is to typeset \dfrac in a box and increase both the height and depth thereof by the specified separation.

\documentclass{article}
\usepackage{amsmath}

\makeatletter
\newcommand{\tabdfrac}[3][3pt]{%
  \sbox\z@{$\m@th\dfrac{#2}{#3}$}%
  \increase@dfrac\ht{#1}%
  \increase@dfrac\dp{#1}%
  \box\z@
}
\newcommand{\increase@dfrac}[2]{%
  \dimen@=#1\z@ \advance\dimen@ #2
  #1\z@=\dimen@
}
\makeatother

\begin{document}

\begin{tabular}{|c|}
\hline
$\tabdfrac{f(n)}{g(n)}$ \\
\hline
\end{tabular}
\quad
\begin{tabular}{|c|}
\hline
$\tabdfrac[6pt]{f(n)}{g(n)}$ \\
\hline
\end{tabular}

\end{document}

enter image description here

2

I have increased the table rows height of a single table. I have added \renewcommand{\arraystretch}{2.5} before tabular and I have increased further the row with \\[1em].

enter image description here

\documentclass[14pt]{article}

\begin{document}
\renewcommand{\arraystretch}{2.5}
\begin{tabular}{|c|}
\hline 
$\displaystyle \frac{f(n)}{g(n)}$ \\[1em]
\hline
\end{tabular}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .