7

I need to display fractions within a table and it requires to set

\renewcommand{\arraystretch}{2.3}

The problem is that not all rows contain fractions, and in this cases the white space below and above is too big. I can tweak it manually with something like \\[-2ex]. This works for the middle cases, though its a little inconvenient, but I have no idea how to reduce the absolute top space.

Something like

\vspace{-2ex}

has no effect.

The best would be to be able to change the arraystretch for a single table row, but the command has no effect after \begin{tabular}. How can I solve this issue?

enter image description here

MWE

\documentclass{article}

\usepackage{amsmath}
\usepackage{booktabs}

\begin{document}

\begin{table}
    \renewcommand{\arraystretch}{2.3}

    \begin{tabular}{@{}c|l@{}}
            \bfseries $R_x$ & Symbol\\
            \hline\hline
            $\dfrac{a}{b}$ & $ \dfrac{A}{B} $\\
            $\dfrac{a}{b}$ & $ \dfrac{A}{B} $\\
            $\dfrac{a}{b}$ & $ \dfrac{A}{B} $\\
            \hline
    \end{tabular}
\end{table}

\end{document}

MWE with siunitx

\documentclass{article}

\usepackage{amsmath}
\usepackage{booktabs}
%\usepackage{siunitx}
\usepackage{wrapfig}

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

\begin{document}

\begin{wrapfigure}[14]{R}{8.5cm}
    \renewcommand{\arraystretch}{2.3}

    \begin{tabular}{@{}Sc|Sl@{}}
            \bfseries $R_x$ & Symbol\\
            \hline\hline
            $\dfrac{a}{b}$ & $ \dfrac{A}{B} $\\
            some text & some other text \\
            $\dfrac{a}{b}$ & $ \dfrac{A}{B} $\\
            $\dfrac{a}{b}$ & $ \dfrac{A}{B} $\\
            \hline
    \end{tabular}
\end{wrapfigure}

\end{document}
11

The best solution is to use the cellspace package: it defines an adjustable minimal vertical padding around a cell. For this, you have to prefix the column specifier with the letter S (or C if you load siunitx).

With \arraystretch, there are two drawbacks: first the cell contents is no more vertically centred, and second, you have to determine, by trial and error, the stretch value – any modification of the contents may result in a new value, as is demonstrated in the following, where I modified one fraction, keeping the value you gave:

\documentclass{article}

\usepackage{amsmath}
\usepackage{booktabs, cellspace, hhline}
\setlength\cellspacetoplimit{4pt}
\setlength\cellspacebottomlimit{4pt}

\begin{document}

\begin{table}
  \renewcommand{\arraystretch}{2.3}
  \begin{tabular}{@{}c|l@{}}
    \bfseries $R_x$ & Symbol \\
    \hline\hline
    $\dfrac{a}{b}$ & $ \dfrac{A}{B} $ \\
    \hline
    $\dfrac{a}{b}$ & $ \dfrac{A}{B + \cfrac{C}{D}} $ \\
    \hline
    $\dfrac{a}{b}$ & $ \dfrac{A}{B} $ \\
    \hline
  \end{tabular}
\hskip2cm
  \begin{tabular}{@{}Sc|Sl@{}}
    \bfseries $R_x$ & Symbol \\
    \hline\hline
    $\dfrac{a}{b}$ & $ \dfrac{A}{B} $ \\
    \hline
    $\dfrac{a}{b}$ & $ \dfrac{A}{B + \cfrac{C}{D}} $ \\
    \hline
    $\dfrac{a}{b}$ & $ \dfrac{A}{B} $ \\
    \hline
  \end{tabular}
\end{table}
\end{document} 

rendered document

4
  • There are weird things happening when siunitx is loaded (changing of layout or erros, depending on content of tabular. Can you check my other MWE? .. which according to google seems to be a known, but 5 year old problem. – thewaywewalk Apr 7 '16 at 10:40
  • 1
    I forgot to mention it, as your code didn't load siunitx: S is a column type defined by siunitx. The answer is in the siunitx manual: use C as a pre-specifier instead (Cc, Cl, Cr) – Bernard Apr 7 '16 at 10:44
  • Now it works like a charm, thanks for letting me know about this great package. However as siunitx is such a heavy used package, you may should include your comment within your answer. – thewaywewalk Apr 7 '16 at 10:47
  • I'll do it. Note cellspace doesn't work in all situations, unfortunately. – Bernard Apr 7 '16 at 10:52
4

Similar result as with cellspace package, as propose Bernard, you can obtain with makecell package:

enter image description here

\documentclass{article}
\usepackage{amsmath}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{wrapfig}

\usepackage{makecell}% <-- for gaped cells

\begin{document}

\begin{wrapfigure}[14]{R}{8.5cm}
\setcellgapes{3pt}
\makegapedcells
    \begin{tabular}{@{}>{$\displaystyle}c<{$}|>{$\displaystyle}l<{$}@{}}
R_x                 &   \text{Symbol}           \\
    \hline\hline
\frac{a}{b}         &   \frac{A}{B}             \\
    \hline
\text{some text}    &   \text{some other text}  \\
    \hline
\frac{a}{b}         &   \frac{A}{B}             \\
    \hline
\frac{a}{b}         &   \frac{A}{B}             \\
    \hline
    \end{tabular}
\end{wrapfigure}
\end{document}

Note: Also \makegapedcells doesn't work in all circumstances. For example, it prevent coloring rows/columns with use \colortbl or [table]{xcolor} packages.

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.