有没有办法指示熊猫Dataframe.to_latex()
为LateX中的输出表附加\footnotesize
(或其他全球选项)?(当然,除了手动添加之外,这是没有效率的,因为我正在生成许多表。)
因此,现在我的代码生成以下LaTeX表:
\begin{table}[H]
\centering
\caption{Caption of the table.}
\label{tab:06_01.example}
\begin{tabular}{lrrr}
\toprule
& & F-1 & F-2 \\
Dataset & Model & & \\
\midrule
\multirow{2}{*}{\textit{H}} & Baseline & 0.904 & 0.887 \\
& Version2 & 0.939 & 0.927 \\
\cline{1-4}
\multirow{2}{*}{\textit{S}} & Baseline & 0.548 & 0.506 \\
& Version2 & 0.582 & 0.541 \\
\cline{1-4}
\midrule
\multirow{2}{*}{\textit{G}} & Baseline & 0.879 & 0.855 \\
& Version2 & 0.910 & 0.895 \\
\cline{1-4}
\multirow{2}{*}{\textit{T}} & Baseline & 0.911 & 0.877 \\
& Version2 & 0.940 & 0.913 \\
\bottomrule
\end{tabular}
\end{table}
来自下列熊猫的资料:
F-1 F-2
dataset Model
H Baseline 0.904 0.887
Version2 0.939 0.927
S Baseline 0.548 0.506
Version2 0.582 0.541
G Baseline 0.879 0.855
Version2 0.910 0.895
T Baseline 0.911 0.877
Version2 0.940 0.913
以及相应的可重现性的dict:
{'F-1': {('H', 'Baseline'): 0.9044961552465764, ('H', 'Fine-Tuned'): 0.9387767951280728, ('S', 'Baseline'): 0.547968262581014, ('S', 'Fine-Tuned'): 0.5815634664656218, ('G', 'Baseline'): 0.8793941208568047, ('G', 'Fine-Tuned'): 0.9102870296052078, ('T', 'Baseline'): 0.9110316123313993, ('T', 'Fine-Tuned'): 0.9404444309041384}, 'F-2': {('H', 'Baseline'): 0.8865304318012182, ('H', 'Fine-Tuned'): 0.9273671656403047, ('S', 'Baseline'): 0.5063582247873787, ('S', 'Fine-Tuned'): 0.5408162758046822, ('G', 'Baseline'): 0.8551648617281388, ('G', 'Fine-Tuned'): 0.8947135188980437, ('T', 'Baseline'): 0.8774834363467384, ('T', 'Fine-Tuned'): 0.9134634736945935}}
通过一个几乎直接的dataframe.to_latex()
。我想要的是更改一些全局表选项,例如,添加\脚注大小,更改\居中,如下所示:
\begin{table}[H]
\footnotesize %include or not
\centering %include or not
\caption{Caption of the table.}
\label{tab:06_01.example}
\begin{tabular}{lrrr}
\toprule
& & F-1 & F-2 \\
Dataset & Model & & \\
\midrule
\multirow{2}{*}{\textit{H}} & Baseline & 0.904 & 0.887 \\
& Version2 & 0.939 & 0.927 \\
\cline{1-4}
\multirow{2}{*}{\textit{S}} & Baseline & 0.548 & 0.506 \\
& Version2 & 0.582 & 0.541 \\
\cline{1-4}
\multirow{2}{*}{\textit{G}} & Baseline & 0.879 & 0.855 \\
& Version2 & 0.910 & 0.895 \\
\cline{1-4}
\multirow{2}{*}{\textit{T}} & Baseline & 0.911 & 0.877 \\
& Version2 & 0.940 & 0.913 \\
\bottomrule
\end{tabular}
\end{table}
乍一看,乳胶()中似乎没有这样的选项,但我不确定格式化器字段可以做什么。此外,我不知道Styler.to_latex()在这里是否有帮助。
PS:另一种好的方法是定义在哪个数据集(例如S)之后包含一个\中间规则(就像我想分离不同类型的数据集一样)。
\begin{table}[H]
\footnotesize %include or not
\centering %include or not
\caption{Caption of the table.}
\label{tab:06_01.example}
\begin{tabular}{lrrr}
\toprule
& & F-1 & F-2 \\
Dataset & Model & & \\
\midrule
\multirow{2}{*}{\textit{H}} & Baseline & 0.904 & 0.887 \\
& Version2 & 0.939 & 0.927 \\
\cline{1-4}
\multirow{2}{*}{\textit{S}} & Baseline & 0.548 & 0.506 \\
& Version2 & 0.582 & 0.541 \\
\cline{1-4}
\midrule
\multirow{2}{*}{\textit{G}} & Baseline & 0.879 & 0.855 \\
& Version2 & 0.910 & 0.895 \\
\cline{1-4}
\multirow{2}{*}{\textit{T}} & Baseline & 0.911 & 0.877 \\
& Version2 & 0.940 & 0.913 \\
\bottomrule
\end{tabular}
\end{table}
发布于 2021-11-26 17:41:17
您可以告诉latex对您的所有表进行这些更改:
\documentclass{article}
\usepackage{float}
\usepackage{booktabs}
\usepackage{multirow}
% change fontsize
\AtBeginEnvironment{tabular}{\footnotesize}
% switch off centering in tables
\AtBeginEnvironment{table}{\let\centering\relax}
\begin{document}
\begin{table}[H]
\centering
\caption{Caption of the table.}
\label{tab:06_01.example}
\begin{tabular}{lrrr}
\toprule
& & F-1 & F-2 \\
Dataset & Model & & \\
\midrule
\multirow{2}{*}{\textit{H}} & Baseline & 0.904 & 0.887 \\
& Version2 & 0.939 & 0.927 \\
\cline{1-4}
\multirow{2}{*}{\textit{S}} & Baseline & 0.548 & 0.506 \\
& Version2 & 0.582 & 0.541 \\
\cline{1-4}
\midrule
\multirow{2}{*}{\textit{G}} & Baseline & 0.879 & 0.855 \\
& Version2 & 0.910 & 0.895 \\
\cline{1-4}
\multirow{2}{*}{\textit{T}} & Baseline & 0.911 & 0.877 \\
& Version2 & 0.940 & 0.913 \\
\bottomrule
\end{tabular}
\end{table}
test
\centering
test
\end{document}
https://stackoverflow.com/questions/70127250
复制相似问题