如何自动更改表格中每隔一行的字体大小?

如何自动更改表格中每隔一行的字体大小?
\documentclass[12pt]{article}
\usepackage{amsmath,amsthm,amssymb,amsfonts}
\usepackage[a4paper]{geometry}
\usepackage{graphicx}
\usepackage{booktabs}
\usepackage{rotating}
\usepackage{textcomp}
\usepackage{subfigure}
\usepackage{hyperref}
\usepackage{amsmath}
\usepackage[margin=10pt,font=small,labelfont=bf, labelsep=endash]{caption}
\usepackage{booktabs}
\begin{document}
\newcommand{\ra}[1]{\renewcommand{\arraystretch}{#1}}
\begin{table*}[h]
\centering
\ra{1}
\resizebox{\textwidth}{!}{
\begin{tabular}{cccccccccc}\toprule
&& \multicolumn{2}{c}{Phase 1} & \phantom{ab}& \multicolumn{2}{c}{Phase 2} && \multicolumn{2}{c}{Phase 3}\\
\cmidrule{3-4}              \cmidrule{6-7}          \cmidrule{9-10}
Day &\phantom{ab}& AAR & CAAR & \phantom{ab} & AAR & CAAR & \phantom{ab} & AAR & CAAR \\ \midrule
$-10$ & \phantom{ab}&0.00211&0.00211 &\phantom{ab}& -0.00104& 0.6& \phantom{ab}&0.00211&0.7\\
 &\phantom{ab}& \footnotesize(0.61)& \footnotesize(0.61)&\phantom{ab}& \footnotesize(0.61)\\
$-9$ & \phantom{ab}& 0.00242 &0.00453 & \phantom{ab}&0.00211 & 0.6& \phantom{ab}&0.00211&0.7\\
&\phantom{ab}& \footnotesize(0.90)& \footnotesize (1.04)&\phantom{ab}& \footnotesize(0.61)\\
\hline\hline
\multicolumn{3}{l}{\footnotesize \textit{t} statistics in parentheses}\\
\multicolumn{3}{l}{\footnotesize {*} \(p<0.05\), {**} \(p<0.01\), {***} \(p<0.001\)}\\
\bottomrule
\end{tabular}
}
\end{table*}\end{document}

大家好。我想创建一个美观的表格,但遇到了一些问题。首先,有没有办法去掉每隔一行的 \footnotesize,并自动更改字体大小?其次,如何让“Phase 1”下面的行从左侧稍微短一点,以便它正好位于数字上方? 表格1。

答案1

这是一个开始,它还没有自动化,但向您展示了一些改进。我现在没有时间完成。请自行处理代码,如果您喜欢的话。

% arara: pdflatex

\documentclass[12pt]{article}
\usepackage[a4paper]{geometry}
\usepackage{booktabs}
\usepackage{threeparttable}
\usepackage{caption}
\usepackage{array}
\makeatletter
\g@addto@macro{\endtabular}{\rowfont{}}% 
\makeatother
\newcommand{\rowfonttype}{}% 
\newcommand{\rowfont}[1]{% 
    \gdef\rowfonttype{#1}#1% credits to http://tex.stackexchange.com/a/62858
}
\newcolumntype{L}{>{\rowfonttype}l}
\newcolumntype{C}{>{\rowfonttype}c}

\begin{document}
\begin{table}
    \centering
    \begin{threeparttable}
        \caption{some table ($t$ statistics in parentheses)}
        \begin{tabular}{L@{\hspace{1cm}}*{6}{C}}
            \toprule
            & \multicolumn{2}{c}{Phase 1} &  \multicolumn{2}{c}{Phase 2} & \multicolumn{2}{c}{Phase 3} \\
            \cmidrule(lr){2-3}\cmidrule(lr){4-5}\cmidrule(lr){6-7}
            Day & AAR & CAAR &  AAR & CAAR & AAR & CAAR \\ 
            \midrule
            $-10$ & 0.00211 & 0.00211 & $-0.00104$ & 0.6 & 0.00211 & 0.7 \\
            \rowfont{\footnotesize}%
            & (0.61) & (0.61) & (0.61) & & & \\
            \rowfont{\normalsize}%
            $-9$ & 0.00242 & 0.00453 & 0.00211 & 0.6 & 0.00211 & 0.7 \\
            \rowfont{\footnotesize}%
            & (0.90) & (1.04)& (0.61) & & & \\
            \bottomrule
        \end{tabular}
        \begin{tablenotes}[para]
            \item[*] $p<0.05$
            \item[**] $p<0.01$
            \item[***] $p<0.001$
        \end{tablenotes}
    \end{threeparttable}
\end{table}
\end{document}

在此处输入图片描述

毕竟,我不建议这样做。如果字体经常变化,看起来会很烦人。还请注意不同的垂直间距,这很丑陋,并且会将小数字推向错误的方向。我会将所有数字保留为相同大小,然后查看包装中的表格siunitx。您将获得对齐的所有数字和点,这更容易阅读。在每一行之后使用一些\addlinespace,表格将是完美的。

答案2

避免缩放表格,但如果这样做,左右两侧没有留出空间,则需要\resizebox{\textwidth}{!}{%

这里我只是将 t 统计量定义为同一单元格的一部分

在此处输入图片描述

不知道为什么那里会有多余的幻影列,所以我把它们删除了。

\documentclass[12pt]{article}
\usepackage{amsmath,amsthm,amssymb,amsfonts}
\usepackage[a4paper]{geometry}

\usepackage{booktabs}
\usepackage{array}
\usepackage{amsmath}
\usepackage[margin=10pt,font=small,labelfont=bf, labelsep=endash]{caption}
\def\tstat#1(#2){\begin{array}[t]{@{}c@{}}#1\\[-3pt]\scriptstyle(#2)\end{array}}
\begin{document}

\begin{table}
\centering

\begin{tabular}{r*{3}{>{\tstat}c}ccc}\toprule
& \multicolumn{2}{c}{Phase 1} &
\multicolumn{2}{c}{Phase 2}& 
\multicolumn{2}{c}{Phase 3}\\
\cmidrule(r{.7em}l{.7em}){2-3}
\cmidrule(r{.7em}l{.7em}){4-5}
\cmidrule(r{.7em}l{.7em}){6-7}
\multicolumn{1}{c}{Day}&
\multicolumn{1}{c}{AAR} &
\multicolumn{1}{c}{CAAR} &
\multicolumn{1}{c}{AAR} &
CAAR  & AAR & CAAR \\ \midrule
$-10$ & 0.00211 (0.61)&0.00211 (0.61)& -0.00104(0.61)& 0.6& 0.00211&0.7\\
$-9$ &  0.00242 (0.90)&0.00453 (1.04)& 0.00211 (0.61)& 0.6& 0.00211&0.7\\
\hline\hline
\multicolumn{3}{l}{\footnotesize $t$ statistics in parentheses}\\
\multicolumn{3}{l}{\footnotesize {*} \(p<0.05\), {**} \(p<0.01\), {***} \(p<0.001\)}\\
\bottomrule
\end{tabular}

\end{table}

\end{document}

相关内容