2

EDIT:

In order to make this question more beneficial for others, what I'm asking is how to simply vertically center the contents of a ''cell'', without having to modify all of the other parameters you have already established in the making of your table.

Is there any way to do this?

ORGINAL:

I'm trying to vertically center the contents of the following table:

\documentclass{article}
\usepackage[a4paper,margin=1in,landscape]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{float}
\usepackage{array}

\begin{document}

\begin{center}
    {\large\textbf{{Gu\'ia Probabilidad}}}
    \noindent\makebox[\linewidth]{\rule{\textwidth}{1pt}}
\end{center}

\subsection*{Distribuciones Discretas:}

\begin{table}[H]
\center
    \begin{tabular}{||c|c|c|c|c|c c@{}||}
    \hline  
    Distribución & Funci\'on de masa de probabilidad & Par  \'ametros & Media & Varianza & Funci\'on generadora de momentos&\\
    \hline
    \hline
    \textit{Bernoulli} & $f(x) = p^x q^{1-x}I_{\{0,1\}}(x)$ & $0< p <1$ & $p$ & $p(1-p)$ & $(1-p) + pe^t$&\\[5ex]
    \hline
    \textit{Binomial} & $f(x) = \begin{pmatrix}n\\x\end{pmatrix}p^x(1-p)^{n-x}I_{0,1,\ldots,n}(x)$ & $0<p<1$ & $np$ & $np(1-p)$ & $(1-p + pe^t)^n$&\\[5ex]
\end{tabular}
\end{table}

\end{document}

I've already checked the answers of similar questions, but I just can't seem to find a simple answer. For example, the answers in this question distort the vertical alignment of my cells.

I think there just should be a really simple way to do this.

Thanks for the help.

PS for some reason I can't upload the image of my table...

  • help us to help you! extend your code snippet to full document, which we can copy to our PC and test then! also remove all errors in your code. – Zarko Oct 10 '17 at 1:06
  • A quibble with the contents of your table: The binomial distribution has 2 parameters, not just 1: n and p. – Mico Oct 10 '17 at 2:00
  • 1
    @Mico that's true. Will add it! – migueldva Oct 10 '17 at 2:03
2

like this?

enter image description here

\documentclass{article}
\usepackage[a4paper,margin=1in,landscape]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}
\usepackage{amsmath, amssymb}
\usepackage{graphicx}
\usepackage{float}
\usepackage{array, makecell}
\setcellgapes{5pt}

\begin{document}

\begin{center}
    {\large\textbf{{Gu\'ia Probabilidad}}}
    \noindent\makebox[\linewidth]{\rule{\textwidth}{1pt}}
\end{center}

\subsection*{Distribuciones Discretas:}

\begin{table}[H]
\center
\makegapedcells
    \begin{tabular}{||c|c| c|c| c|c||}
    \hline
    Distribución & Funci\'on de masa de probabilidad & Par  \'ametros & Media & Varianza & Funci\'on generadora de momentos\\
    \hline
    \hline
    \textit{Bernoulli} &  $f(x) = p^x q^{1-x}I_{\{0,1\}}(x)$ & $0< p <1$ & $p$ & $p(1-p)$ & $(1-p) + pe^t$\\
    \hline
    \textit{Binomial} & $f(x) = \begin{pmatrix}n\\x\end{pmatrix}p^x(1-p)^{n-x}I_{0,1,\ldots,n}(x)$ & $0<p<1$ & $np$ & $np(1-p)$ & $(1-p + pe^t)^n$\\
\end{tabular}
\end{table}

\end{document}

note: in your mwe is defined seven columns, but used only six. therefore i deleted last (empty) columns. i use makecell package for adding vertical space to cells' contents.

edit: it seems that you looking for this:

enter image description here

\documentclass{article}
\usepackage[a4paper,margin=1in,landscape]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}
\usepackage{amsmath, amssymb}
\usepackage{graphicx}
\usepackage{float}
\usepackage{array, makecell}
\setcellgapes{3pt}

\begin{document}

\begin{center}
    {\large\textbf{{Gu\'ia Probabilidad}}}
    \noindent\makebox[\linewidth]{\rule{\textwidth}{1pt}}
\end{center}

\subsection*{Distribuciones Discretas:}

\begin{table}[H]
\center
\makegapedcells
    \begin{tabular}{||c|c| c|c| c|c<{\rule[-2.2em]{0pt}{5em}} ||}
    \hline
    Distribución 
        & Funci\'on de masa de probabilidad 
            & Par  \'ametros
                & Media
                    & Varianza 
                        & \multicolumn{1}{c|}{%
                                    Funci\'on generadora de momentos}\\
    \hline
    \hline
    \textit{Bernoulli} &  $f(x) = p^x q^{1-x}I_{\{0,1\}}(x)$ & $0< p <1$ & $p$ & $p(1-p)$ & $(1-p) + pe^t$\\
    \hline
    \textit{Binomial} & $f(x) = \binom{n}{x}p^x(1-p)^{n-x}I_{0,1,\ldots,n}(x)$ & $0<p<1$ & $np$ & $np(1-p)$ & $(1-p + pe^t)^n$\\
    \hline
\end{tabular}
\end{table}

\end{document}

in above mwe i consider Mico comment below.

  • 1
    Almost... I managed to achieve the same. But in my example I want the vertical height to be the same for every row. That's why I have the extra column and the [5ex] at the end of each row. – migueldva Oct 10 '17 at 1:26
  • as i tested your code, you not achieve the same since your approach was wrong ... lead to ugly result about which you complain. your wish can be fulfilled, if you now the height of rows in advance. – Zarko Oct 10 '17 at 1:30
  • I acheived it. Just didn't post it on the question, since it was not what I needed, the code I uploaded is my desired solution except for the vertical centering. What I mean is that I want the table to stay the same as the one uploaded but with vertical centering! You mean that if I simply define the row height in advance with the code you uploaded, I'll get what I need? – migueldva Oct 10 '17 at 1:35
  • 1
    +1. Since the amsmath package is in use, I'd replace \begin{pmatrix}n\\x\end{pmatrix} with \binom{n}{x}. – Mico Oct 10 '17 at 1:37
4

The cleanest, and most reader-friendly, solution would be to provide fewer (but better-spaced) horizontal lines, and no vertical lines at all. That way, the reader's eye doesn't get needlessly distracted. For ease of comparison, the following screenshot also shows the output of the OP's initial code.

enter image description here

\documentclass{article}
\usepackage[a4paper,margin=1in,landscape]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}
\usepackage{amsmath,amsfonts,amssymb}
\usepackage{graphicx}
\usepackage{float}
\usepackage{array}
\usepackage{booktabs}
\DeclareMathOperator{\I}{I} % indicator function should be a "math operator"
\begin{document}

\begin{center}
    {\large\textbf{Gu\'ia Probabilidad}}
    \noindent\makebox[\linewidth]{\rule{\textwidth}{1pt}}
\end{center}

\subsection*{Distribuciones Discretas}

\bigskip
\begin{center}
    \begin{tabular}{@{} l ccccc @{}}
    \toprule  
    Distribución & 
    Funci\'on de masa de probabilidad & 
    Par\'ametros & Media & Varianza & 
    Funci\'on generadora de momentos\\
    \midrule
    \addlinespace
    Bernoulli & 
    $f(x) = p^x q^{1-x} \I_{\{0,1\}}(x)$ & 
    $0< p <1$ & $p$ & $p(1-p)$ & $(1-p) + pe^t$ \\[2ex]
    Binomial & 
    $f(x) = \binom{n}{x} p^x(1-p)^{n-x} \I_{0,1,\dots,n}(x)$ & 
    $0<p<1$ & $np$ & $np(1-p)$ & $(1-p + pe^t)^n$\\
    \addlinespace
    \bottomrule
\end{tabular}
\end{center}

\end{document}
  • thank you for comment. i would accept your answer (+1), not mine :-). – Zarko Oct 10 '17 at 1:50

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.