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

Table to LaTeX #330

Open
koenichiwa opened this issue Apr 12, 2023 · 2 comments
Open

Table to LaTeX #330

koenichiwa opened this issue Apr 12, 2023 · 2 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@koenichiwa
Copy link

I was curious if the table output could be in LaTeX form.

Taking some inspiration from pandas DataFrame.to_latex(), you could have an output similar to:

\begin{tabular}{lrr}
    \toprule
    {} &  A & B \\
    \midrule
    X &  1 &  2 \\
    Y &  3 &  4 \\
    \bottomrule
\end{tabular}

This is just a quick example, and you might want to add some spacing in some cases in between the columns to make it humanly readable.

It does expect the end user to use booktabs as a LaTeX package because of \toprule and friends. But, if pandas can get away with it, I don't see why this library wouldn't either. We could also swap them for \hline.

NB that this creates a tabular. To use it in a LaTeX file, the end user would generally pack it in a table like so:

\begin{table}[]
    \centering
    \begin{tabular}{rr}
        \toprule
        A &  B \\
        \midrule
        1 &  2 \\
        \bottomrule
    \end{tabular}
    \caption{My super simple example}
    \label{tab:simple-example}
\end{table}

My gut feeling says that it's best to leave the more serious aspects of styling to the end user, and thus stick to creating tabulars. Namely because it's impossible to know which packages the user is already using and extra styling might create extra (possibly incompatible) dependencies. This would just leave the library in control of the amount of rows/columns, and the alignment of the cells.

On the other hand this is a library for pretty printing tables, and it would also be possible to create the full table.

But let me know your thoughts on that last part.

@zhiburt zhiburt added enhancement New feature or request good first issue Good for newcomers labels Apr 12, 2023
@zhiburt
Copy link
Owner

zhiburt commented Apr 26, 2023

@scirin

@zhiburt zhiburt assigned zhiburt and unassigned zhiburt Apr 26, 2023
@zhiburt
Copy link
Owner

zhiburt commented Apr 26, 2023

Hi @koenichiwa

Thanks for the proposal.
(I didn't answered back then cause your description was more than enough).

So pandas has a switch to chose between longtable and booktabs we can do it too (maybe there more popular extensions?).

My gut feeling says that it's best to leave the more serious aspects of styling to the end user, and thus stick to creating tabulars. Namely because it's impossible to know which packages the user is already using and extra styling might create extra (possibly incompatible) dependencies. This would just leave the library in control of the amount of rows/columns, and the alignment of the cells.

On the other hand this is a library for pretty printing tables, and it would also be possible to create the full table.

Exactly;
We could add some things (probably index/colors/formatting/padding/margin/span maybe more?) but it would be hard to do a comprehensive styling.

I just wonder how it would be possible.
In HTML for example we can add id, class tags so a user could tweak styles in its own CSS block.
But I guess it's not possible with LaTeX.

As an option custom visitor function could be exposed to change built latex tree.

Otherwise I guess editing it manually does not make a lot of sense.


Implementation details;

I believe it shall be something similar to https://github.com/zhiburt/tabled/tree/master/table_to_html

PS: Not an expert in LaTex.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants