将一个表格置于另一个表格的单元格中央

将一个表格置于另一个表格的单元格中央

我有这张表:

\documentclass[10pt,conference]{IEEEtran}
\usepackage{pgfplots}
\usepackage{tikz}        
\pgfplotsset{compat=newest}
\usepackage{cite}
\usepackage{newtxtext,newtxmath}
\usepackage{booktabs,siunitx}
\usepackage{multirow}
\usepackage{amsmath,amsfonts}
\usepackage{algorithmic}
\usepackage{graphicx}
\usepackage{pifont}
\usepackage{textcomp}
\usepackage{tabularx,ragged2e,bm,newtxmath} % new packages
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepackage{xcolor}
\usepackage{array}

\begin{document}
\begin{table*}[bt]
\newcommand{\mr}[1]{\multirow{2}{*}{#1}}
\newcommand{\mc}[1]{\multicolumn{2}{c}{#1}}
\newcommand{\ts}[1]{\textsubscript{#1}}
\newcommand{\edcoh}{\mathrm{ed}_{\mathrm{coh}}}
\newcommand{\cderr}{\mathrm{cd}_{\mathrm{err}}}
\newcommand{\true}{\mathrm{true}}
\setlength{\tabcolsep}{0pt}
\caption{Scenarios results 2 }\label{tab:results}
\begin{tabular*}{\textwidth}{
  @{\extracolsep{\fill}}
  c
  *{3}{ccc}
  @{}
}
\toprule
&
\multicolumn{3}{c}{Anomaly propagation step 1} &
\multicolumn{3}{c}{Anomaly propagation  step 2} &
\multicolumn{3}{c}{Anomaly propagation  step 3} \\

\cmidrule{2-4}
\cmidrule{5-7}
\cmidrule{8-10}

Scenario  
& Detection & Propagation Path & PIS
& Detection & Propagation Path & PIS
& Detection & Propagation Path & PIS
 \\
\midrule
\addlinespace
%Scenario 1
\mr{1} & \begin{tabular}[c]{@{}l@{}}$\edcoh=\true$ \\ $t=\SI{57}{\hour}$\end{tabular} & \begin{tabular}[c]{@{}l@{}}
PU2-T1-PLC2-SCADA \\PU2-T1-PLC2-PLC1-SCADA \\PU2-T1-PLC2-PLC1-PU1-T1 
\\PU2-T1-PLC2-PLC1-PU2\end{tabular}  
& \begin{tabular}[c]{@{}l@{}}
27 \\ 41 \\ 47,75 \\ 41
\end{tabular}

& \begin{tabular}[c]{@{}l@{}}$\edcoh=\true$ \\ $t=\SI{79}{\hour}$\end{tabular} & \begin{tabular}[c]{@{}l@{}}
PU1-T1-PLC2-SCADA \\PU1-T1-PLC2-PLC1-SCADA \\PU1-T1-PLC2-PLC1-PU2-T1 
\\PU1-T1-PLC2-PLC1-PU1  
\end{tabular}  
& \begin{tabular}[c]{@{}l@{}}
27 \\ 41 \\ 47,75 \\ 41
\end{tabular}

& \begin{tabular}[c]{@{}l@{}}$\edcoh=\true$ \\ $t=\SI{79.6}{\hour}$\end{tabular} & \begin{tabular}[c]{@{}l@{}}
T1-PLC2-SCADA \\T1-PLC2-PLC1-SCADA \\T1-PLC2-PLC1-PU1-T1
\\T1-PLC2-PLC1-PU2-T1 
\end{tabular}    
& \begin{tabular}[c]{@{}l@{}}
20,25 \\ 34.25 \\ 41 \\ 41
\end{tabular}   \\
\addlinespace
%Scenario 2
\mr{2} & \begin{tabular}[c]{@{}l@{}}$\edcoh=\true$ \\ $t=\SI{30}{\hour}$\end{tabular} & \begin{tabular}[l]{@{}l@{}}
T7-PLC9-SCADA \\T7-PLC9-PLC5-SCADA \\T7-PLC9-PLC5-PU10-T7 
\\T7-PLC9-PLC5-PU11-T7\end{tabular}  
& \begin{tabular}[c]{@{}l@{}}
20,25 \\ 34,25 \\ 41 \\ 41
\end{tabular}

& n/a 
& n/a
& n/a
& n/a   
& n/a
& n/a \\
\addlinespace
%Scenario 3
\mr{3} & \begin{tabular}[c]{@{}l@{}}$\edcoh=\true$ \\ $t=\SI{3,9}{\hour}$\end{tabular} & \begin{tabular}[c]{@{}l@{}}
PU2-T1-PLC2-SCADA \\PU2-T1-PLC2-PLC1-SCADA \\PU2-T1-PLC2-PLC1-PU1-T1 
\\PU2-T1-PLC2-PLC1-PU2\end{tabular}  
& \begin{tabular}[c]{@{}l@{}}
27 \\ 41 \\ 47,75 \\ 41
\end{tabular}

& \begin{tabular}[c]{@{}l@{}}$\edcoh=\true$ \\ $t=\SI{11,3}{\hour}$\end{tabular} & \begin{tabular}[c]{@{}l@{}}
PU2-T1-PLC2-SCADA \\PU2-T1-PLC2-PLC1-SCADA \\PU2-T1-PLC2-PLC1-PU1-T1 
\\PU2-T1-PLC2-PLC1-PU2  
\end{tabular}  
& \begin{tabular}[c]{@{}l@{}}
27 \\ 41 \\ 47,75 \\ 41
\end{tabular}

& \begin{tabular}[c]{@{}l@{}}$\edcoh=\true$ \\ $t=\SI{13,7}{\hour}$\end{tabular} & \begin{tabular}[c]{@{}l@{}}
PU2-T1-PLC2-SCADA \\PU2-T1-PLC2-PLC1-SCADA \\PU2-T1-PLC2-PLC1-PU1-T1 
\\PU2-T1-PLC2-PLC1-PU2  
\end{tabular}    
& \begin{tabular}[c]{@{}l@{}}
27 \\ 41 \\ 47,75 \\ 41
\end{tabular}   \\

\midrule[\heavyrulewidth]
\multicolumn{8}{l}{PIS: Propagation Impact Score}
\end{tabular*}
\end{table*}


\end{document}

\begin{tabular}[c]{@{}l@{}}我使用的是单元格中的表格,而不是多行。尽管使用了或,我还是无法将它们置于中央或左中央\begin{tabular}[l]{@{}l@{}}。我尝试更改列类型,但似乎没有任何改变。我想将每个“检测”列置于中央,并将每个“传播路径”列置于左中央。

得到的结果如下: 在此处输入图片描述 如您所见,“检测”列未居中,并且第二行的第三个单元格未居左居中。

感谢您的帮助。

[编辑]

感谢@Simon Dispa,我将所需的列居中。我还修改了代码以对齐每个“传播路径”列的文本。我使用了\begin{tabular}{|L{34mm}|} T7-PLC9-SCADA \\T7-PLC9-PLC5-SCADA \\T7-PLC9-PLC5-PU10-T7 \\T7-PLC9-PLC5-PU11-T7\end{tabular}

\newcolumntype{L}[1]{>{\RaggedRight\hspace{0pt}}p{#1}} 在此处输入图片描述

答案1

但是你的代码生成了居中的列!它们可能很紧凑,但却居中。

我添加了垂直线以便更好地进行可视化。它还将底部行(PIS 列)的最后一个单元格居中。我认为这样看起来更好。同样的方法可以应用于检测列中的单元格。

b

        & \begin{tabular}[c]{@{}c@{}} % <<<< changed
            27 \\ 41 \\ 47,75 \\ 41
        \end{tabular} 

为了对齐较短的(示例中为两个),可以使用\multicolumn{1}{l}{...}

        & \begin{tabular}[c]{@{}l@{}}$\edcoh=\true$ \\ $t=\SI{79.6}{\hour}$\end{tabular} & \multicolumn{1}{l}{\begin{tabular}{@{}l@{}} %<<<<<<<<<<<<<<< changed
            T1-PLC2-SCADA \\T1-PLC2-PLC1-SCADA \\T1-PLC2-PLC1-PU1-T1
            \\T1-PLC2-PLC1-PU2-T1 
        \end{tabular}}

居中DetectionPIS单元格,左对齐两个Propagation Path 单元格。 d

这是最终的代码。

\documentclass[10pt,conference]{IEEEtran}
\usepackage{pgfplots}
\usepackage{tikz}        
\pgfplotsset{compat=newest}
\usepackage{cite}
\usepackage{newtxtext,newtxmath}
\usepackage{booktabs,siunitx}
\usepackage{multirow}
\usepackage{amsmath,amsfonts}
\usepackage{algorithmic}
\usepackage{graphicx}
\usepackage{pifont}
\usepackage{textcomp}
\usepackage{tabularx,ragged2e,bm,newtxmath} % new packages
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepackage{xcolor}
\usepackage{array}

\begin{document}
    \begin{table*}[bt]
        \newcommand{\mr}[1]{\multirow{2}{*}{#1}}
        \newcommand{\mc}[1]{\multicolumn{2}{c}{#1}}
        \newcommand{\ts}[1]{\textsubscript{#1}}
        \newcommand{\edcoh}{\mathrm{ed}_{\mathrm{coh}}}
        \newcommand{\cderr}{\mathrm{cd}_{\mathrm{err}}}
        \newcommand{\true}{\mathrm{true}}
        \setlength{\tabcolsep}{0pt}
        \caption{Scenarios results 2 }\label{tab:results}
    
        \begin{tabular*}{\textwidth}{
                @{\extracolsep{\fill}}
                c
                *{3}{ccc}
                @{}
            }
            \toprule
            &
            \multicolumn{3}{c}{Anomaly propagation step 1} &
            \multicolumn{3}{c}{Anomaly propagation  step 2} &
            \multicolumn{3}{c}{Anomaly propagation  step 3} \\
            
            \cmidrule{2-4}
            \cmidrule{5-7}
            \cmidrule{8-10}
            
            Scenario  
            & Detection & Propagation Path & PIS
            & Detection & Propagation Path & PIS
            & Detection & Propagation Path & PIS
            \\
            \midrule
            \addlinespace
            %Scenario 1
            \mr{1} & \begin{tabular}[c]{@{}c@{}}$\edcoh=\true$ \\ $t=\SI{57}{\hour}$\end{tabular} & \begin{tabular}[c]{@{}l@{}}
                PU2-T1-PLC2-SCADA \\PU2-T1-PLC2-PLC1-SCADA \\PU2-T1-PLC2-PLC1-PU1-T1 
                \\PU2-T1-PLC2-PLC1-PU2\end{tabular}  
            & \begin{tabular}[c]{@{}c@{}}
                27 \\ 41 \\ 47,75 \\ 41
            \end{tabular}
            
            & \begin{tabular}[c]{@{}c@{}}$\edcoh=\true$ \\ $t=\SI{79}{\hour}$\end{tabular} & \begin{tabular}[c]{@{}l@{}}
                PU1-T1-PLC2-SCADA \\PU1-T1-PLC2-PLC1-SCADA \\PU1-T1-PLC2-PLC1-PU2-T1 
                \\PU1-T1-PLC2-PLC1-PU1  
            \end{tabular}  
            & \begin{tabular}[c]{@{}c@{}}
                27 \\ 41 \\ 47,75 \\ 41
            \end{tabular}
            
            & \begin{tabular}[c]{@{}c@{}}$\edcoh=\true$ \\ $t=\SI{79.6}{\hour}$\end{tabular} & \multicolumn{1}{l}{\begin{tabular}{@{}l@{}} %<<<<<<<<<<<<<<< changed
                T1-PLC2-SCADA \\T1-PLC2-PLC1-SCADA \\T1-PLC2-PLC1-PU1-T1
                \\T1-PLC2-PLC1-PU2-T1 
            \end{tabular} }   
            & \begin{tabular}[c]{@{}c@{}}
                20,25 \\ 34.25 \\ 41 \\ 41
            \end{tabular}   \\
            \addlinespace
            %Scenario 2
            \mr{2} & \begin{tabular}[c]{@{}c@{}}$\edcoh=\true$ \\ $t=\SI{30}{\hour}$\end{tabular} & \multicolumn{1}{l}{\begin{tabular}[l]{@{}l@{}}
                T7-PLC9-SCADA \\T7-PLC9-PLC5-SCADA \\T7-PLC9-PLC5-PU10-T7 
                \\T7-PLC9-PLC5-PU11-T7\end{tabular}} 
            & \begin{tabular}[c]{@{}c@{}}
                20,25 \\ 34,25 \\ 41 \\ 41
            \end{tabular}
            
            & n/a 
            & n/a
            & n/a
            & n/a   
            & n/a
            & n/a \\
            \addlinespace
            %Scenario 3
            \mr{3} & \begin{tabular}[c]{@{}c@{}}$\edcoh=\true$ \\ $t=\SI{3,9}{\hour}$\end{tabular} & \begin{tabular}[c]{@{}l@{}}
                PU2-T1-PLC2-SCADA \\PU2-T1-PLC2-PLC1-SCADA \\PU2-T1-PLC2-PLC1-PU1-T1 
                \\PU2-T1-PLC2-PLC1-PU2\end{tabular}  
            & \begin{tabular}[c]{@{}c@{}}
                27 \\ 41 \\ 47,75 \\ 41
            \end{tabular}
            
            & \begin{tabular}[c]{@{}c@{}}$\edcoh=\true$ \\ $t=\SI{11,3}{\hour}$\end{tabular} & \begin{tabular}[c]{@{}l@{}}
                PU2-T1-PLC2-SCADA \\PU2-T1-PLC2-PLC1-SCADA \\PU2-T1-PLC2-PLC1-PU1-T1 
                \\PU2-T1-PLC2-PLC1-PU2  
            \end{tabular}  
            & \begin{tabular}[c]{@{}c@{}}
                27 \\ 41 \\ 47,75 \\ 41
            \end{tabular}
            
            & \begin{tabular}[c]{@{}c@{}}$\edcoh=\true$ \\ $t=\SI{13,7}{\hour}$\end{tabular} & \begin{tabular}[c]{@{}l@{}}
                PU2-T1-PLC2-SCADA \\PU2-T1-PLC2-PLC1-SCADA \\PU2-T1-PLC2-PLC1-PU1-T1 
                \\PU2-T1-PLC2-PLC1-PU2  
            \end{tabular}    
            & \begin{tabular}[c]{@{}c@{}} % <<<< changed
                27 \\ 41 \\ 47,75 \\ 41
            \end{tabular}   \\
            
            \midrule[\heavyrulewidth]
            \multicolumn{8}{l}{PIS: Propagation Impact Score}
        \end{tabular*}
    \end{table*}        
    
\end{document}

相关内容