# How to fix the same row height, column width and align vertically-center each cell?

I have the following table:

\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\renewcommand{\arraystretch}{2.2}

\begin{table}[H]
\centering
\caption{Tipos de funções de ativação}
\label{activacao}
\begin{tabular}{p{35mm}P{35mm}P{35mm}}
\toprule
\textbf{Nome}        & \textbf{Função $f$}                                                  & \textbf{Contradomínio}       \\ \midrule
Limiar               & $$\begin{cases} 1, & u_i \geq 0 \\ 0, & u_i < 0 \end{cases}$$                    & ${0,1}$             \\ \midrule
Linear               & $u_i$                                                                & $]-\infty,-\infty[$ \\ \midrule
Por troços           & $$\begin{cases} 1, & u_i \geq 0.5 \\ ku_i, & -0.5 < u_i < 0.5 \\ 0, & u_i \leq -0.5 \end{cases}$$                  & $[0,1]$             \\ \midrule
Logística            & $\frac{1}{1+e^{-ku_i}}$                                              & $[0,1]$             \\ \midrule
Tangente hiperbólica & $tanh(ku_i)$                                                         & $[-1,1]$            \\ \midrule
Sin                  & $sin(u_i \: mod \: 2\pi)$                                            & $[-1,1]$            \\ \midrule
Cos                  & $cos(u_i \: mod \: 2\pi)$                                            & $[-1,1]$            \\ \midrule
Gaussiana            & $e^{\frac{-u^2}{2k^2}}$                                              & $[-1,1]$            \\ \midrule
Quadrada             & $-sign(u_i)u_{}^{2}$                                                 & $]-\infty,-\infty[$ \\ \bottomrule
\end{tabular}
\end{table}

\renewcommand{\arraystretch}{1}~


And using:

\usepackage{multicol}
\usepackage{tabularx}
\usepackage{array}
\usepackage{booktabs}


And I'm getting this:

I wish to get the same row height for all rows (even though I used the \arraystretch cmd), the same column width and all 3 columns must be vertically center aligned. As for horizontal alignment, the first column should be on the left, and the other two on the middle. As you can sse by image above, the cells with \cases are vertically centered, but I don't know why. I tried with both p and m headers but with no success.

• Welcome to TeX.SE! Not an answer, but use \cos and \sin (Note the backslash) instead of cos and sin when in math mode. – Troy Apr 7 '17 at 14:41
• and please "transform your code snippets into one, complete MWE (Minimal Working Example) with \documentclass{...} on it beginning and \end{document} on the end. – Zarko Apr 7 '17 at 14:46

See, if this is satisfactory solution for you:

\usepackage[utf8]{inputenc}
\DeclareMathOperator{\sign}{sign}
\newcolumntype{P}[1]{>{\centering\arraybackslash}m{#1}} % vertical center cell contents

\begin{table}[hbt]
\centering
\caption{Tipos de funções de ativação}
\label{activacao}
\begin{tabular}{@{\rule[-8mm]{0mm}{18mm}\hspace{\tabcolsep}}% determine cells heights
P{35mm}
*{2}{>{$\displaystyle}P{35mm}<{$}}}
\toprule
\textbf{Nome}        &  \textbf{Função $f$}     &   \textbf{Contradomínio}       \\
\midrule
Limiar               &  \begin{cases} 1,    &
u_i \geq 0 \\
0,    & u_i < 0
\end{cases}
& {0,1}                         \\
\midrule
Linear               & u_i                      & ]-\infty,-\infty[             \\
\midrule
Por troços           &  \begin{cases} 1,    & u_i \geq 0.5      \\
ku_i, & -0.5 < u_i < 0.5  \\
0,    & u_i \leq -0.5
\end{cases}             & [0,1]                         \\
\midrule
Logística            & \frac{1}{1+e^{-ku_i}}    &   [0,1]                       \\
\midrule
Tangente hiperbólica & \tanh(ku_i)               & [-1,1]                       \\
\midrule
Sinus                & \sin(u_i \: mod \: 2\pi)  & [-1,1]                       \\
\midrule
Cosinus              & \cos(u_i \: mod \: 2\pi)  & [-1,1]                       \\
\midrule
Gaussiana            & \mathrm{e}^{\frac{-u^2}{2k^2}}   &   [-1,1]              \\
\midrule
\bottomrule
\end{tabular}
\end{table}


Edit: in solution is now considered Bernard comment.

• You forgot \usepackage[T1]{fontenc}! – Bernard Apr 7 '17 at 16:39
• @Bernard, I not forget .. OP didn't say, that it is necessary ... I ask him to provide MWE, but till now nothing happens :), so I use on old my file which was able generate this table and bother with font encoding ... – Zarko Apr 7 '17 at 17:50
• @Paulos, here is habit that instead say "thank you" your thankfulness express with voting of answer (by clicking on upper pen at top left side of answer) and even accept it with click on check mark there, – Zarko Apr 7 '17 at 17:57

I do not think that the same row height improve the quality of the table, it rather produces lots of unnecessary vertical space. Suggestions for improvements:

• Removal of the lines between ordinary rows. If the standard three lines (\toprule, \midrule, \bottomrule) are used, then the table structure is much clear (table area, header, body).

• Instead of the rules, additional white space separates the formulas more clearly. The example below uses \addlinespace of package booktabs and also shows, how the default (.5em) can be changed for the table.

• The third column can be centered at the comma. The example below realizes this by two columns using the comma as column separator. The tricky part is the lengthy column title. The excess width would go into the right column and the title would no longer be centered. Therefore, the example measures the title width and calculates the width portions for the two columns.

• The math operator names (tanh, sin, cos, sign) are usually typeset in an upright font. Package amsmath provides macros for most of them. New operators can be declared by \DeclareMathOperator.

• The cells inside a row are vertically aligned at the baseline, which should not be changed.

• The example uses the standard column width like l and c instead of fixed width. Fixed column widths make sense if the whole width of the table is too large and the cells contents should be broken across lines. But this is not necessary here.

Example (the lines are reformatted, because my editor and screen are limited by a width):

\documentclass{article}
\usepackage{amsmath}
\usepackage{array}
\usepackage{booktabs}
\usepackage{caption}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[utf8]{inputenc}
\usepackage[portuges]{babel}

\DeclareMathOperator{\sign}{sign}

\begin{document}
\begin{table}
\centering
\caption{Tipos de funções de ativação}
\label{activacao}
\begin{tabular}{lcr@{$,{}$}l}
\toprule
\textbf{Nome}
& \textbf{Função $f$}
& \multicolumn{1}{r@{$\hphantom{,{}}$}}{%
\sbox0{\textbf{Contradomínio}}\sbox2{$,{}$}%
}
\midrule
Limiar
& $$\begin{cases} 1, & u_i \geq 0 \\ 0, & u_i < 0 \end{cases}$$
& $0$ & $1$ \\
Linear
& $u_i$
& $]-\infty$ & $-\infty[$ \\
Por troços
& $\begin{cases} 1, & u_i \geq 0.5 \\ ku_i, & -0.5 < u_i < 0.5 \\ 0, & u_i \leq -0.5 \end{cases}$
& $[0$ & $1]$ \\
Logística
& $\frac{1}{1+e^{-ku_i}}$
& $[0$ & $1]$ \\
Tangente hiperbólica
& $\tanh(ku_i)$
& $[-1$ & $1]$ \\
Sin
& $\sin(u_i \mod 2\pi)$
& $[-1$ & $1]$ \\
Cos
& $\cos(u_i \mod 2\pi)$
& $[-1$ & $1]$ \\
Gaussiana
& $e^{\frac{-u^2}{2k^2}}$
& $[-1$ & $1]$ \\
& $-\sign(u_i)u_{}^{2}$
& $]-\infty$ & $-\infty[$ \\

• @Paulos Thanks, fixed in updated answer via \multicolumn` to override the column specification to remove the comma. – Heiko Oberdiek Apr 7 '17 at 17:12