TabularX - 单元格内容退出

TabularX - 单元格内容退出

我正在尝试修复我的垂直表格,年龄值正在退出单元格。

\begin{landscape}
\begin{tabularx}{\linewidth}{|>{\hsize=1.5\hsize}X|*{12}{>{\hsize=0.75\hsize}X|}}
\hline
    & \multicolumn{2}{c|}{\textbf{Shu et al.}} & \multicolumn{2}{c|}{\textbf{VRC}} & \multicolumn{2}{c|}{\textbf{SRC}} & \multicolumn{2}{c|}{\textbf{MSRC}} & \multicolumn{2}{c|}{\textbf{NFRC}} & \multicolumn{2}{c|}{\textbf{FSC}} \\ \hline
    & \makecell{Stable} & \makecell{Progr} & \makecell{Stable} & \makecell{Progr} & \makecell{Stable} & \makecell{Progr} & \makecell{Stable} & \makecell{Progr} & \makecell{Stable} & \makecell{Progr} & \makecell{Stable} & \makecell{Progr} \\ \hline
    \textbf{Subjects, No.} & 72 & 72 & 12 & 12 & 72 & 72 & 72 & 72 & 72 & 72 & 51 & 51 \\ \hline
    \textbf{F/M No.} & 29/43 & 22/50 & 3/9 & 3/9 & 29/43 & 29/43 & 29/43 & 29/43 & 35/37 & 35/37 & 19/32 & 20/31 \\ \hline
    \textbf{Age, mean +/- SD} & 61.3$\pm$10.09 & 61.45$\pm$11.44 & 66.5$\pm$10.5 & 68.1$\pm$6.9 & 61.0$\pm$8.8 & 61.2$\pm$8.6 & 60.7$\pm$6.4 & 60.7$\pm$9.3 & 62.0$\pm$9.4 & 62.0$\pm$9.2 & 60.3$\pm$8.6 & 63.8$\pm$8.9 \\ \hline
    \textbf{Hoehn \& Yahr Stage 1 (n)} & 47 & 25 & 0 & 0 & 32 & 32 & 32 & 32 & 32 & 32 & 22 & 22 \\ \hline
    \textbf{Hoehn \& Yahr Stage 2 (n)} & 47 & 25 & 12 & 12 & 40 & 40 & 40 & 40 & 40 & 40 & 29 & 29 \\ \hline
\end{tabularx}
\captionof{table}{Summary of cohorts constructed.}
\label{table:cohorts}
\end{landscape}

它看起来是这样的:

在此处输入图片描述

有什么推荐的解决办法吗?

答案1

尝试使用tabularray包。

\documentclass{article}

\usepackage[margin=1in]{geometry}
\usepackage{pdflscape}
\usepackage{tabularray}
\UseTblrLibrary{siunitx}

\begin{document}
\begin{landscape}
    \begin{tblr}{
        colspec={X[l,1]*{12}{X[-0.6]}},
        column{1}={cmd=\bfseries},
        rowspec={*{7}{m{3em}}},
        row{1}={cmd=\bfseries},
        row{5}={cmd=\num[separate-uncertainty]},
        cell{5}{1}={guard},
        hlines,
    }
        & \SetCell[c=2]{c} Shu et al. & & \SetCell[c=2]{c} VRC & & \SetCell[c=2]{c} SRC & & \SetCell[c=2]{c} MSRC & & \SetCell[c=2]{c} NFRC & & \SetCell[c=2]{c} FSC & \\
        & Stable & Progr & Stable & Progr & Stable & Progr & Stable & Progr & Stable & Progr & Stable & Progr \\
        Subjects, No. & 72 & 72 & 12 & 12 & 72 & 72 & 72 & 72 & 72 & 72 & 51 & 51 \\
        F/M No. & 29/43 & 22/50 & 3/9 & 3/9 & 29/43 & 29/43 & 29/43 & 29/43 & 35/37 & 35/37 & 19/32 & 20/31 \\
        \textbf{Age, mean +/- SD} & 61.3 \pm 10.09 & 61.45 \pm 11.44 & 66.5 \pm 10.5 & 68.1 \pm 6.9 & 61.0 \pm 8.8 & 61.2 \pm 8.6 & 60.7 \pm 6.4 & 60.7 \pm 9.3 & 62.0 \pm 9.4 & 62.0 \pm 9.2 & 60.3 \pm 8.6 & 63.8 \pm 8.9 \\
        Hoehn \& Yahr Stage 1 (n) & 47 & 25 & 0 & 0 & 32 & 32 & 32 & 32 & 32 & 32 & 22 & 22 \\
        Hoehn \& Yahr Stage 2 (n) & 47 & 25 & 12 & 12 & 40 & 40 & 40 & 40 & 40 & 40 & 29 & 29 \\
    \end{tblr}
\end{landscape}
\end{document}

在此处输入图片描述

