2

I have the following table almost finished (I tried to make the code as much readable as I could)

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{tikz}
\usepackage{mathtools}
\usepackage{array}

\begin{document}
    \begin{center}
        \renewcommand{\arraystretch}{1.6}
        \begin{equation*}
        \begin{array}{ | >{\centering\arraybackslash$} p{4.0cm} <{$} 
            | >{\centering\arraybackslash$} p{4.0cm} <{$} 
            | >{\centering\arraybackslash$} p{4.0cm} <{$}
            | } \hline
        a+\infty=\infty & a-\infty=-\infty & \infty+\infty=\infty \\ \hline                              % End of 1st row

        -\infty-\infty=-\infty & \infty\cdot\infty=\infty & -\infty\cdot\infty=-\infty \\ \hline         % End of 2nd row

        \dfrac{a}{\infty}=0         & 

        \dfrac{a}{0}=
        \left\{ \renewcommand{\arraystretch}{1}
        \begin{tabular}{c}
        $ \infty $ si $ a>0 $\\
        $ -\infty $ si $ a<0 $
        \end{tabular} \right.\ &

        \infty^a=
        \left\{ \renewcommand{\arraystretch}{1}
        \begin{tabular}{c}
        $ \infty $ si $ a>0 $\\
        $ 0 $  si $ a<0 $
        \end{tabular}\right.\ \\ \hline                                                                  % End of 3rd row

        \infty^\infty=\infty&\infty^{-\infty}=0&

        a^\infty=
        \left\{ \renewcommand{\arraystretch}{1}
        \begin{tabular}{c}
        $ \infty $ si $ a>1 $\\
        $ 0 $  si $ 0\leq a<1 $
        \end{tabular}\right.\ \\ \hline                                                                  % End of 4th row

        \cellcolor{gray!25}& 0^a=0\text{ si $ a>0 $} &\cellcolor{gray!25}  \\ \hline                       % End of 5th row

        \end{array}
        \end{equation*}
    \end{center}
\end{document}

Several problems here:

  • I managed to make the columns to have the same width but I have to copy-paste that code every time I want to make a column with that property (maybe some redefinition with \renewcommand?)
  • When I use tabular inside the array environment the curly brackets are too close from the cell limits, and I wonder if you can redefine the size of all the cells of those rows to fit those tables.
  • Is there an option that array (or tabular) could get that stretch the array without having to use \renewcommand{\arraystretch}{<number>} every time I make a new table?

I'm looking for a general solution, not only for this problem, since I will define a lot of tables in my next report, and for sure a lot of people will appreciate a general solution since I see lots of questions about this mysterious world of LaTeX tables.

1
  • One quick comment: \begin{center}\begin{equation*} is not a correct way to center equations.
    – user121799
    Jan 31, 2019 at 4:39

1 Answer 1

1

You can create a new column type this way:

\newcolumntype{C}{>{\centering\arraybackslash $}p{\mylen}<{$}}

and then use it in your array column definition:

\begin{array}{|C|C|C|}

\mylen is defined such as to have 3 columns with the same width but to not generate Overfull hbox (for the explanation, see, for example, here. I also used a smaller font size.

To enlarge the cell height I have used \mystrut{<length>} to put a gap before the content and \\[<length>] to put a gap after it. I didn't renew \arraystrech because this affects also the spacing in cases environment, which I used instead of tabular.

As marmot said in his comment, no need to put an equation environment in a center one, it is already centered.

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{mathtools}
\usepackage{array}
\usepackage{calc}
\newlength{\mylen}
\setlength{\mylen}{\linewidth/3-2\tabcolsep-\arrayrulewidth-\arrayrulewidth/3}
\newcolumntype{C}{>{\centering\arraybackslash $}p{\mylen}<{$}}
\newcommand{\mystrut}[1]{\rule{0pt}{#1}}

\begin{document}
\begin{equation*}\small
    \begin{array}{|C|C|C|} 
    \hline
    \mystrut{12pt} a+\infty=\infty & a-\infty=-\infty & \infty+\infty=\infty \\[4pt] 
    \hline                              % End of 1st row
    \mystrut{12pt} -\infty-\infty=-\infty & \infty\cdot\infty=\infty & -\infty\cdot\infty=-\infty \\[4pt] \hline         % End of 2nd row
    \mystrut{26pt}\dfrac{a}{\infty}=0         & 
    \dfrac{a}{0}=
    \begin{cases}
     \infty  & \text{si }  a>0 \\
     -\infty  & \text{si }  a<0 
    \end{cases} &
    \infty^a=
    \begin{cases}
     \infty & \text{si }  a>0 \\
     0  & \text{si }  a<0 
    \end{cases} \\[20pt]
    \hline                                % End of 3rd row
    \mystrut{26pt}\infty^\infty=\infty&\infty^{-\infty}=0&

    a^\infty=
    \begin{cases}
     \infty & \text{si } a>1 \\
     0  & \text{si } 0\leq a<1 
    \end{cases} \\[20pt] 
    \hline                                % End of 4th row
\cellcolor{gray!25}& \mystrut{14pt}0^a=0\text{ si $ a>0 $} &\cellcolor{gray!25}  \\[4pt]
\hline                       % End of 5th row
    \end{array}
\end{equation*}

\end{document}

enter image description here

3
  • 2
    I decline any responsibility for the correctness of the math in this answer.
    – CarLaTeX
    Jan 31, 2019 at 7:07
  • I have laughed with that comment :)
    – Martín
    Jan 31, 2019 at 11:42
  • @Martín lol, thank you for accepting my answer :)
    – CarLaTeX
    Jan 31, 2019 at 14:07

You must log in to answer this question.

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