小桌子问题

小桌子问题

我正在尝试制作这样的表格: 在此处输入图片描述

但是当我使用此代码来生成它时:

\begin{table}[h!]
\centering
 \caption{Elastic properties of tissue}
 \label{jj}
\begin{adjustbox}{width=\textwidth,totalheight=\textheight,keepaspectratio}
\huge
\begin{tabular}{cccccccc}
\hline
 \multicolumn{4}{c}{decagonal prism-shaped tumor}& \multicolumn{4}{c}{10-winged star-shaped base tumor}\\
 \hline
Number of elements & Element type&Maximum relative error(\%) &Computational time(sec)&Number of elements & Element type&Maximum relative error(\%)&Computational time(sec)\\
\hline
21796 & C3D4T &0&19.27&22362&C3D4T&0&21.49\\
\hline
29725 & C3D4T &0.0751&23.44&29869&C3D4T&0.0665&23.56\\
\hline
44029 & C3D4T &0.0382&29.82&43366&C3D4T&00269&30.81\\
\hline
\end{tabular}
\end{adjustbox}
\end{table}

我明白了: 在此处输入图片描述

里面的文字太小了。

我该如何修复它?

答案1

像这样?

在此处输入图片描述

与您的代码片段相比,我做了以下更改:

  • 完成 MWE
  • 改用tabularxtabular
  • 列类型的更新命令X
  • 用于booktabs水平线
  • 减小字体大小至\small

完成 MWE:

