4

I'm trying to make a table like this: enter image description here

But when i use this code to generate it:

\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}

I get this: enter image description here

Which the inside text is so tiny.

How can i fix that?

0

4 Answers 4

3

Like this?

enter image description here

In comparison to your code snipped I make the following changes:

  • made complete MWE
  • use tabularx instead tabular
  • renewcommand for column type X
  • use booktabs for horizontal rules
  • reduce font size to \small

Complete 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
  • Thank you very much, but it makes a frame for the whole of page!
    – H.H
    Commented Jul 12, 2016 at 14:00
  • yes, because I use it as option in geometry package to show page layout. it serves only for test purposed, for document production it had to be removed.
    – Zarko
    Commented Jul 12, 2016 at 14:24
4

Here is a start, by stacking the column headers in a \Centerstack.

EDITED to add a column and use \cline to produce line-break effect. Additionally, set in \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}

enter image description here

0
3

In your code, you want to resize you table by adapting the width and height of the produced table with an adjustbox, as if it was a picture you wanted to resize. It is not the better way to do it. Indeed, you see that the font size is also shrunk.

There are plenty of ways to define a table according to its maximal dimensions. Here is a suggestion using tabulary. It uses following syntax:

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

tabulary introduces new column types: L, C, R, and J that have adjustable width (see documentation).

You can observe that, instead of writing CCCCCCCC as coulmn types, you can use the trick : *{8}{C} (i.e. 8 times the column C).
Last advice: when you create tables, always load the array package!


enter image description here

\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}

P.S.: See also Steven's answer for refinement using \clines and \Centerstack!

0
3

Don't use adjustbox! You can have a table in \footnotesize loading geometry, which gives by default more sensible margins, playing with the value of \tabcolsep and using a mix of tabularx and makecell in order to have multiline column heads. Here are two possibilities, both replacing \hline with the rules of booktabs:

    \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} 

enter image description here

Ìmprovement added:

Here is a solution with a small fontsize. I used caption for caption formatting and a correct vertical spacing between above caption and table. The use of X column type is different.

\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} 

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .