0

I am trying to merge the cell Triangular so that the x & y values correspond to that element. Similarly, trying to achieve the same for the Quadrilateral cell and No. Elements cell. Please help, i've tried so many things and cannot figure it out!!

\documentclass{article}
\usepackage{geometry}
\usepackage{tabularray}
\UseTblrLibrary{siunitx}

\begin{document}
\begin{table}[!ht]
    \centering
    \caption{Caption}
    \begin{adjustbox}{width=1\textwidth}
    \begin{tabular}{ccccccccc}
        \toprule
        Mesh Iteration & Triangular & & Quadrilateral & & Curvature Factor & No. Elements & & Max Stress\\
         & X & Y & X & Y & & Triangular & Quadrilateral & $\sigma_{\unit{xx}}$\\
         \hline \hline
         1 & 1 & 1 & 1 & 1 & 0.3 & 130 & 50 & 395.20\\
         2a & 1 & 1 & 0.5 & 1 & 0.3 & 130 & 25 & 394.82\\
         2b & 1 & 1 & 0.5 & 1 & 0.1 & 230 & 25 & 433.59\\
         3(1/2) & 0.25/0.5 & 0.25/0.5 & 0.5 & 1 & 0.3 & 106/44 & 10 & 430.87\\
         \bottomrule
    \end{tabular}
    \end{adjustbox}
    \label{tab:my_label}
