表格中的不同字体大小和行高

表格中的不同字体大小和行高

我必须排版一个表格,在不同的表格行中使用不同的字体大小。我使用 Werner 在表格中不同行的字体大小不同

\documentclass{standalone}

\usepackage{array}
\usepackage{booktabs}
\usepackage{caption}
\makeatletter
\g@addto@macro{\endtabular}{\rowfont{}}% Clear row font
\makeatother
\newcommand{\rowfonttype}{}% Current row font
\newcommand{\rowfont}[1]{% Set current row font
   \gdef\rowfonttype{#1}#1%
}
\newcolumntype{L}{>{\rowfonttype}l}

\begin{document}

\begin{tabular}[t]{ll}
    \toprule
    Hello & World \\
    Hello & World \\
    Hello & World \\    
    Hello & World \\
    Hello & World \\
    Hello & World \\
    \bottomrule
\end{tabular}

\begin{tiny}
\begin{tabular}[t]{ll}
    \toprule
    Hello & World \\
    Hello & World \\
    Hello & World \\    
    Hello & World \\
    Hello & World \\
    Hello & World \\
    \bottomrule
\end{tabular}
\end{tiny}

\begin{tabular}[t]{LL}
    \toprule
    \rowfont{\tiny}%
    Hello & World \\
    Hello & World \\
    Hello & World \\    
    \rowfont{\normalsize}%
    Hello & World \\
    Hello & World \\
    Hello & World \\
    \bottomrule
\end{tabular}

\end{document}

这给出了以下结果:

在此处输入图片描述

显然,\newfont可以很好地调整第三个表中的字体大小,但表格行的高度仍然是基于计算的normalsize。有没有办法将第三个表格的前三行的高度调整为“正常”高度tiny


跟进

David 的解决方案与我提供的 MWE 配合得很好。但是,使用 longtable 时,我得到以下结果:

\documentclass{article}

\usepackage{setspace}
\usepackage{array}
\usepackage{longtable}
\usepackage{threeparttablex}
\usepackage{booktabs}
\usepackage{caption}

\setstretch{1.25}
\renewcommand{\arraystretch}{1.00}

% Use different font sizes in table
\makeatletter
\g@addto@macro{\endtabular}{\rowfont{}}% Clear row font
\makeatother
\newcommand{\rowfonttype}{}% Current row font
\newcommand{\rowfont}[1]{% Set current row font
   \gdef\rowfonttype{#1}#1%
}
\newcolumntype{P}{>{\rowfonttype}p}

\begin{document}

\begin{ThreePartTable}
\setstretch{1.00}
\begin{TableNotes}[para,flushleft]
Some caption.
\end{TableNotes}
\begin{footnotesize}

\begin{longtable}{@{}P{1cm}P{1cm}P{1cm}P{1cm}@{}}
\caption{A list}\\

\toprule
\endfirsthead
\captionsetup{labelsep=endash}
\caption[]{\emph{continued from previous page}}\\
\toprule
\endhead
\midrule
\multicolumn{4}{@{}r@{}}{\emph{Continued on next page}} \\
\endfoot
\bottomrule
\insertTableNotes
\endlastfoot
    xxx & xxx & xxx & xxx \\
    xxx & xxx & xxx & xxx \\
    xxx & xxx & xxx & xxx \\
    \rowfont{\tiny}%
    xxx & xxx & xxx & xxx \\
    xxx & xxx & xxx & xxx \\
    xxx & xxx & xxx & xxx \ \rowfont{\normalsize}%
\end{longtable}

\end{footnotesize}
\end{ThreePartTable}


\renewcommand\arraystretch{0} 
\begin{ThreePartTable}
\setstretch{1.00}
\begin{TableNotes}[para,flushleft]
Some caption.
\end{TableNotes}
\begin{footnotesize}

\begin{longtable}{@{}P{1cm}P{1cm}P{1cm}P{1cm}@{}}
\caption{A list}\\

\toprule
\endfirsthead
\captionsetup{labelsep=endash}
\caption[]{\emph{continued from previous page}}\\
\toprule
\endhead
\midrule
\multicolumn{4}{@{}r@{}}{\emph{Continued on next page}} \\
\endfoot
\bottomrule
\insertTableNotes
\endlastfoot
    xxx & xxx & xxx & xxx \\
    xxx & xxx & xxx & xxx \\
    xxx & xxx & xxx & xxx \\
    \rowfont{\tiny}%
    xxx & xxx & xxx & xxx \\
    xxx & xxx & xxx & xxx \\
    xxx & xxx & xxx & xxx \ \rowfont{\normalsize}%
\end{longtable}

\end{footnotesize}
\end{ThreePartTable}

\end{document}

在此处输入图片描述

有没有办法让tiny这里的行具有适当的行高?

答案1

在此处输入图片描述

\documentclass{standalone}

\usepackage{array}
\usepackage{booktabs}
\usepackage{caption}
\makeatletter
\g@addto@macro{\endtabular}{\gdef\rowfonttype{}}% Clear row font
\makeatother
\newcommand{\rowfonttype}{}% Current row font
\newcommand{\rowfont}[1]{% Set current row font
   \noalign{\gdef\rowfonttype{#1}}}%
\newcolumntype{L}{>{\rowfonttype\strut}l}

\begin{document}

\begin{tabular}[t]{ll}
    \toprule
    Hello & World \\
    Hello & World \\
    Hello & World \\    
    Hello & World \\
    Hello & World \\
    Hello & World \\
    \bottomrule
\end{tabular}

\begin{tiny}
\begin{tabular}[t]{ll}
    \toprule
    Hello & World \\
    Hello & World \\
    Hello & World \\    
    Hello & World \\
    Hello & World \\
    Hello & World \\
    \bottomrule
\end{tabular}
\end{tiny}

\renewcommand\arraystretch{0}
\begin{tabular}[t]{LL}
    \toprule
    \rowfont{\tiny}%
    Hello & World \\
    Hello & World \\
    Hello & World \\    
    \rowfont{\normalsize}%
    Hello & World \\
    Hello & World \\
    Hello & World \\
    \bottomrule
\end{tabular}

\end{document}

相关内容