[Tex/LaTex] Function sign table, complete with first and second derivative, plus concavity/convexity and asymptotic behaviour – a better way

tables

There has got to be a better/easier way to do this!! And by the way, how does one format the code [when posting a question] to look nice, compact, and full of colours?

\documentclass{article}

\usepackage[2.5cm]{geometry}% http://ctan.org/pkg/geometry
\usepackage{amsmath}% http://ctan.org/pkg/amsmath

\begin{document}
\begin{tabular}{ l || l c c c c c c c r |}  
  $x$ \vspace{1pt}  
  & $ -\, \infty $  
  & \hspace*{-0.5cm}   
  & \hspace*{-0.5cm} $ -\, 1 $  
  & \hspace*{-0.5cm}  
  & \hspace*{-0.7cm} $0$  
  & \hspace*{-1.0cm}  
  & \hspace*{-0.5cm} $+\, 1$  
  & \hspace*{-0.5cm}  
  & \hspace*{-0.5cm} $ +\, \infty $ \\  
\hline

  \parbox[t][1.0cm]{2.0cm}{\vspace{1pt} $y' \,=\, \dfrac{\,x^{2} \,-\, 1\,}{x^{2}}$ \vspace{1pt}}  
  & $\begin{array}{c} \\ + \quad +\\ \end{array}$  
  & \hspace*{-0.5cm} $\begin{array}{c} \\ + \quad + \quad +  \\ \end{array}$  
  & \hspace*{-0.5cm} $\begin{array}{c} \\ 0 \\ \end{array}$  
  & \hspace*{-0.5cm} $\begin{array}{c} \\ - \quad - \quad - \\ \end{array}$  
  & \hspace*{-0.7cm} $\begin{array}{c} \\ \vert \\ \end{array}$  
  & \hspace*{-1.0cm} $\begin{array}{c} \\ - \quad - \quad - \\ \end{array}$  
  & \hspace*{-0.5cm} $\begin{array}{c} \\ 0 \\ \end{array}$  
  & \hspace*{-0.5cm} $\begin{array}{c} \\ + \quad + \quad + \\ \end{array}$  
  & \hspace*{-1.0cm} $\begin{array}{c} \\ + \\ \end{array}$ \\  
\hline 

  \parbox[t][1.0cm]{2.0cm}{\vspace{1pt} $y'' \,=\, \dfrac{2}{\,x^{3}\,}$ \vspace{1pt}}  
  & $\begin{array}{c} \\ - \quad - \\ \end{array}$  
  & \hspace*{-0.5cm} $\begin{array}{c} \\ - \quad - \quad - \\ \end{array}$  
  & \hspace*{-0.5cm} $\begin{array}{c} \\ - \\ \end{array}$  
  & \hspace*{-0.5cm} $\begin{array}{c} \\ - \quad - \quad - \\ \end{array}$  
  & \hspace*{-0.7cm} $\begin{array}{c} \\ \vert \\ \end{array}$  
  & \hspace*{-1.0cm} $\begin{array}{c} \\ + \quad + \quad + \\ \end{array}$  
  & \hspace*{-0.5cm} $\begin{array}{c} \\ + \\ \end{array}$  
  & \hspace*{-0.5cm} $\begin{array}{c} \\ + \quad + \quad + \\ \end{array}$  
  & \hspace*{-1.0cm} $\begin{array}{c} \\ + \\ \end{array}$ \\  
\hline 

  \parbox[t][1.0cm]{2.0cm}{ $y \,=\, x \,+\, \dfrac{1}{\,x\,}$ }  
  & $-\, \infty \;\; \nearrow$  
  & \hspace*{-0.5cm} $ \begin{array}{c} \\ \nearrow \quad \nearrow \quad \nearrow \\ \bigcap \end{array} $  
  & \hspace*{-0.5cm} $ -\, 2 $  
  & \hspace*{-0.5cm} $ \begin{array}{c} \\ \searrow \quad \searrow \quad \searrow \\ \bigcap \end{array} $  
  & \hspace*{-0.7cm} $ \;\genfrac{}{}{0.0pt}{}{}{}_{-\,\infty} {\Big |}^{+\, \infty}\; $  
  & \hspace*{-0.7cm} $ \begin{array}{c} \\ \searrow \quad \searrow \quad \searrow \\ \bigcup \end{array} $  
  & \hspace*{-0.5cm} $ +\, 2 $  
  & \hspace*{-0.5cm} $ \begin{array}{c} \\ \nearrow \quad \nearrow \quad \nearrow \\ \bigcup \end{array} \vspace{2pt} $  
  & \hspace*{-1.0cm} $+\, \infty$ \\  
\hline  

\end{tabular}\\
\end{document}

Best Answer

In my original comment, I asked if your code came from a WYSIWYG, because it looked as if it had a lot of unnecessary code- typically you get this kind of code when (attempting) to export from another program to TeX.

Anyway, here's my version of your table:

screenshot

In the code below I have

  • deleted all of the \begin{array}{c}...\end{array}
  • deleted all of the \hspace*{...}
  • loaded the booktabs package which gives lots of useful features for tables, including \toprule, \midrule, and \bottomrule
  • loaded the tabularx package to allow the table to stretch to (in this case) the \textwidth
  • made the row separation larger by changing \arraystretch

You'll also notice that I have been quite sparing with my +, -, \searrow, and \nearrow. As the examples get more complicated and you need to consider more intervals, you would necessarily need to delete a lot of them anyway.

If you want to see how wide the table is, you can change showframe=true in the loading of the geometry package. If ever you want your table to be wider than the standard textwidth, then you can enclose it in an adjustwidth environment from the changepage package.

\documentclass{article}

\usepackage[showframe=false]{geometry}
\usepackage{booktabs}
\usepackage{amsmath}
\usepackage{tabularx}

% use this package if you want to temporarily 
% widen the page
%\usepackage{changepage}

% use this columntype if you want to RIGHT justify your columns
\newcolumntype{Y}{>{\raggedleft\arraybackslash}X}


\begin{document}

\renewcommand{\arraystretch}{3}

\noindent\begin{tabularx}{\textwidth}{p{2cm}XXXXXXXXX}
 \toprule
    $x$                         &       $-\infty$   &                  &  $-1$ &                   &   $0$                      &                  &   $+1$  &                   &   $\infty$    \\ \midrule
    $y'=\dfrac{x^2-1}{x^2}$     &       $+$         &      $+$         &  $0$  &       $-$         &   $|$                      &   $-$            &   $0$   &      $+$          &   $+$         \\
    $y''=\dfrac{2}{x^3}$        &       $-$         &      $-$         &  $-$  &       $-$         &   $|$                      &   $+$            &   $+$   &      $+$          &   $+$         \\
    $y=x+\dfrac{1}{x}$          &       $-\infty$   & $\nearrow\bigcap$&  $-2$ & $\searrow\bigcap$ &   ${}_{-\infty}|^{+\infty}$&$\searrow\bigcup$ &   $+2$  & $\nearrow\bigcup$ &   $\infty$\\
 \bottomrule
\end{tabularx}



\end{document}