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?
1 Answer
Reset to default 0Solution 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
)