解释

  1. X[l,1]将文本向左刷新,并将X[-0.6]列宽设置为最多第一列宽度的 0.6 倍。
  2. column{1}={cmd=\bfseries}并将row{1}={cmd=\bfseries}第一行和第一列格式化为粗体。
  3. rowspec={*{7}{m{3em}}}将所有行垂直居中,并将行高设置为3em
  4. row{5}={cmd=\num[separate-uncertainty]}\num使用包中的命令格式化第 5 行中的条目siunitx。这有助于更好地打印不确定性。
  5. cell{5}{1}={guard}阻止将之前的设置(第 5 行格式)应用于第 5 行的第一列,因为它不是数字。siunitx会抛出错误。这还会清除应用于第 1 列的粗体格式,因此必须在此处再次明确应用。
  6. hlines在每一行的前后画线。
  7. SetCell[c=2]{c}创建一个跨越两列的多列单元格(因此c=2)并使文本({c}部分)居中。

编辑

获取vlines第一行:

\documentclass{article}

\usepackage[margin=1in]{geometry}
\usepackage{pdflscape}
\usepackage{tabularray}
\UseTblrLibrary{siunitx}

\begin{document}
    \begin{landscape}
        \begin{tblr}{
                colspec={|X[l,1] | *{12}{X[-0.6]}|},
                column{1}={cmd=\bfseries},
                rowspec={*{7}{m{3em}}},
                row{1}={cmd=\bfseries},
                row{5}={cmd=\num[separate-uncertainty]},
                cell{5}{1}={guard},
                hlines,
                vlines={1}{solid},
            }
            & \SetCell[c=2]{c} Shu et al. & & \SetCell[c=2]{c} VRC & & \SetCell[c=2]{c} SRC & & \SetCell[c=2]{c} MSRC & & \SetCell[c=2]{c} NFRC & & \SetCell[c=2]{c} FSC & \\
            & Stable & Progr & Stable & Progr & Stable & Progr & Stable & Progr & Stable & Progr & Stable & Progr \\
            Subjects, No. & 72 & 72 & 12 & 12 & 72 & 72 & 72 & 72 & 72 & 72 & 51 & 51 \\
            F/M No. & 29/43 & 22/50 & 3/9 & 3/9 & 29/43 & 29/43 & 29/43 & 29/43 & 35/37 & 35/37 & 19/32 & 20/31 \\
            \textbf{Age, mean +/- SD} & 61.3 \pm 10.09 & 61.45 \pm 11.44 & 66.5 \pm 10.5 & 68.1 \pm 6.9 & 61.0 \pm 8.8 & 61.2 \pm 8.6 & 60.7 \pm 6.4 & 60.7 \pm 9.3 & 62.0 \pm 9.4 & 62.0 \pm 9.2 & 60.3 \pm 8.6 & 63.8 \pm 8.9 \\
            Hoehn \& Yahr Stage 1 (n) & 47 & 25 & 0 & 0 & 32 & 32 & 32 & 32 & 32 & 32 & 22 & 22 \\
            Hoehn \& Yahr Stage 2 (n) & 47 & 25 & 12 & 12 & 40 & 40 & 40 & 40 & 40 & 40 & 29 & 29 \\
        \end{tblr}
    \end{landscape}
\end{document}

在此处输入图片描述

编辑3

第一行的每个合并单元格周围的垂直线。

\documentclass{article}

\usepackage[margin=1in]{geometry}
\usepackage{pdflscape}
\usepackage{tabularray}
\UseTblrLibrary{siunitx}

\begin{document}
    \begin{landscape}
        \begin{tblr}{
                colspec={|X[l,1] *{6}{| X[-0.6] X[-0.6]}|},
                column{1}={cmd=\bfseries},
                rowspec={*{7}{m{3em}}},
                row{1}={cmd=\bfseries},
                row{5}={cmd=\num[separate-uncertainty]},
                cell{5}{1}={guard},
                hlines,
            }
            & \SetCell[c=2]{c} Shu et al. & & \SetCell[c=2]{c} VRC & & \SetCell[c=2]{c} SRC & & \SetCell[c=2]{c} MSRC & & \SetCell[c=2]{c} NFRC & & \SetCell[c=2]{c} FSC & \\
            & Stable & Progr & Stable & Progr & Stable & Progr & Stable & Progr & Stable & Progr & Stable & Progr \\
            Subjects, No. & 72 & 72 & 12 & 12 & 72 & 72 & 72 & 72 & 72 & 72 & 51 & 51 \\
            F/M No. & 29/43 & 22/50 & 3/9 & 3/9 & 29/43 & 29/43 & 29/43 & 29/43 & 35/37 & 35/37 & 19/32 & 20/31 \\
            \textbf{Age, mean +/- SD} & 61.3 \pm 10.09 & 61.45 \pm 11.44 & 66.5 \pm 10.5 & 68.1 \pm 6.9 & 61.0 \pm 8.8 & 61.2 \pm 8.6 & 60.7 \pm 6.4 & 60.7 \pm 9.3 & 62.0 \pm 9.4 & 62.0 \pm 9.2 & 60.3 \pm 8.6 & 63.8 \pm 8.9 \\
            Hoehn \& Yahr Stage 1 (n) & 47 & 25 & 0 & 0 & 32 & 32 & 32 & 32 & 32 & 32 & 22 & 22 \\
            Hoehn \& Yahr Stage 2 (n) & 47 & 25 & 12 & 12 & 40 & 40 & 40 & 40 & 40 & 40 & 29 & 29 \\
        \end{tblr}
    \end{landscape}
\end{document}

在此处输入图片描述

相关内容