1

I need to do a Table with the following data:

\documentclass[t,11pt]{beamer}
\usetheme{Warsaw}

\usepackage[brazil,shorthands=off]{babel} \usepackage[utf8]{inputenc}

\usepackage{amsmath} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{graphicx} \usepackage{graphicx} \usepackage{tikz,pgfplots} \usepackage{booktabs}

\begin{document}

\begin{frame}{Método da bissecção} \begin{footnotesize} \begin{table}[!htb] \centering \caption{14 iterações do método da bissecção para $f(x)=2-e^x$} \label{tab:my-table} %\begin{tabular}{rrrrr} \begin{tabular}{rrrrr} \toprule $k$ & $a_k$ & $p_k$ & $b_k$ & $|\log 2 - p_k|$ \ \midrule 1.0 & 0.0 & 1.0 & 2.0 & 0.306853 \ 2.0 & 0.0 & 0.5 & 1.0 & 0.193147 \ 3.0 & 0.5 & 0.75 & 1.0 & 0.0568528 \ 4.0 & 0.5 & 0.625 & 0.75 & 0.0681472 \ 5.0 & 0.625 & 0.6875 & 0.75 & 0.00564718 \ 6.0 & 0.6875 & 0.71875 & 0.75 & 0.0256028 \ 7.0 & 0.6875 & 0.703125 & 0.71875 & 0.00997782 \ 8.0 & 0.6875 & 0.695312 & 0.703125 & 0.00216532 \ 9.0 & 0.6875 & 0.691406 & 0.695312 & 0.00174093 \ 10.0 & 0.691406 & 0.693359 & 0.695312 & 0.000212199 \ 11.0 & 0.691406 & 0.692383 & 0.693359 & 0.000764371 \ 12.0 & 0.692383 & 0.692871 & 0.693359 & 0.000276091 \ 13.0 & 0.692871 & 0.693115 & 0.693359 & 3.19506e-5 \ 14.0 & 0.693115 & 0.693237 & 0.693359 & 9.0194e-5 \ \bottomrule \end{tabular} \end{table} \end{footnotesize} \end{frame}

\end{document}

I would like to:

  1. eliminate the zeros at right in first column
  2. round the columns 2, 3 and 4 with 6 decimal places and complete with zero when the number has less decimal places.
  3. round the column 4 to 6 decimal places and
  4. write 3.19506e-5 in decimal way.

enter image description here

Zarko
  • 296,517

2 Answers2

1

It is not entirely clear, what you like to have. Your table numbers have maximal 6 decimals, not 8. Do you like to fill decimal numbers with zeros?

Anyway, I suspect that you looking for something like this:

enter image description here

With use of S columns defined in the siunitx package which enable customization of numbers presenting (aligning at decimal points):

\documentclass[t,11pt]{beamer}
\usetheme{Warsaw}

\usepackage[brazil,shorthands=off]{babel}

\usepackage{amsmath, amssymb} \usepackage{pgfplots} \usepackage{booktabs}

\usepackage{siunitx}

\begin{document} \begin{frame} \frametitle{Table} \begin{table} \caption{} \label{tab:my-table} \small \begin{tabular}{r*{3}{S[table-format=1.6]}} \hline $k$ & $a_k$ & $p_k$ & $b_k$ \ \hline 1 & 0.0 & 0.5 & 1.0 \ 2 & 0.5 & 0.75 & 1.0 \ 3 & 0.5 & 0.625 & 0.75 \ 4 & 0.625 & 0.6875 & 0.75 \ 5 & 0.6875 & 0.71875 & 0.75 \ 6 & 0.6875 & 0.703125 & 0.71875 \ 7 & 0.6875 & 0.695312 & 0.703125 \ 8 & 0.6875 & 0.691406 & 0.695312 \ 9 & 0.691406 & 0.693359 & 0.695312 \ 10 & 0.691406 & 0.692383 & 0.693359 \ 11 & 0.692383 & 0.692871 & 0.693359 \ 12 & 0.692871 & 0.693115 & 0.693359 \ 13 & 0.693115 & 0.693237 & 0.693359 \ 14 & 0.693115 & 0.693176 & 0.693237 \ \hline \end{tabular} \end{table} \end{frame} \end{document}

Addendum: Now, after providing own (now deleted) "answer", which should bi inserted in your question, the problem is more clear. With help of further S column options, you can achieve the following:

enter image description here

\documentclass[t,11pt]{beamer}
\usetheme{Warsaw}

\usepackage[brazil,shorthands=off]{babel} \usepackage{mathtools, amssymb} \DeclarePairedDelimiter\abs{\lvert}{\rvert} \usepackage{booktabs}

\usepackage{siunitx} % <---

\begin{document} \begin{frame} \frametitle{Método da bissecção} \begin{table} \caption{14 iterações do método da bissecção para $f(x)=2-e^x$} \label{tab:my-table} \footnotesize \begin{tabular}{S[table-format=2.0, zero-decimal-to-integer] *{3}{S[table-format=1.6, round-integer-to-decimal, round-mode=places, round-precision = 6]} S[table-format=1.8, round-integer-to-decimal, round-mode=places, round-precision = 8, scientific-notation = fixed, fixed-exponent = 0]} \toprule $k$ & {$a_k$} & {$p_k$} & {$b_k$} & {$\abs{\log 2 - p_k}$} \ \midrule 1.0 & 0.0 & 1.0 & 2.0 & 0.306853 \ 2.0 & 0.0 & 0.5 & 1.0 & 0.193147 \ 3.0 & 0.5 & 0.75 & 1.0 & 0.0568528 \ 4.0 & 0.5 & 0.625 & 0.75 & 0.0681472 \ 5.0 & 0.625 & 0.6875 & 0.75 & 0.00564718 \ 6.0 & 0.6875 & 0.71875 & 0.75 & 0.0256028 \ 7.0 & 0.6875 & 0.703125 & 0.71875 & 0.00997782 \ 8.0 & 0.6875 & 0.695312 & 0.703125 & 0.00216532 \ 9.0 & 0.6875 & 0.691406 & 0.695312 & 0.00174093 \ 10.0 & 0.691406 & 0.693359 & 0.695312 & 0.000212199 \ 11.0 & 0.691406 & 0.692383 & 0.693359 & 0.000764371 \ 12.0 & 0.692383 & 0.692871 & 0.693359 & 0.000276091 \ 13.0 & 0.692871 & 0.693115 & 0.693359 & 3.19506e-5 \ 14.0 & 0.693115 & 0.693237 & 0.693359 & 9.0194e-5 \ \bottomrule \end{tabular} \end{table} \end{frame}

\end{document}

Note:

  • beamer load graphicx package, so you not need to (re)load it twice ...
  • In LaTeX installation after April 2018 the utf8 input encoding is default features, so no longer need to use \usepackage[utf8]{inputenc} in document preamble (LATEX News).
  • Off-topic: check values in the last table columns. If they are calculated as noted in column header, than they are incorrect.
Zarko
  • 296,517
0

You can use numprint package, it allows you to round numbers in table to a certain decimal place (I think this is what you are asking for correct?).

There is another question that actually answers this, if you want to read more about it look here

Cavenfish
  • 180