2

Quick advise:

I want to have a tabular side-by-side.

How would you guys suggest me to go about making sure they have the same height?

Consider the case:

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage{booktabs}

\begin{document}

\begin{table}[H]
\centering
\begin{tabular}{p{14.5em}}
\toprule
\textbf{Medidas Absolutas} \\
\midrule
Média dos erros quadrados \newline MSE$=\frac{1}{n} \sum_{i=1}^n (\hat{x_i}-x_i)^2 $ \\
\midrule
Média dos desvios absolutos \newline MAD$=\frac{1}{n} \sum_{i=1}^n |\hat{x_i}-x_i|$ \\
\bottomrule
\end{tabular}
\hfill
\begin{tabular}{p{14.5em}}
\toprule
\textbf{Medidas Relativas} \\
\midrule
Coeficiente de Theil \newline U$=\frac{\sqrt{\sum_{i=1}^n(\hat{x_i}-x_i)^2}}{\sqrt{\sum_{i=1}^n(x_i-x_{i-1})^2}}$ \\
\midrule
Mean Absolute Percentage Error\newline MAPE$=\frac{1}{n}\sum_{i=1}^n \Big|\frac{(\hat{x_i}-x_i)}{x_i} \Big|$ \\
\bottomrule
\end{tabular}
\caption{Algumas medidas para avaliação do desempenho dos modelos preditivos.}
\end{table}

\end{document}

screenshot

The problem is that the equations on the right are a little too big. I would like the corresponding row of the left table to have the same height.

I have tried \renewcommand{\arraystretch}{1.6} is that it increases size to all rows, not just the bigger ones.

I have tried using \phantom, but it does not quite look for some reason ...

Maybe some \mbox with same height?

ps: these are some examples of absolute and relative error functions. If someone has some other idea to present this information that would be welcome as well!

  • just make them the same tabular with @{\hspace{2cm}] or some such space in the middle – David Carlisle Aug 4 '15 at 11:38
  • with the 2015 latex release the example produces ! LaTeX Error: Unknown float option 'H'. (You need the float package for H) – David Carlisle Aug 4 '15 at 11:46
2

\vphantom can be used to adjust the row/line spacings of the two tables. This aligns the equation lines. Also some text lines nees \vphantom because of the descenders in the other table.

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage{booktabs}

\begin{document}

\begin{table}
  \centering
  \begin{tabular}{p{14.5em}}
    \toprule
    \textbf{Medidas Absolutas} \\
    \midrule
    Média dos erros quadrados \newline MSE$=\frac{1}{n} \sum_{i=1}^n
    (\hat{x_i}-x_i)^2 $%
    \vphantom{$\frac{\sqrt{\sum_{i=1}^n}}{\sqrt{\sum_{i=1}^n}}$}
    \\
    \midrule
    Média dos desvios absolutos\vphantom{g}
    \newline MAD$=\frac{1}{n} \sum_{i=1}^n
    |\hat{x_i}-x_i|$%
    \vphantom{$\Big|$}
    \\
    \bottomrule
  \end{tabular}
  \hfill
  \begin{tabular}{p{14.5em}}
    \toprule
    \textbf{Medidas Relativas} \\
    \midrule
    Coeficiente de Theil\vphantom{q} \newline
    U$=\frac{\sqrt{\sum_{i=1}^n(\hat{x_i}-x_i)^2}}
      {\sqrt{\sum_{i=1}^n(x_i-x_{i-1})^2}}$
    \\
    \midrule
    Mean Absolute Percentage Error\newline MAPE$=\frac{1}{n}\sum_{i=1}^n
    \Big|\frac{(\hat{x_i}-x_i)}{x_i} \Big|$ \\
    \bottomrule
  \end{tabular}
  \caption{Algumas medidas para avaliação do desempenho dos modelos
    preditivos.}
\end{table}

\end{document}

Result

  • I did not know about \vphantom. Thank you! – Ricardo Cruz Aug 4 '15 at 13:15
3

If you are willing to use \cmidrules throughout (in lieu of \toprule and \bottomrule), then you can combine them into one tabular.

EDITED to clean up syntax, adding {}= for proper spacing and a \displaystyle for better vertical separation of fraction terms.

REEDITED to eliminate \newline from OP's approach, instead converting to two separate tabular rows, thus resulting in a better appearance.

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage{booktabs,stackengine}
\stackMath
\begin{document}

\begin{table}[H]
\centering
\begin{tabular}{p{14.5em}c@{\hspace{1cm}}p{14.5em}}
\cmidrule{1-1}\cmidrule{3-3}
%\toprule
\textbf{Medidas Absolutas} &&\textbf{Medidas Relativas}\\
\cmidrule{1-1}\cmidrule{3-3}
Média dos erros quadrados  
&& Coeficiente de Theil \\
MSE${}=\frac{1}{n} \sum_{i=1}^n (\hat{x_i}-x_i)^2 $ &&
U${}=\displaystyle\frac{\sqrt{%
  \addstackgap[0pt]{\sum_{i=1}^n(\hat{x_i}-x_i)^2}}}{\sqrt{\addstackgap[0pt]{\sum_{i=1}^n(x_i-x_{i-1})^2}}}$\\
\cmidrule{1-1}\cmidrule{3-3}
Média dos desvios absolutos \newline MAD${}=\frac{1}{n} \sum_{i=1}^n |\hat{x_i}-x_i|$ 
&& Mean Absolute Percentage Error\newline MAPE${}=\frac{1}n\sum_{i=1}^n \Big|\frac{(\hat{x_i}-x_i)}{x_i} \Big|$\\
\cmidrule{1-1}\cmidrule{3-3}
%\bottomrule
\end{tabular}
\caption{Algumas medidas para avaliação do desempenho dos modelos preditivos.}
\end{table}

\end{document}

enter image description here

  • I did not know about partial \cmidrule - very creative, thanks. But I am going with the other solution of using \vphantom. The table looks a bit better ... – Ricardo Cruz Aug 4 '15 at 13:16
  • @RicardoCruz Glad to have shown you an alternate technique. Best wishes. – Steven B. Segletes Aug 4 '15 at 13:17
  • @RicardoCruz I did just revise my answer to convert your \newline cells into two separate rows. This will result in more balanced spacing, as well. – Steven B. Segletes Aug 4 '15 at 13:22

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.