最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

dataframe - In Julia, how to make PrettyTables.jl use the booktabs package? - Stack Overflow

programmeradmin3浏览0评论

I am using Julia and I want to export a certain dataframe as a LaTeX table. The dataframe is called portfolios and I am sharing it as a dictionary below.

Dict{String, Vector} with 5 entries:
  "Sharpe Ratio" => [1.08321, 0.89012, 1.23641, 1.08433]
  "Portfolio"    => ["Equal weights", "Minimum volatility", "Tangency", "Risk parity"]
  "Return"       => [0.092, 0.0579556, 0.106783, 0.0810661]
  "Gini index"   => [0.0, 0.568016, 0.533732, 0.183507]
  "Volatility"   => [0.0849329, 0.0651099, 0.0863653, 0.0747617]

Currently, my code is the following:

using PrettyTables as PT

PT.pretty_table(
        io,
        portfolios;
        backend = Val(:latex),
        show_subheader = false,
        alignment=[:l, :c, :c, :c, :c],
        formatters = PT.ft_printf("%1.2f")
    )

This will generate the following:

\begin{tabular}{lcccc}
  \hline
  \textbf{Portfolio} & \textbf{Return} & \textbf{Volatility} & \textbf{Sharpe Ratio} & \textbf{Gini index} \\\hline
  Equal weights & 0.09 & 0.08 & 1.08 & 0.00 \\
  Minimum volatility & 0.06 & 0.07 & 0.89 & 0.57 \\
  Tangency & 0.11 & 0.09 & 1.24 & 0.53 \\
  Risk parity & 0.08 & 0.07 & 1.08 & 0.18 \\\hline
\end{tabular}

How can I force PrettyTables.jl to use the rules (\midrule, \toprule, ...) from the booktabs package?

I am using Julia and I want to export a certain dataframe as a LaTeX table. The dataframe is called portfolios and I am sharing it as a dictionary below.

Dict{String, Vector} with 5 entries:
  "Sharpe Ratio" => [1.08321, 0.89012, 1.23641, 1.08433]
  "Portfolio"    => ["Equal weights", "Minimum volatility", "Tangency", "Risk parity"]
  "Return"       => [0.092, 0.0579556, 0.106783, 0.0810661]
  "Gini index"   => [0.0, 0.568016, 0.533732, 0.183507]
  "Volatility"   => [0.0849329, 0.0651099, 0.0863653, 0.0747617]

Currently, my code is the following:

using PrettyTables as PT

PT.pretty_table(
        io,
        portfolios;
        backend = Val(:latex),
        show_subheader = false,
        alignment=[:l, :c, :c, :c, :c],
        formatters = PT.ft_printf("%1.2f")
    )

This will generate the following:

\begin{tabular}{lcccc}
  \hline
  \textbf{Portfolio} & \textbf{Return} & \textbf{Volatility} & \textbf{Sharpe Ratio} & \textbf{Gini index} \\\hline
  Equal weights & 0.09 & 0.08 & 1.08 & 0.00 \\
  Minimum volatility & 0.06 & 0.07 & 0.89 & 0.57 \\
  Tangency & 0.11 & 0.09 & 1.24 & 0.53 \\
  Risk parity & 0.08 & 0.07 & 1.08 & 0.18 \\\hline
\end{tabular}

How can I force PrettyTables.jl to use the rules (\midrule, \toprule, ...) from the booktabs package?

Share Improve this question asked Mar 10 at 19:13 Raul Guarini RivaRaul Guarini Riva 7951 gold badge13 silver badges29 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Solution found (via Google Gemini, since neither Chap GPT nor Claude could do it).

The correct argument to chage was tf :

PT.pretty_table(
        io,
        portfolios;
        backend = Val(:latex),
        show_subheader = false,
        alignment=[:l, :c, :c, :c, :c],
        formatters = PT.ft_printf("%1.2f"),
        tf = PT.tf_latex_booktabs
    )
发布评论

评论列表(0)

  1. 暂无评论