\documentclass{article}
\usepackage{booktabs,tabularx}
\usepackage{ragged2e}
\renewcommand\tabularxcolumn[1]{b{#1}}

\usepackage[showframe]{geometry}

\begin{document}
\begin{table}[htb]
    \centering
    \small
\caption{Elastic properties of tissue}
    \label{jj}
\begin{tabularx}{\textwidth}{*{8}{>{\Centering\arraybackslash}X}}
    \toprule
\multicolumn{4}{c}{decagonal prism-shaped tumor}
    &   \multicolumn{4}{c}{10-winged star-shaped base tumor}            \\
    \cmidrule(lr){1-4} \cmidrule(lr){5-8}
Number of elements  & Element type  & Maximum relative error (\%)   & Computa\-tional time (sec) 
    & Number of elements    & Element type  & Maximum relative error (\%)   & Computa\-tional time (sec)    \\
    \midrule
21796   &   C3D4T   &   0       &   19.27   &   22362   &   C3D4T   &   0       &   21.49       \\
29725   &   C3D4T   &   0.0751  &   23.44   &   29869   &   C3D4T   &   0.0665  &   23.56       \\
44029   & C3D4T     &   0.0382  &   29.82   &   43366   &   C3D4T   &   00269   &   30.81       \\
    \bottomrule
\end{tabularx}
    \end{table} 
\end{document}

答案2

从这里开始,通过将列标题堆叠在一起\Centerstack

已编辑,添加一列并用于\cline产生换行效果。此外,在 中设置\sffamily

\documentclass{article}
\usepackage{adjustbox,stackengine}
\setstackEOL{/}
\setstackgap{L}{\normalbaselineskip}
\begin{document}
\begin{table}[h!]
\sffamily
\centering
 \caption{Elastic properties of tissue}
 \label{jj}
\begin{adjustbox}{width=\textwidth,totalheight=\textheight,keepaspectratio}
\huge
\begin{tabular}{ccccccccc}
\hline
 \multicolumn{4}{c}{decagonal prism-shaped tumor}&& \multicolumn{4}{c}{10-winged star-shaped base tumor}\\
\cline{1-4}\cline{6-9}
\Centerstack{Number of/ elements} & \Centerstack{Element/type}&
\Centerstack{Maximum/ relative/ error(\%)} &\Centerstack{Computational /time(sec)}&&
\Centerstack{Number/ of/ elements} & \Centerstack{Element/ type}&
\Centerstack{Maximum/ relative/ error(\%)}&\Centerstack{Computational/ time(sec)}\\
\cline{1-4}\cline{6-9}
21796 & C3D4T &0&19.27&&22362&C3D4T&0&21.49\\
\cline{1-4}\cline{6-9}
29725 & C3D4T &0.0751&23.44&&29869&C3D4T&0.0665&23.56\\
\cline{1-4}\cline{6-9}
44029 & C3D4T &0.0382&29.82&&43366&C3D4T&00269&30.81\\
\cline{1-4}\cline{6-9}
\end{tabular}
\end{adjustbox}
\end{table}
\end{document}

在此处输入图片描述

答案3

在您的代码中,您想通过使用 调整生成的表格的宽度和高度来调整表格的大小adjustbox,就好像您要调整图片的大小一样。这不是更好的方法。事实上,您会看到字体大小也缩小了。

根据表格的最大尺寸,有很多种方法可以定义表格。以下是使用tabulary. 它使用以下语法:

\begin{tabulary}{<maximal_width_of_the_table>}{<column_types>}
    <your_table>
\end{tabulary}

tabulary引入了新的列类型:L、、和具有可调整宽度的列类型(参见文档)CRJ

您可以观察到,CCCCCCCC您可以使用技巧:(*{8}{C}即 8 倍的列C),而不是将其写为列类型。
最后的建议:创建表时,请务必加载array包!


在此处输入图片描述

\documentclass{scrartcl}
    \usepackage{adjustbox}
    \usepackage{array, tabulary}

\begin{document}
    \begin{table}[h!]
        \centering
        \caption{Elastic properties of tissue}
        \label{jj}
            \begin{tabulary}{\textwidth}{*{8}{C}}
                \hline
                \multicolumn{4}{c}{decagonal prism-shaped tumor}& \multicolumn{4}{c}{10-winged star-shaped base tumor}\\
                \hline
                Number of elements & Element type&Maximum relative error(\%) &Computational time(sec)&Number of elements & Element type&Maximum relative error(\%)&Computational time(sec)\\
                \hline
                21796 & C3D4T &0&19.27&22362&C3D4T&0&21.49\\
                \hline
                29725 & C3D4T &0.0751&23.44&29869&C3D4T&0.0665&23.56\\
                \hline
                44029 & C3D4T &0.0382&29.82&43366&C3D4T&00269&30.81\\
                \hline
            \end{tabulary}
    \end{table}
\end{document}

附注:另请参阅史蒂文的回答\cline使用s 和进行细化\Centerstack

答案4

不要使用!您可以在加载时adjustbox使用表格,默认情况下会提供更合理的边距,使用 的值并混合使用和以获得多行列头。以下是两种可能性,均 使用 的规则进行替换:\footnotesizegeometry\tabcolseptabularxmakecell\hlinebooktabs

    \documentclass{article}
    \usepackage[utf8]{inputenc}
    \usepackage[showframe]{geometry} \usepackage{fourier, erewhon}
    \usepackage{array, graphicx, caption, booktabs, adjustbox, makecell, tabularx}%

    \usepackage[table, x11names]{xcolor}
   \renewcommand{\tabularxcolumn}[1]{>{\centering\arraybackslash}m{#1}}

    \begin{document}

\begin{table}[h!]
  \centering\setlength\tabcolsep{3pt}\setlength\cmidrulewidth{\lightrulewidth}
  \captionsetup{font=small}
  \caption{Elastic properties of tissue}
  \label{jj}
  \footnotesize
  \begin{tabularx}{\linewidth}{c*{2}{cXX}X}
    \toprule
    \multicolumn{4}{c}{decagonal prism-shaped tumor}& \multicolumn{4}{c}{10-winged star-shaped base tumor}\\
    \cmidrule(l{0.4em}r){1-4} \cmidrule(l{0.4em}r){5-8}
    \thead{Number of & & & & & & & \\ elements} & \thead{Element\\ type} & Maximum \makebox[\linewidth]{relative error (\%)} & Computational time (sec)& \thead{Number of \\ elements} & \thead{Element \\type} & Maximum \makebox[\linewidth]{relative error (\%)} & Computational time (sec) \\
    \cmidrule(l{0.4em}r){1-4} \cmidrule(l{0.4em}r){5-8}
    21796 & C3D4T & 0 & 19.27 & 22362 & C3D4T & 0 & 21.49 \\
    \addlinespace
    29725 & C3D4T & 0.0751 & 23.44 & 29869 & C3D4T & 0.0665 & 23.56 \\
    \addlinespace
    44029 & C3D4T & 0.0382 & 29.82 & 43366 & C3D4T & 00269 & 30.81 \\
    \bottomrule
  \end{tabularx}
\end{table}


\begin{table}[h!]
  \centering\setlength\tabcolsep{3pt}\setlength\cmidrulewidth{\lightrulewidth}
  \captionsetup{font=small}
  \caption{Elastic properties of tissue}
  \label{jj}
  \footnotesize
  \begin{tabularx}{\linewidth}{c*{2}{cXX}X}
    \toprule
    \multicolumn{4}{c}{decagonal prism-shaped tumor}& \multicolumn{4}{c}{10-winged star-shaped base tumor}\\
    \cmidrule(l{0.4em}r){1-4} \cmidrule(l{0.4em}r){5-8}
    \thead{Number of & & & & & & & \\ elements} & \thead{Element\\ type} & Maximum \makebox[\linewidth]{relative error (\%)} & Computational time (sec)& \thead{Number of \\ elements} & \thead{Element \\type} & Maximum \makebox[\linewidth]{relative error (\%)} & Computational time (sec) \\
    \cmidrule(r){1-4} \cmidrule(l){5-8}
    \addlinespace[-\belowrulesep]
    \rowcolor{lightgray!30}21796 & C3D4T & 0 & 19.27 & 22362 & C3D4T & 0 & 21.49 \\[1.5ex]
    29725 & C3D4T & 0.0751 & 23.44 & 29869 & C3D4T & 0.0665 & 23.56 \\[1.5ex]
    \rowcolor{lightgray!30}44029 & C3D4T & 0.0382 & 29.82 & 43366 & C3D4T & 00269 & 30.81 \\[1.5ex]
    \addlinespace[-\aboverulesep]
    \bottomrule
  \end{tabularx}
\end{table}

\end{document} 

在此处输入图片描述

增加的改进:

这是一个small带有字体大小的解决方案。我使用caption它来格式化标题,并在上​​面的标题和表格之间设置正确的垂直间距。列类型的使用X有所不同。

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[showframe]{geometry} %
\usepackage{tabularx, makecell, booktabs, caption}

\begin{document}

\begin{table}[ht!]
\centering
\sffamily\small
\setlength{\tabcolsep}{5pt}
\captionsetup{font={sf, small},labelfont=bf, labelsep=period}
 \caption{Elastic properties of tissue}
 \label{jj}
\begin{tabularx}{\linewidth}{*{2}{ccc >{\centering\arraybackslash}X}}
\toprule
 \multicolumn{4}{c}{decagonal prism-shaped tumor}& \multicolumn{4}{c}{10-winged star-shaped base tumor}\\
 \cmidrule(lr){1-4}\cmidrule(lr){5-8}
\makecell{Number of\\ elements} & \makecell{Element\\ type} & \makecell{Maximum\\ relative\\ error(\%)} & \makecell{Computational\\ time (sec)} & \makecell{Number of\\ elements} & \makecell{Element\\ type} & \makecell{Maximum\\ relative\\ error (\%)} & \makecell{Computational\\ time (sec)} \\
\midrule
21796 & C3D4T &0&19.27&22362&C3D4T&0&21.49\\
\addlinespace
29725 & C3D4T &0.0751&23.44&29869&C3D4T&0.0665&23.56\\
\addlinespace
44029 & C3D4T &0.0382&29.82&43366&C3D4T&00269&30.81\\
\bottomrule
\end{tabularx}

\end{table}

\end{document} 

在此处输入图片描述

相关内容