删除表格行并分别给两个表格添加标题

删除表格行并分别给两个表格添加标题

第一个问题。我想将这两个表格组织为主表的子表 (a) 和 (b),并共享一个标题。

第二个问题。我想用红线划掉第一个子表的第二行。

谁能帮我?

'''

\begin{table}[H]
\centering
\resizebox{\textwidth}{!}{
\newcolumntype{B}{>{\columncolor{bluepoli!40}}}

\begin{tabular}{|Bc| c c c c c c c|}
\hline
\rowcolor{bluepoli!40}

    \textbf{\footnotesize    Patient} & Varus angle [°] & Posterior slope [°] & Body Weight [kg] & Body Weight [N] & $-F_z$ (HIGH100) [N] & $-F_z$ (Individual) [N] & Weight Factor [/] \T\B\\
    \hline
   \textbf{\footnotesize     K1L} & 3 & 5 & 105 & 1030 & 4136.8 & 3587.1 & 0.92\T\B\\
    \textbf{\footnotesize    K2L} & 5 & 11 & 92 & 903 & 4138.1 & 3655.3 & 0.94 \T\B\\
    \textbf{\footnotesize    K3R} & 3.5 & 10 & 98 & 960 & 4152.8 & 2887.9 & 0.74 \T\B \\
    \textbf{\footnotesize   K5R} & 1 & 7 & 96 & 942 & 3508.4 & 3374.5 & 0.86 \T\B \\
    \textbf{\footnotesize    K6L} & -4 & 7 & 83 & 814 & 4060.3 & 2970.9 & 0.76 \T\B\\
    \textbf{\footnotesize   K7L} & 6.5 & 7 & 69 & 678 & 3488.3 & 2146.8 & 0.55 \T\B\\
    \textbf{\footnotesize   K8L} & 4 & 11 & 79 & 775 & 3542.8 & 2109.7 & 0.54 \T\B\\
    \textbf{\footnotesize   K9L} & 7 & 6 & 109 & 1070 & 2938.5 & 2182.6 & 0.56 \T\B\\
    \hline
\end{tabular}}
\caption{}

\bigskip
\resizebox{\textwidth}{!}{
\newcolumntype{B}{>{\columncolor{bluepoli!40}}}
\begin{tabular}{|Bc| c c c c c c c|}
\hline
\rowcolor{bluepoli!40}

   \textbf{\footnotesize    Patient} & Varus angle [°] & Posterior slope [°] & Body Weight [kg] & Body Weight [N] & $-F_z$ (HIGH100) [N] & $-F_z$ (Individual) [N] & Weight Factor [/] \T\B\\
    \hline
    \textbf{\footnotesize    K1L} & 3 & 5 & 105 & 1030 & 2646.3 & 2436.1 & 0.86 \T\B\\
    \textbf{\footnotesize    K2L} & 5 & 11 & 92 & 903 & 2830.9 & 1948.4 & 0.69 \T\B\\
    \textbf{\footnotesize    K3R} & 3.5 & 10 & 98 & 960 & 2762.4 & 1987.7 & 0.7 \T\B \\
    \textbf{\footnotesize   K5R} & 1 & 7 & 96 & 942 & 2935.1 & 1996.5 & 0.7 \T\B \\
    \textbf{\footnotesize    K6L} & -4 & 7 & 83 & 814 & 3034.1 & 2187.6 & 0.86 \T\B\\
    \textbf{\footnotesize   K7L} & 6.5 & 7 & 69 & 678 & 2414.4 & 1666.9 & 0.59 \T\B\\
    \textbf{\footnotesize   K8L} & 4 & 11 & 79 & 775 & 2741 & 1631.4 & 0.58 \T\B\\
    \textbf{\footnotesize   K9L} & 7 & 6 & 109 & 1070 & 3359 & 2149.7 & 0.76 \T\B\\
    \hline
\end{tabular}}

\caption{Table in which the \emph{Weight Factors} are depicted as the ratio between the first load peak of the activity and the corresponding one in the average \emph{HIGH100} data. In figure a) the stair descending activity is shown while in figure b) the walking exercise can be seen. In both cases the patient highlighted in red was considered an outlier for the following calculations.}
\label{tab:WF_tab}
\end{table}

答案1

(1)第一个问题。要使两个subtables(a) 和 (b) 共享一个标题,可以将以下结构与包一起使用subcaption

\begin{table}[ht!]
    \centering  
    \begin{subtable}{\linewidth}    
        \footnotesize \centering
        \begin{tabular}{|c| c c c c c c c|}     
        ...
        \end{tabular}
        \subcaption{Subtable I}\label{subtab:a}
    \end{subtable}% 
    \bigskip
    
    \begin{subtable}{\linewidth}    
        \footnotesize \centering
        \begin{tabular}{|c| c c c c c c c|}     
        ...
        \end{tabular}
        \subcaption{Subtable II}\label{subtab:b}
    \end{subtable}%
        \caption{Table in which the \emph{Weight Factors} are depicted  ...}
        \label{tab:WF_tab}
\end{table}

(2)要使表格适合页面且字体易读,需要进行更多更改,主要是使用三行作为标题(包makecell)并简化列定义(包array)。还添加了包siunitx以包含适当的 SI 单位。

(3)第二个问题。删除整行的解决方案来自删除整行

用 标记红线的起点\StrikeStarts{<cell contents>},用 标记红线的终点\StrikeEnds{<cell contents>}

(半)最终结果

抄送

这是所使用的代码。

(仍然需要使表格自动适应文本的宽度,对齐小数点,改进“线条”,但这些超出了问题的范围)

\documentclass[12pt,a4paper]{article}

\usepackage{array}
\usepackage{graphicx}
\usepackage[table]{xcolor}

\usepackage{makecell} % newlines in cell
\renewcommand\theadalign{tc}
\renewcommand\theadfont{\bfseries}

\usepackage{siunitx} % SI units
\usepackage{subcaption}% subtables

\newcolumntype{C}[2]{>{\bfseries\columncolor{#1}\centering}p{#2}}   
\setlength{\tabcolsep}{3pt}

\usepackage{showframe}

% From https://tex.stackexchange.com/a/488910/161015
\usepackage{tikz}
\tikzstyle{every picture}+=[remember picture]
\tikzstyle{na} = [shape=rectangle,inner sep=0pt]

\newcommand{\StrikeStarts}[1]{%
    \tikz[baseline=(begin.base)]\node[na](begin){#1};
}

\newcommand{\StrikeEnds}[1]{%
    \tikz[baseline=(end.base)]\node[na](end){#1};
    \begin{tikzpicture}[overlay]
        \draw[red] (begin.west) -- (end.east);
    \end{tikzpicture}
}

\begin{document}
\begin{table}[ht!]
\centering
\renewcommand*{\arraystretch}{1.2} % expand the cells vertically
    
    \begin{subtable}{\linewidth}    
    \footnotesize \centering
        \begin{tabular}{|C{blue!10}{1.5cm}| c c c c c c c|}     
            \hline
            \rowcolor{blue!10}          
            \thead{\\Patient } &
            \thead{ Varus \\angle \\ \unit{[\degree]} } &
            \thead{Posterior\\ slope \\ \unit{[\degree]} } &
            \thead{ Body \\ Weight \\ \unit{[\kilogram]}} &
            \thead{Body \\Weight  \\ \unit{[\newton]}} &
            \thead{ $-F_z$ \\(HIGH100) \\ \unit{[\newton]} }&
            \thead{$-F_z$ \\ (Individual)\\ \unit{[\newton]}} &
            \thead{Weight \\Factor\\ \unit{[/]} }\\
            \hline
            K1L&3   &5  &105&1030   &2646.3 &2436.1 &0.86\\
    \StrikeStarts{K2L}&5    &11 &92 &903    &2830.9 &1948.4 &\StrikeEnds{0.69}\\
            K3R&3.5 &10 &98 &960    &2762.4 &1987.7 &0.7\\
            K5R&1   &7  &96 &942    &2935.1 &1996.5 &0.7\\
            K6L&-4  &7  &83 &814    &3034.1&2187.6  &0.86\\
            K7L&6.5 &7  &69 &678    &2414.4 &1666.9 &0.59\\
            K8L&4   &11 &79 &775    &2741   &1631.4 &0.58\\
            K9L&7   &6  &109        &1070   &3359   &2149.7&0.76\\
            \hline
        \end{tabular}
        \subcaption{Subtable I}\label{subtab:a}
    \end{subtable}%

\bigskip
    
    \begin{subtable}{\linewidth}    
    \footnotesize \centering
    \begin{tabular}{|C{blue!10}{1.5cm}| c c c c c c c|}     
        \hline
        \rowcolor{blue!10}          
        \thead{\\Patient } &
        \thead{ Varus \\angle \\ \unit{[\degree]} } &
        \thead{Posterior\\ slope \\ \unit{[\degree]} } &
        \thead{ Body \\ Weight \\ \unit{[\kilogram]}} &
        \thead{Body \\Weight  \\ \unit{[\newton]}} &
        \thead{ $-F_z$ \\(HIGH100) \\ \unit{[\newton]} }&
        \thead{$-F_z$ \\ (Individual)\\ \unit{[\newton]}} &
        \thead{Weight \\Factor\\ \unit{[/]} }\\
        \hline
        K1L&3   &5  &105&1030   &2646.3 &2436.1 &0.86\\
        K2L&5   &11 &92 &903    &2830.9 &1948.4 &0.69\\
        K3R&3.5 &10 &98 &960    &2762.4 &1987.7 &0.7\\
        K5R&1   &7  &96 &942    &2935.1 &1996.5 &0.7\\
        K6L&-4  &7  &83 &814    &3034.1&2187.6  &0.86\\
        K7L&6.5 &7  &69 &678    &2414.4 &1666.9 &0.59\\
        K8L&4   &11 &79 &775    &2741   &1631.4 &0.58\\
        K9L&7   &6  &109        &1070   &3359   &2149.7&0.76\\
        \hline
    \end{tabular}
    \subcaption{Subtable II}\label{subtab:b}
\end{subtable}%
        \caption{Table in which the \emph{Weight Factors} are depicted as the ratio between the first load peak of the activity and the corresponding one in the average \emph{HIGH100} data. In table (a) the stair descending activity is shown while in table (b) the walking exercise can be seen. In both cases the patient highlighted in red was considered an outlier for the following calculations.}
        \label{tab:WF_tab}
    \end{table}
\end{document}

与 tikz 节点配合使用的包nicematrix能够管理删除线以及X列、S单元格内的列和新行(命令\Block)。这是一个例子:

d

\documentclass[12pt,a4paper]{article}

\usepackage[table]{xcolor}  
\usepackage{siunitx} % SI units
\usepackage{subcaption}% subtables
\usepackage[left=3.00cm, right=3.00cm, top=4.00cm, bottom=3.00cm]{geometry}

\usepackage{nicematrix} 
\usepackage{tikz}

\begin{document}
\begin{table}[ht!]
\centering\footnotesize
    \begin{subtable}{\linewidth}    
    \centering\footnotesize
    \sisetup{table-format = 2.2, table-alignment-mode = format}
    \begin{NiceTabular}[width=\linewidth]{>{\bfseries\columncolor{blue!10}}c  S[table-number-alignment = center]  c  X[c]  X[c] X[2,c] X[2,c] S[table-number-alignment = center]}[cell-space-top-limit=4pt,cell-space-bottom-limit=2pt]     
            \hline
            \rowcolor{blue!10}\RowStyle{\bfseries}      
            \Block{}{Patient } &
            \Block{}{Varus \\angle \\ \unit{[\degree]} } &
            \Block{}{Posterior\\ slope \\ \unit{[\degree]} } &
            \Block{}{Body \\ Weight \\ \unit{[\kilogram]}} &
            \Block{}{Body \\Weight  \\ \unit{[\newton]}} &
            \Block{}{$-F_z$ \\(HIGH100) \\ \unit{[\newton]} }&
            \Block{}{$-F_z$ \\ (Individual)\\ \unit{[\newton]}} &
            \Block{}{Weight \\Factor\\ \unit{[/]} }\\
            \hline
            K1L&3   &5  &105&1030   &2646.3 &2436.1 &0.86\\
            K2L&5   &11 &92 &903    &2830.9 &1948.4 &0.69\\
            K3R&3.5 &10 &98 &960    &2762.4 &1987.7 &0.7\\
            K5R&1   &7  &96 &942    &2935.1 &1996.5 &0.7\\
            K6L&-4  &7  &83 &814    &3034.1&2187.6  &0.86\\
            K7L&6.5 &7  &69 &678    &2414.4 &1666.9 &0.59\\
            K8L&4   &11 &79 &775    &2741   &1631.4 &0.58\\
            K9L&7   &6  &109        &1070   &3359   &2149.7&0.76\\
            \hline
            \CodeAfter
            \tikz \draw [red] (3.5-|1) -- (3.5-|9);     % strikeout <<<<<<<<<<<<<<<<<<          
        \end{NiceTabular}
        \subcaption{Subtable I}\label{subtab:a}
    \end{subtable}%

    \bigskip
    
    \begin{subtable}{\linewidth}    
    entering\footnotesize   
    \subcaption{Subtable II}\label{subtab:b}
    \end{subtable}%
        \caption{Table in which the \emph{Weight Factors} are depicted as the ratio between the first load peak of the activity and the corresponding one in the average \emph{HIGH100} data. In table (a) the stair descending activity is shown while in table (b) the walking exercise can be seen. In both cases the patient highlighted in red was considered an outlier for the following calculations.}
            \label{tab:WF_tab}
    \end{table}
\end{document}

答案2

通过使用tabularray(带有库booktabssiunitxsubcaption以及tikz带有库tikzmark


\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx}
\usepackage{subcaption}

\begin{document}
    \begin{table}[ht]
    \sisetup{group-minimum-digits=4}%
\subfloat[Case A]{%
\begin{tblr}{colspec = {|X[l, m, font=\bfseries]
                         Q[c,m,si={table-format=-1.1}]|
                         Q[c,m,si={table-format=2}]
                         Q[c,m,si={table-format=3}]
                         Q[c,m,si={table-format=4}]
                    *{2}{Q[c,m,si={table-format=4.1}]}
                         Q[c,m,si={table-format=1.2}]|
                       },
              colsep = 3.3pt,
              row{1} = {font=\small, bg=cyan9}
            }
    \toprule
Patient
    & {{{Varus\\ angle\\ {[\si{\degree}]} }}}
            & {{{Posterior\\ slope\\ {[\si{\degree}]} }}}
                 & {{{Body\\ Weight\\ {[\si{\kilo\gram}]} }}}
                        & {{{Body\\ Weight\\ {[\si{\newton}]} }}}
                              & {{{$-F_z$\\ (HIGH100)\\ {[\si{\newton}]} }}}
                                       & {{{$-F_z$ \\ (Individual)\\ {[\si{\newton}]} }}}
                                                & {{{Weight\\ Factor}}}   \\
K1L &  3    &  5 & 105 & 1030 & 4136.8 & 3587.1 & 0.92  \\
\tikzmarknode{a}{K2L} 
    &  5    & 11 &  92 &  903 & 4138.1 & 3655.3 & 0.94  \\
K3R &  3.5  & 10 &  98 &  960 & 4152.8 & 2887.9 & 0.74  \\
K5R &  1    &  7 &  96 &  942 & 3508.4 & 3374.5 & 0.86  \\
K6L & -4    &  7 &  83 &  814 & 4060.3 & 2970.9 & 0.76  \\
K7L &  6.5  &  7 &  69 &  678 & 3488.3 & 2146.8 & 0.55  \\
K8L &  4    & 11 &  79 &  775 & 3542.8 & 2109.7 & 0.54  \\
K9L &  7    &  6 & 109 & 1070 & 2938.5 & 2182.6 & 0.56  \\
    \bottomrule
\end{tblr}
    }

\medskip
\subfloat[Case B]{%
\begin{tblr}{colspec = {|X[l, m, font=\bfseries]
                         Q[c,m,si={table-format=-1.1}]|
                         Q[c,m,si={table-format=2}]
                         Q[c,m,si={table-format=3}]
                         Q[c,m,si={table-format=4}]
                    *{2}{Q[c,m,si={table-format=4.1}]}
                         Q[c,m,si={table-format=1.2}]|
                       },
              colsep = 3.3pt,
              row{1} = {font=\small, bg=cyan9}
            }
    \toprule
Patient
    & {{{Varus\\ angle\\ {[\si{\degree}]} }}}
            & {{{Posterior\\ slope\\ {[\si{\degree}]} }}}
                 & {{{Body\\ Weight\\ {[\si{\kilo\gram}]} }}}
                        & {{{Body\\ Weight\\ {[\si{\newton}]} }}}
                              & {{{$-F_z$\\ (HIGH100)\\ {[\si{\newton}]} }}}
                                       & {{{$-F_z$ \\ (Individual)\\ {[\si{\newton}]} }}}
                                                & {{{Weight\\ Factor}}}   \\
    \midrule
K1L &  3    &  5 & 105 & 1030 & 4136.8 & 3587.1 & 0.92  \\
K1L &  3    &  5 & 105 & 1030 & 2646.3 & 2436.1 & 0.86  \\
K2L &  5    & 11 &  92 &  903 & 2830.9 & 1948.4 & 0.69  \\
K3R &  3.5  & 10 &  98 &  960 & 2762.4 & 1987.7 & 0.7   \\
K5R &  1    &  7 &  96 &  942 & 2935.1 & 1996.5 & 0.7   \\
K6L & -4    &  7 &  83 &  814 & 3034.1 & 2187.6 & 0.86  \\
K7L &  6.5  &  7 &  69 &  678 & 2414.4 & 1666.9 & 0.59  \\
K8L &  4    & 11 &  79 &  775 & 2741   & 1631.4 & 0.58  \\
K9L &  7    &  6 & 109 & 1070 & 3359   & 2149.7 & 0.76  \\
    \bottomrule
\end{tblr}
}

\caption{Table in which the \emph{Weight Factors} are depicted as the ratio between the first load peak of the activity and the corresponding one in the average \emph{HIGH100} data. In figure a) the stair descending activity is shown while in figure b) the walking exercise can be seen. In both cases the patient highlighted in red was considered an outlier for the following calculations.}
\label{tab:WF_tab}

\tikz[overlay,remember picture]\draw[red, thick] (a.west) -- ++ (\dimexpr\linewidth-1em,0);
    \end{table}
\end{document}

在此处输入图片描述

相关内容