[Tex/LaTex] Problem with fit a table in beamer

beamertables

I try to use \resizebox to fit table in slide, but I reach some error. Please help me fix this problem.

\documentclass{beamer}
\usepackage{graphicx}
\usepackage[labelsep=quad,indention=10pt]{subfig}
\usepackage{tikz}
\usetikzlibrary{matrix,chains,positioning,decorations.pathreplacing,arrows,calc,}
\usetikzlibrary{decorations.markings}
\usepackage{booktabs}% http://ctan.org/pkg/booktabs
\usepackage{array}% http://ctan.org/pkg/array
\usepackage{amsmath,amsthm,relsize}
\usepackage{adjustbox}
\def \symstalinear{ 
$f(x) = 
\begin{cases}
    -1,                 & \quad \hfill x<-1.\\
    \phantom{-}x,       & \quad \hfill -1 \leq x \leq1\\
    \phantom{-}1,       & \quad \hfill x>1
\end{cases}$
}
\def \hardlimit{
$f(x) = \begin{cases}
  0 &\quad \hfill x<0\\
  1 &\quad \hfill x \geq 0\\
\end{cases}
$
}
\begin{document}
\frame{
 \resizebox{width=\textwidth}{height=\textheight}{
\begin{table}[h!]
    \begin{center}
        \begin{tabular}{ l >{$}c<{$} >{$}c<{$}}
        \toprule
        \textbf{Function} & \multicolumn{1}{c}{\textbf{Definition}}  & \multicolumn{1}{c}{\textbf{Range}} \\
        \midrule
        Linear & f(x)=x & (-\infty,\infty) \\[2ex]
        Log-sigmoid & \dfrac{1}{1+e^{-x}}&(0,1)\\[3ex]
        Hyperbolic Tangent Sigmoid & \dfrac{e^x-e^{-x}}{e^x+e^{-x}}&(-1,1)\\[3ex]
        Symmetric Saturating Linear & $\symstalinear$ & [-1,1] \\[3ex]
        Hard limit & $\hardlimit$ &[0,1]\\
        \bottomrule
        \end{tabular}

    \end{center}
\caption{Definitons of activation function}
\label{tbl:def of act func}
\end{table}%
}
}
\end{document}

Best Answer

The command is error for your \resizebox. Should be

\resizebox{xxcm}{!} {  % ! keep the aspectratio with xx width, no need to use width=xx. 
  \begin{tabular}...
  \end{tabular}
}

Also \scalebox from graphicx works too.

\scalebox{0.7}{
  \begin{tabular}...
  \end{tabular}
}

enter image description here

Code

\documentclass{beamer}
\usepackage{graphicx}
\usepackage[labelsep=quad,indention=10pt]{subfig}
%\usepackage{tikz}
%\usetikzlibrary{matrix,chains,positioning,decorations.pathreplacing,arrows,calc,}
%\usetikzlibrary{decorations.markings}
\usepackage{booktabs}% http://ctan.org/pkg/booktabs
\usepackage{array}% http://ctan.org/pkg/array
\usepackage{amsmath,amsthm,relsize}
%\usepackage{adjustbox} % This seems to cause a problem too.
\def\symstalinear{% 
$f(x) = 
\begin{cases}
    -1,                 & \quad \hfill x<-1.\\
    \phantom{-}x,       & \quad \hfill -1 \leq x \leq1\\
    \phantom{-}1,       & \quad \hfill x>1
\end{cases}$
}
\def\hardlimit{%
$f(x) = \begin{cases}
  0 &\quad \hfill x<0\\
  1 &\quad \hfill x \geq 0
\end{cases}
$
}
\begin{document}
\frame{
\begin{table}[h!]
    \begin{center}
\resizebox{\textwidth}{!}{
        \begin{tabular}{ l >{$}c<{$} >{$}c<{$}}
        \toprule
        \textbf{Function} & \multicolumn{1}{c}{\textbf{Definition}}  & \multicolumn{1}{c}{\textbf{Range}} \\
        \midrule
        Linear & f(x)=x & (-\infty,\infty) \\[2ex]
        Log-sigmoid & \dfrac{1}{1+e^{-x}}&(0,1)\\[3ex]
        Hyperbolic Tangent Sigmoid & \dfrac{e^x-e^{-x}}{e^x+e^{-x}}&(-1,1)\\[3ex]
        Symmetric Saturating Linear & $\symstalinear$ & [-1,1] \\[3ex]
        Hard limit & $\hardlimit$ &[0,1]\\
        \bottomrule
        \end{tabular}
}
    \end{center}
\caption{Definitons of activation function}
\label{tbl:def of act func}
\end{table}%
}
\end{document}
Related Question