2

First question. I want to organize these two tabular as subtables (a) and (b) of a main table and share a single caption.

Second question. I want to cross out the second row of the first subtable with a red line.

Can anyone help me?

'''

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

Simon Dispa
  • 39,141
  • 3
    Welcome to TeX.SE! Please extend your code fragment to complete, compilable small document. What column type is B? – Zarko Mar 16 '22 at 13:18

2 Answers2

2

(1) First question. To have two subtables (a) and (b) sharing a single caption the following structure might be used together with the package 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) Making the table fit into the page with a readable font required more changes, mostly using three lines for the header (package makecell) and simplifying the column definitions (package array). Also added the package siunitx to include proper SI units.

(3) Second question. The solution for strikeout an entire row was taken from strikeout a entire row

Mark the start of the red line with \StrikeStarts{<cell contents>} and the end with \StrikeEnds{<cell contents>}

The (semi) final result

cc

This is the code used.

(Still needed is to make the tabular automatically fit the width of the text, align the decimal points, improve the "lines", but those things are beyond the scope of the questions)

\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)]\nodena{#1}; }

\newcommand{\StrikeEnds}[1]{% \tikz[baseline=(end.base)]\nodena{#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 } &amp;
        \thead{ Varus \\angle \\ \unit{[\degree]} } &amp;
        \thead{Posterior\\ slope \\ \unit{[\degree]} } &amp;
        \thead{ Body \\ Weight \\ \unit{[\kilogram]}} &amp;
        \thead{Body \\Weight  \\ \unit{[\newton]}} &amp;
        \thead{ $-F_z$ \\(HIGH100) \\ \unit{[\newton]} }&amp;
        \thead{$-F_z$ \\ (Individual)\\ \unit{[\newton]}} &amp;
        \thead{Weight \\Factor\\ \unit{[/]} }\\
        \hline
        K1L&amp;3   &amp;5  &amp;105&amp;1030   &amp;2646.3 &amp;2436.1 &amp;0.86\\
\StrikeStarts{K2L}&amp;5    &amp;11 &amp;92 &amp;903    &amp;2830.9 &amp;1948.4 &amp;\StrikeEnds{0.69}\\
        K3R&amp;3.5 &amp;10 &amp;98 &amp;960    &amp;2762.4 &amp;1987.7 &amp;0.7\\
        K5R&amp;1   &amp;7  &amp;96 &amp;942    &amp;2935.1 &amp;1996.5 &amp;0.7\\
        K6L&amp;-4  &amp;7  &amp;83 &amp;814    &amp;3034.1&amp;2187.6  &amp;0.86\\
        K7L&amp;6.5 &amp;7  &amp;69 &amp;678    &amp;2414.4 &amp;1666.9 &amp;0.59\\
        K8L&amp;4   &amp;11 &amp;79 &amp;775    &amp;2741   &amp;1631.4 &amp;0.58\\
        K9L&amp;7   &amp;6  &amp;109        &amp;1070   &amp;3359   &amp;2149.7&amp;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 } &amp;
    \thead{ Varus \\angle \\ \unit{[\degree]} } &amp;
    \thead{Posterior\\ slope \\ \unit{[\degree]} } &amp;
    \thead{ Body \\ Weight \\ \unit{[\kilogram]}} &amp;
    \thead{Body \\Weight  \\ \unit{[\newton]}} &amp;
    \thead{ $-F_z$ \\(HIGH100) \\ \unit{[\newton]} }&amp;
    \thead{$-F_z$ \\ (Individual)\\ \unit{[\newton]}} &amp;
    \thead{Weight \\Factor\\ \unit{[/]} }\\
    \hline
    K1L&amp;3   &amp;5  &amp;105&amp;1030   &amp;2646.3 &amp;2436.1 &amp;0.86\\
    K2L&amp;5   &amp;11 &amp;92 &amp;903    &amp;2830.9 &amp;1948.4 &amp;0.69\\
    K3R&amp;3.5 &amp;10 &amp;98 &amp;960    &amp;2762.4 &amp;1987.7 &amp;0.7\\
    K5R&amp;1   &amp;7  &amp;96 &amp;942    &amp;2935.1 &amp;1996.5 &amp;0.7\\
    K6L&amp;-4  &amp;7  &amp;83 &amp;814    &amp;3034.1&amp;2187.6  &amp;0.86\\
    K7L&amp;6.5 &amp;7  &amp;69 &amp;678    &amp;2414.4 &amp;1666.9 &amp;0.59\\
    K8L&amp;4   &amp;11 &amp;79 &amp;775    &amp;2741   &amp;1631.4 &amp;0.58\\
    K9L&amp;7   &amp;6  &amp;109        &amp;1070   &amp;3359   &amp;2149.7&amp;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}

The package nicematrix , that works with tikz node is able to manage the strikeout and also the X columns, the S columns and the new line inside the cell (command \Block). This is an example:

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}

Simon Dispa
  • 39,141
2

By use of the tabularray (with libraries booktabs and siunitx), subcaption and tikz with library 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}

enter image description here

Zarko
  • 296,517