如何在文档中包含数据表

如何在文档中包含数据表

我正在尝试在文档中包含一个数据表。我收到未满警告,而且文本对我来说太小了。如何让文本变大?

理想情况下,我希望表格的字体大小与文档的其余部分相同,数字右对齐。目前文本太小,列标题的右端与数字的左端垂直对齐。

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{adjustbox}
\usepackage{makecell}
\usepackage{graphicx}
\usepackage{enumitem}
\usepackage{tabularx}
\usepackage{geometry}
    \geometry{a4paper, total={160mm,247mm}, left=25mm,top=25mm, }

\begin{document}

% \begin{center}
\begin{adjustbox}{max width=16cm}
\begin{tabular}{|m{2cm}|m{2cm}|m{3cm}|m{3cm}|m{3cm}|m{3cm}|} 
  \hline
  Velocity (m/s) & Reynolds number & Viscous X \par force  & Viscous Y \par force  & Viscous X \par force  & Viscous Y \par force \\ 
  \hline
  \hfill 1 & \hfill 2 & \hfill 1247.208 & \hfill 0.401 & \hfill 1935.377 & \hfill 0.071 \\ 
  \hline
  \hfill 10 & \hfill 20 & \hfill 12487.550 & \hfill 40.039 & \hfill 19370.400 & \hfill 7.136 \\ 
  \hline
  \hfill 100 & \hfill 200 & \hfill 136167.000 & \hfill 3472.528 & \hfill 206349.900 & \hfill 714.765 \\ 
  \hline
\end{tabular}
\end{adjustbox}
%\end{center}

\end{document}

答案1

问题是正在缩放表格。

不要指定单元格宽度并让 TeX 计算它们。如果将长文本拆分成多行,则可以获得更好的渲染效果。并且与siunitx特征的对齐效果更好。

\documentclass{article}
\usepackage{geometry}
\usepackage{booktabs,siunitx}

\geometry{a4paper, total={160mm,247mm}, left=25mm,top=25mm}

\begin{document}

\begin{center}
% local settings
\newcommand{\splitcell}[1]{\smash{\begin{tabular}[t]{@{}c@{}}#1\end{tabular}}}
\sisetup{group-minimum-digits=3}

\begin{tabular}{
  @{}
  S[table-format=3.0]
  S[table-format=3.0]
  S[table-format=6.3]
  S[table-format=4.3]
  S[table-format=6.3]
  S[table-format=3.3]
  @{}
}
\toprule
{\splitcell{Velocity \\ (\unit{m/s})}} &
{\splitcell{Reynolds \\ number}} &
\multicolumn{4}{c}{Force} \\
\cmidrule{3-6}
&& {Viscous X}  & {Viscous Y} & {Viscous X} & {Viscous Y} \\ 
\midrule
  1 &   2 &   1247.208 &    0.401 &   1935.377 &   0.071 \\ 
 10 &  20 &  12487.550 &   40.039 &  19370.400 &   7.136 \\ 
100 & 200 & 136167.000 & 3472.528 & 206349.900 & 714.765 \\ 
\bottomrule
\end{tabular}
\end{center}

\end{document}

在此处输入图片描述

答案2

为什么不使用tabularx而改呢tabular̀

\begin{adjustbox}{max width=16cm}
  \begin{tabularx}{16cm}{|*6{X|}}
  \hline
  Velocity (m/s) & Reynolds number & Viscous X \par force  & Viscous Y \par force  & Viscous X \par force  & Viscous Y \par force \\ 
  \hline
  \hfill 1 & \hfill 2 & \hfill 1247.208 & \hfill 0.401 & \hfill 1935.377 & \hfill 0.071 \\ 
  \hline
  \hfill 10 & \hfill 20 & \hfill 12487.550 & \hfill 40.039 & \hfill 19370.400 & \hfill 7.136 \\ 
  \hline
  \hfill 100 & \hfill 200 & \hfill 136167.000 & \hfill 3472.528 & \hfill 206349.900 & \hfill 714.765 \\ 
  \hline

\end{tabularx}
\end{adjustbox}

表格型

答案3

  • 与@egreg 回答类似(+1¸),但使用tabularray软件包版本 2022B:
  • 不要缩放表格!最好将表格列设计得更窄一些。
  • 要对齐数字(在小数点处),请使用 `siunitx} 包

编辑: 规格数字格式由默认改为列数字格式。

\documentclass{article}
\usepackage[a4paper,
            total={160mm,247mm}, left=25mm,top=25mm]{geometry}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx}

\begin{document}
    \begin{center}
\sisetup{group-minimum-digits=3}
\begin{tblr}{colspec = {*{2}{Q[c, si={table-format=3.0}]}
                             Q[c, si={table-format=6.3}]
                             Q[c, si={table-format=4.3}]
                             Q[c, si={table-format=6.3}]
                             Q[c, si={table-format=3.3}]},
             row{1,2}= {guard}
             }
  \toprule
\SetCell[r=2]{c} {Velocity\\ (m/s)}
    & \SetCell[r=2]{c} {Reynolds\\ number}
            & \SetCell[c=4]{c}   Force
                            &           &               &           \\
    \midrule
    &       & Viscous X     & Viscous Y & Viscous X     & Viscous Y \\
    \midrule
1   &  2    &  1247.208     &    0.401  &   1935.377    &   0.071   \\
10  &  20   &  12487.550    &   40.039  &  19370.400    &   7.136   \\
100 & 200   & 136167.000    & 3472.528  & 206349.900    & 714.765   \\
    \bottomrule
\end{tblr}
\end{center}
\end{document}

在此处输入图片描述

(红线表示文本区域边框)

相关内容