\end{table}
\end{document}
2
  • Welcome to TeX:SE Please always provide complete small document called MWE (Minimal Working Example), which reproduce your problem. Btw, newer use `adjustbox on table. It make inconsistent font size with size use in document.
    – Zarko
    Commented May 30, 2022 at 22:15
  • noted, thank you! first time using this so I appreciate your comment. will keep in mind for next time!!
    – Misslee8
    Commented May 30, 2022 at 23:23

4 Answers 4

2

As I understood your question, your table will become more clear, if you jailed your cells :-):

enter image description here

This can be simple done by use of the tabularray package:

\documentclass{article}
\usepackage{geometry}
\usepackage{tabularray}
\UseTblrLibrary{siunitx}

\begin{document}
\begin{table}[!ht]
    \centering
    \caption{Caption}
    \footnotesize
    \begin{tblr}{hline{1,3,Z} = 1pt, hline{2,4-Y} = {solid},
                 vlines,
                 colspec = { *{9}{X[c,m]} },
                 colsep = 3pt
                 }
Mesh Iteration 
    &\SetCell[c=2]{c}   Triangular 
        &   &\SetCell[c=2]{c}   Quadrilateral    
                &   & Curvature Factor  
                        &\SetCell[c=2]{c}   No. Elements 
                            &   & Max  Stress   \\
    & X & Y & X & Y & Triangular  
                        &\SetCell[c=2]{c}   Quadrilateral 
                            &   & $\sigma_{\unit{xx}}$      \\
1      & 1 & 1 & 1   & 1 & 0.3 & 130 & 50 & 395.20\\
2a      & 1 & 1 & 0.5 & 1 & 0.3 & 130 & 25 & 394.82\\
2b      & 1 & 1 & 0.5 & 1 & 0.1 & 230 & 25 & 433.59\\
3(1/2)  & 0.25/0.5 
            & 0.25/0.5 
                & 0.5 & 1 & 0.3 & 106/44 
                                      & 10 & 430.87\\
    \end{tblr}
    \label{tab:my_label}
\end{table}
\end{document}
1
  • shoooot, saw this just didn't know how to execute with my own. thank you for the help! <3
    – Misslee8
    Commented May 30, 2022 at 23:01
0

Here is a MWE which I believe addresses your issue.I used multicolumn, which you can read about here: https://texblog.org/2012/12/21/multi-column-and-multi-row-cells-in-latex-tables/

\documentclass{article}
\usepackage{adjustbox, booktabs}


\begin{document}

\begin{table}[!ht]
    \centering
    \caption{Caption}
    \begin{adjustbox}{width=1\textwidth}
    \begin{tabular}{ccccccccc}
        \toprule
        Mesh Iteration & \multicolumn{2}{c}{Triangular} & \multicolumn{2}{c}{Quadrilateral} & Curvature Factor & \multicolumn{2}{c}{No. Elements} & Max Stress\\
         & X & Y & X & Y & & Triangular & Quadrilateral & $\sigma_{\unit{xx}}$\\
         \hline \hline
         1 & 1 & 1 & 1 & 1 & 0.3 & 130 & 50 & 395.20\\
         2a & 1 & 1 & 0.5 & 1 & 0.3 & 130 & 25 & 394.82\\
         2b & 1 & 1 & 0.5 & 1 & 0.1 & 230 & 25 & 433.59\\
         3(1/2) & 0.25/0.5 & 0.25/0.5 & 0.5 & 1 & 0.3 & 106/44 & 10 & 430.87\\
         \bottomrule
    \end{tabular}
    \end{adjustbox}
    \label{tab:my_label}
\end{table}

\end{document}

MWE using multicolumn

3
  • Your code does not compile :) Commented May 30, 2022 at 22:46
  • OMG thank you!! <3
    – Misslee8
    Commented May 30, 2022 at 23:00
  • @SimonDispa, I didn't know what package the \unit command was coming from. On Overleaf, it comes through as an error but still compiles, and I figured OP would already have the correct packages included.
    – user26305
    Commented May 31, 2022 at 0:09
0

Here's a similar to user26305's but I put in some negative space before "Quadrilateral" since it's wider than the two columns it spans combines:

\documentclass[12pt]{article}
\usepackage{adjustbox}
\usepackage{booktabs}
\usepackage{siunitx}

\begin{document}

\begin{table}[!ht]
    \centering
    \caption{Caption}
    \begin{adjustbox}{width=1\textwidth}
    \begin{tabular}{ccccccccc}
        \toprule
        Mesh Iteration & \multicolumn{2}{c}{Triangular} & \multicolumn{2}{@{\hspace*{-0.4em}}c}{Quadrilateral} & Curvature Factor & \multicolumn{2}{c}{No.\ Elements} & Max Stress\\
         & X & Y & X & Y & & Triangular & Quadrilateral & $\sigma_{\unit{xx}}$\\
         \hline \hline
         1 & 1 & 1 & 1 & 1 & 0.3 & 130 & 50 & 395.20\\
         2a & 1 & 1 & 0.5 & 1 & 0.3 & 130 & 25 & 394.82\\
         2b & 1 & 1 & 0.5 & 1 & 0.1 & 230 & 25 & 433.59\\
         3(1/2) & 0.25/0.5 & 0.25/0.5 & 0.5 & 1 & 0.3 & 106/44 & 10 & 430.87\\
         \bottomrule
    \end{tabular}
    \end{adjustbox}
    \label{tab:my_label}
\end{table}
\end{document}

table example

1
  • yes, thank you!! <3
    – Misslee8
    Commented May 30, 2022 at 23:00
0

Another proposal:


mwe


\documentclass{article}
\usepackage{geometry,booktabs,lipsum,multirow,siunitx}
\begin{document}
\lipsum[4][1-10]
\begin{table}[!ht]
 \caption{Caption\label{tab:my_label}}    
\centering\small
\begin{tabular*}{\linewidth}{@{}@{\extracolsep{\fill}}ccc>{\centering}p{2.5em}>{\centering}p{2.5em}cccc@{}}
 \toprule
\multirow{2.7}{*}{\parbox{4em}{\centering Mesh\\Iteration}} & \multicolumn{2}{c}{Triangular} & 
 \multicolumn{2}{c}{Quadrilateral} & \multirow{2.7}{*}{\parbox{5em}{\centering Curvature Factor}} & \multicolumn{2}{c}{No. Elements} & \multirow{2}{*}{\parbox{4em}{\centering Max Stress\\[-1ex]  $\sigma_{\unit{xx}}$}} \\
\cmidrule(rl){2-3}
\cmidrule(rl){4-5}
\cmidrule(rl){7-8}
 & X & Y & X & Y & & Triangular & Quadrilateral & \\
\cmidrule(rl){1-1}
\cmidrule(rl){2-2}
\cmidrule(rl){3-3}
\cmidrule(rl){4-4}
\cmidrule(rl){5-5}
\cmidrule(rl){6-6}
\cmidrule(rl){7-7}
\cmidrule(rl){8-8}
\cmidrule(rl){9-9}
%\midrule
1 & 1 & 1 & 1 & 1 & 0.3 & 130 & 50 & 395.20\\
2a & 1 & 1 & 0.5 & 1 & 0.3 & 130 & 25 & 394.82\\
2b & 1 & 1 & 0.5 & 1 & 0.1 & 230 & 25 & 433.59\\
3(1/2) & 0.25/0.5 & 0.25/0.5 & 0.5 & 1 & 0.3 & 106/44 & 10 & 430.87\\
\bottomrule
\end{tabular*}
\end{table}
\lipsum[2][1-6]
\end{document}

You must log in to answer this question.

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