合并 Latex 表中的单元格

合并 Latex 表中的单元格

我正在尝试合并三角形单元格,以便 x 和 y 值与该元素相对应。同样,尝试对四边形单元格和 No. Elements 单元格实现相同的操作。请帮忙,我试了很多方法,但还是搞不定!!

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

答案1

据我理解你的问题,如果你把自己关进牢房,你的表格会变得更加清晰:-):

在此处输入图片描述

通过使用以下tabularray包可以简单完成此操作:

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

答案2

这是一个 MWE,我相信它可以解决您的问题。我使用了多列,您可以在此处阅读: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 使用多列

答案3

这里与用户 26305 的类似,但我在“四边形”之前添加了一些负空间,因为它比它跨越的两列加起来更宽:

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

表格示例

答案4

另一个建议:


姆韦


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

相关内容