Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: add and option for scientific notation in LaTeX #216

Closed
HMegh opened this issue Sep 5, 2023 · 2 comments
Closed

Feature request: add and option for scientific notation in LaTeX #216

HMegh opened this issue Sep 5, 2023 · 2 comments

Comments

@HMegh
Copy link

HMegh commented Sep 5, 2023

Hi,

Would it be possible to add an option so that the numbers in the latex output will be displayed using the scientific notation "\times 10^n"? For example, .000025 will be 2.5\times 10^{-5} instead of 2.5e-5.

Right now, I can do this with a regex find-replace, but it would be awesome if the package supports it.

@ronisbr
Copy link
Owner

ronisbr commented Sep 5, 2023

Hi @HMegh !

In fact you can do this by using the formatter ft_latex_sn:

julia> a = rand(4, 4) * 1e5
4×4 Matrix{Float64}:
 78664.9     762.498  89321.9  58704.7
 51475.3   86237.6    11990.0  33106.3
 41140.2   10658.2    55646.8  35019.9
  2035.81  80699.8    33982.4  77060.7

julia> pretty_table(a; tf = tf_latex_default, formatters = ft_latex_sn(4))
\begin{tabular}{rrrr}
  \hline
  \textbf{Col. 1} & \textbf{Col. 2} & \textbf{Col. 3} & \textbf{Col. 4} \\\hline
  $7.866 \cdot 10^{4}$ & 762.5 & $8.932 \cdot 10^{4}$ & $5.87 \cdot 10^{4}$ \\
  $5.148 \cdot 10^{4}$ & $8.624 \cdot 10^{4}$ & $1.199 \cdot 10^{4}$ & $3.311 \cdot 10^{4}$ \\
  $4.114 \cdot 10^{4}$ & $1.066 \cdot 10^{4}$ & $5.565 \cdot 10^{4}$ & $3.502 \cdot 10^{4}$ \\
  2036 & $8.07 \cdot 10^{4}$ & $3.398 \cdot 10^{4}$ & $7.706 \cdot 10^{4}$ \\\hline
\end{tabular}
Captura de Tela 2023-09-05 às 09 08 07

The first argument is the number of decimal cases in the mantissa. The second argument can be a vector of integers telling to which columns the formatter must be applied.

@HMegh
Copy link
Author

HMegh commented Sep 5, 2023

Awesome! That's what I was looking for, thank you.

@HMegh HMegh closed this as completed Sep 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants