文档中表格的字体大小相同

文档中表格的字体大小相同

我不知道如何在一个文档中让下面的两个表格具有相同的字体大小。我认为 latex 会创建不同的字体大小,因为一个表格有更多列。但是,我不知道如何以相同的小字体大小创建第一个表格。

感谢您的帮助。

\documentclass[a4paper,12pt,oneside,notitlepage]{article}

\usepackage{geometry}
\usepackage{etex}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{booktabs,dcolumn} 
\usepackage{setspace}         
\usepackage{bm}
\usepackage{endnotes}

\topmargin0.0cm   \topskip0cm
\headheight0.0cm  \headsep0.0cm
\textheight22.6cm \textwidth16.51cm
\footskip1.5cm    %\parskip0.5cm
\usepackage{longtable,tabu,}
\setlength{\parindent}{0em}
\usepackage{csvsimple}
\usepackage{lipsum}
\usepackage{float}
\usepackage{caption}
\usepackage{adjustbox}

\makeatletter
\csvset{
    autobooktabularcenterlong/.style={
        file=#1,
        after head=\csv@pretable\begin{tabular}{*{\csv@columncount}            {c}}\csv@tablehead,
            table head=\toprule\csvlinetotablerow\\\midrule,
            late after line=\\,
            table foot=\\\bottomrule,
            late after line=\ifnumequal{\thecsvrow}{20}{\\\midrule}{\\},
            late after last line=\csv@tablefoot\end{tabular}\csv@posttable,
        command=\csvlinetotablerow},
}
\makeatother
\newcommand{\csvautobooktabularcenterlong}[2][]        {\csvloop{autobooktabularcenterlong={#2},#1}}


\DeclareCaptionLabelSeparator{tableNewline}{\par}
\captionsetup[longtable]{
    justification=centering,
    labelsep=tableNewline,skip=5pt
}

\makeatletter
\renewcommand\footnotesize{%
    \@setfontsize\footnotesize\@ixpt{11}%
    \abovedisplayskip 8\p@ \@plus2\p@ \@minus4\p@
    \abovedisplayshortskip \z@ \@plus\p@
    \belowdisplayshortskip 4\p@ \@plus2\p@ \@minus2\p@
    \def\@listi{\leftmargin\leftmargini
        \topsep 4\p@ \@plus2\p@ \@minus2\p@
        \parsep 2\p@ \@plus\p@ \@minus\p@
        \itemsep \parsep}%
    \belowdisplayskip \abovedisplayskip
}
\makeatother
\begin{filecontents*}{dataonev1.csv}
Sector Description;A in percent;B in percent;Number of C values
Technology ;2.649;4.852;5
Automobiles \& Parts ;1.143;5.072;49
Personal \& Household Goods ;0.786;2.27;4
Utilities ;0.756;3.606;51
Food \& Beverage ;0.564;2.583;7
Oil \& Gas ;0.563;4.001;53
Insurance ;0.45;5.309;25
Banks ;0.323;3.783;130
Index;0.299;2.543;158
Industrial Goods \& Services ;0.243;2.504;41
Telecommunications ;0.194;5.09;57
\end{filecontents*}


\begin{filecontents*}{datatwov1.csv}
Sector;A in percent;B SD in percent;C in percent;D SD in percent;E in         percent;F SD in percent
Automobiles \& Parts;4.93;4.93;0.5;0.5;1.14;5.07
Banks;0.64;0.64;0.08;0.08;0.32;3.78
Basic Resources;2.9;2.9;-0.75;-0.75;-0.14;3.41
Chemicals;0.2;0.2;0;0;0.06;3.04
Construction \& Materials;;;-0.84;-0.84;-0.84;2.82
Financial Services;;;-0.25;-0.25;-0.25;1.78
Food \& Beverage;0.56;0.56;;;0.56;2.58
\end{filecontents*}


\begin{document}
    \setlength{\parskip}{1,27ex plus 0,635ex minus 0,211ex}
    \renewcommand{\baselinestretch}{1.25}
    \normalsize 
    \thispagestyle{empty}
    \renewcommand{\labelitemi}{$\diamond$}  % Aufzählungssymbol in Listen

\lipsum

\begin{table}[H]
    \centering
    \begin{adjustbox}{max width=0.9\textwidth}
        \footnotesize
        \csvautobooktabular[separator=semicolon]{dataonev1.csv}
    \end{adjustbox}
    \caption{dataone}\label{tab:dataone}
\end{table}

\lipsum

\begin{table}[H]
    \centering
    \begin{adjustbox}{max width=0.9\textwidth}
        \footnotesize
        \csvautobooktabularcenterlong[separator=semicolon]{datatwov1.csv}
    \end{adjustbox}
    \caption{datatwo}\label{tab:datatwo}
\end{table}
\end{document}

答案1

像这样,\adjustbox严格地删除和设置表格怎么样?\tiny

\documentclass[a4paper,12pt]{article}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[width=17cm]{geometry}
\usepackage{booktabs,dcolumn} 
\usepackage{csvsimple}
\usepackage{lipsum}
\usepackage{capt-of}
\makeatletter
\csvset{autobooktabularcenterlong/.style={... your definition ...}}
\makeatother
\newcommand{\csvautobooktabularcenterlong}[2][]{... your definition ...}
\begin{document}
\lipsum[2]
\begin{center}
  \tiny
  \csvautobooktabular[separator=semicolon]{dataonev1.csv}
  \captionof{table}{dataone}\label{tab:dataone}
\end{center}
\lipsum[2]
\begin{center}
  \tiny
  \csvautobooktabularcenterlong[separator=semicolon]{datatwov1.csv}
  \captionof{table}{datatwo}\label{tab:datatwo}
\end{center}
\end{document}

在此处输入图片描述

答案2

如果您使用\tiny字体大小来使表格材料“按原样”适合页面,则会面临导致该材料几乎无法阅读的严重风险。

我建议您 (a) 重新组织标题材料,使其占用更少的空间,(b) 将数字数据与(实际或隐含的)小数标记对齐,以及 (c) 对负数使用正确的印刷“减号”符号。在下面的代码中,我使用S列类型(由siunitx)来实现目标 (b) 和 (c)。通过这些更改,您可以轻松地将表格放入文本块中没有必须借助字体大小魔法。

在此处输入图片描述

\documentclass[a4paper,12pt,oneside,notitlepage]{article}

\usepackage{geometry}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{booktabs,setspace,lipsum,caption,siunitx}

\topmargin0.0cm   \topskip0cm
\headheight0.0cm  \headsep0.0cm
\textheight22.6cm \textwidth16.51cm
\footskip1.5cm    %\parskip0.5cm


\setlength{\parindent}{0em}
\setlength{\parskip}{1.27ex plus 0.635ex minus 0.211ex}
\setstretch{1.25}
\renewcommand{\labelitemi}{$\diamond$}  % Aufzählungssymbol in Listen

\begin{document}
\thispagestyle{empty}

\begin{table}[ht!]
\centering
\begin{tabular}{@{} l *{2}{S[table-format=1.3]}
                           S[table-format=3.0] @{}}
\toprule
Sector Description & {A}       & {B}       & {Number of} \\
                   & {(in \%)} & {(in \%)} & {C Values}\\
\midrule
Technology                    & 2.649 & 4.852 &   5\\
Automobiles \& Parts          & 1.143 & 5.072 &  49\\
Personal \& Household Goods   & 0.786 & 2.27  &   4\\
Utilities                     & 0.756 & 3.606 &  51\\ 
\addlinespace
Food \& Beverage              & 0.564 & 2.583 &   7\\
Oil \& Gas                    & 0.563 & 4.001 &  53\\
Insurance                     & 0.45  & 5.309 &  25\\
Banks                         & 0.323 & 3.783 & 130\\ 
\addlinespace
Index                         & 0.299 & 2.543 & 158\\
Industrial Goods \& Services  & 0.243 & 2.504 &  41\\
Telecommunications            & 0.194 & 5.09  &  57\\
\bottomrule
\end{tabular}
\caption{dataone}\label{tab:dataone}
\end{table}

\lipsum[2] % filler text

\begin{table}[h!]
\centering
\begin{tabular}{@{} l *{2}{S[table-format= 1.2]}
                      *{3}{S[table-format=-1.2]}
                           S[table-format= 1.2] @{}}
\toprule
Sector & {A} & {B SD} & {C} & {D SD} & {E}  & {F SD} \\
& {(in \%)} & {(in \%)} & {(in \%)} & {(in \%)} & {(in \%)} & {(in \%)}\\
\midrule
Automobiles \& Parts      & 4.93 & 4.93 & 0.5 & 0.5 & 1.14 & 5.07\\
Banks                     & 0.64 & 0.64 & 0.08 & 0.08 & 0.32 & 3.78\\
Basic Resources           & 2.9 & 2.9 & -0.75 & -0.75 & -0.14 & 3.41\\
Chemicals                 & 0.2 & 0.2 & 0 & 0 & 0.06 & 3.04\\
Construction \& Materials &  &  & -0.84 & -0.84 & -0.84 & 2.82\\
Financial Services        &  &  & -0.25 & -0.25 & -0.25 & 1.78\\
Food \& Beverage          & 0.56 & 0.56 &  &  & 0.56 & 2.58\\
\bottomrule
\end{tabular}
\caption{datatwo}\label{tab:datatwo}
\end{table}
\end{document}

相关内容