多列和多行表格(缺少分隔符)

多列和多行表格(缺少分隔符)

我确实知道表格中的垂直分隔符不是最佳做法,但在极少数情况下我需要它们。

从下面的代码中可以看出,单元格“Switch fcsw1”和“Switch fcsw1”之间的分隔符丢失了。这是怎么回事?

\documentclass[a4paper,10pt]{article}

\usepackage{ucs}
\usepackage[utf8]{inputenc}
\usepackage[ukrainian]{babel}
\usepackage[T1,T2A]{fontenc}
\usepackage{multirow, booktabs, array, adjustbox}

\renewcommand{\arraystretch}{1.3}

\begin{document}
 \section{Multicolumn and multorow table}
 \begin{table}[h]
    \centering
    \begin{adjustbox}{width=1\textwidth}
    \begin{tabular}{l|l|l|l|l} \toprule
        \multirow{3}{*}{\textbf{Device}} & \multicolumn{4}{l}{\textbf{Alias}} \\ \cline{2-5}
        & \multicolumn{2}{l}{\textbf{Switch fcsw1}} & \multicolumn{2}{l}{\textbf{Switch fcsw2}} \\ \cline{2-5}
        & \textbf{name} & \textbf{WWN} & \textbf{name} & \textbf{WWN} \\ \midrule
        \multirow{2}{*}{Big Device 1} & DevA01\textunderscore A & 50:00:00:00:00:00:00:00 & aDevA01\textunderscore A & 50:00:00:00:00:00:00:00  \\
        & DevA01\textunderscore B & 50:00:00:00:00:00:00:00 & aDevA01\textunderscore B & 50:00:00:00:00:00:00:00 \\ \midrule
        \multirow{2}{*}{Big Device 2} & DevA02\textunderscore A & 50:00:00:00:00:00:00:00 & aDevA02\textunderscore A & 50:00:00:00:00:00:00:00 \\
        & DevA02\textunderscore B & 50:00:00:00:00:00:00:00 & aDevA02\textunderscore B & 50:00:00:00:00:00:00:00 \\ \midrule
        Small Device 3 & 50:00:00:00:00:00:00:00 & aKYVDC01BAK26 & 50:00:00:00:00:00:00:00 \\
        Small Device 4 & aDevX01 & 50:00:00:00:00:00:00:00 & aDevX01 & 50:00:00:00:00:00:00:00 \\
        Small Device 5 & aDevX02 & 50:00:00:00:00:00:00:00 & aDevX02 & 50:00:00:00:00:00:00:00 \\ \bottomrule
        \end{tabular}
    \end{adjustbox}
    \caption{MRMC Table}
    \label{table:1}
\end{table}
\end{document}

结果: 在此处输入图片描述

答案1

带有垂直线...

相反\multicolumn{2}{c}{\textbf{Switch fcsw1}}你应该写\multicolumn{2}{c|}{\textbf{Switch fcsw1}}(观察|列类型后c):

在此处输入图片描述

\documentclass{article}
\usepackage{geometry}
\usepackage[utf8]{inputenc}
%\usepackage[T1,T2A]{fontenc}
\usepackage{booktabs, makecell, multirow}
\setcellgapes{5pt}

\begin{document}
 \section{Multicolumn and multorow table}
    \begin{table}[h]
    \centering
    \makegapedcells
    \scriptsize
 \begin{tabular*}{\linewidth}{l|l| l|l| l}
    \hline
    & \multicolumn{4}{c}{\textbf{Alias}}        \\
    \cline{2-5}
Device
    & \multicolumn{2}{c|}{\textbf{Switch fcsw1}} & \multicolumn{2}{c}{\textbf{Switch fcsw2}} \\
    \cline{2-5}
        & \textbf{name} & \textbf{WWN} & \textbf{name} & \textbf{WWN} \\
    \hline
\multirow{2}{*}{Big Device 1}
    & DevA01\textunderscore A & 50:00:00:00:00:00:00:00 & aDevA01\textunderscore A & 50:00:00:00:00:00:00:00  \\
    & DevA01\textunderscore B & 50:00:00:00:00:00:00:00 & aDevA01\textunderscore B & 50:00:00:00:00:00:00:00 \\ \hline
\multirow{2}{*}{Big Device 2}
    & DevA02\textunderscore A & 50:00:00:00:00:00:00:00 & aDevA02\textunderscore A & 50:00:00:00:00:00:00:00 \\
    & DevA02\textunderscore B & 50:00:00:00:00:00:00:00 & aDevA02\textunderscore B & 50:00:00:00:00:00:00:00 \\ \hline
    Small Device 3 & 50:00:00:00:00:00:00:00 & aKYVDC01BAK26 & 50:00:00:00:00:00:00:00 \\
    Small Device 4 & aDevX01 & 50:00:00:00:00:00:00:00 & aDevX01 & 50:00:00:00:00:00:00:00 \\
    Small Device 5 & aDevX02 & 50:00:00:00:00:00:00:00 & aDevX02 & 50:00:00:00:00:00:00:00 \\
    \hline
        \end{tabular*}
    \caption{MRMC Table}
    \label{table:1}

包中的表格规则bookmarks被替换为\hline。垂直间距使用makegapedcells包中的宏makecell。垂直间距量由确定\setcellgapes{5pt}

答案2

命令\toprule\midrule\bottomrule设计目的不是与垂直规则一起工作。

只需移除它们或者改用\hline即可。

这是一个不同的渲染(没有用到\multirow)。

\documentclass[a4paper,10pt]{article}

\usepackage{booktabs}

\begin{document}

\begin{table}[htp]
\centering
\scriptsize

\addtolength{\tabcolsep}{-2.2pt}
\begin{tabular}{@{}lllll@{}}
\toprule
\textbf{Device} & \multicolumn{4}{c}{\textbf{Alias}} \\
\cmidrule{2-5}
& \multicolumn{2}{c}{\textbf{Switch fcsw1}}
& \multicolumn{2}{c}{\textbf{Switch fcsw2}} \\
\cmidrule(lr){2-3}\cmidrule(lr){4-5}
& \multicolumn{1}{c}{\textbf{name}}
& \multicolumn{1}{c}{\textbf{WWN}}
& \multicolumn{1}{c}{\textbf{name}}
& \multicolumn{1}{c@{}}{\textbf{WWN}} \\
\midrule
Big Device 1 & DevA01\_A & 50:00:00:00:00:00:00:00 & aDevA01\_A & 50:00:00:00:00:00:00:00  \\
             & DevA01\_B & 50:00:00:00:00:00:00:00 & aDevA01\_B & 50:00:00:00:00:00:00:00 \\
\midrule
Big Device 2 & DevA02\_A & 50:00:00:00:00:00:00:00 & aDevA02\_A & 50:00:00:00:00:00:00:00 \\
             & DevA02\_B & 50:00:00:00:00:00:00:00 & aDevA02\_B & 50:00:00:00:00:00:00:00 \\
\midrule
Small Device 3 & & 50:00:00:00:00:00:00:00 & aKYVDC01BAK26 & 50:00:00:00:00:00:00:00 \\
Small Device 4 & aDevX01 & 50:00:00:00:00:00:00:00 & aDevX01 & 50:00:00:00:00:00:00:00 \\
Small Device 5 & aDevX02 & 50:00:00:00:00:00:00:00 & aDevX02 & 50:00:00:00:00:00:00:00 \\ \bottomrule
\end{tabular}

\caption{MRMC Table}\label{table:1}

\end{table}

\end{document}

在此处输入图片描述

答案3

另一个选择是使用 tabu 包,它具有更清晰的代码和许多选项,在这种环境下,当确定线条的样式时,会出现不连续线条的错误,但可以通过在线中包含一个间隙来解决,\\[-xpt]其中x是线条的粗细。

\documentclass[a4paper,10pt]{article}
\usepackage{ucs}
\usepackage[utf8]{inputenc}
\usepackage[ukrainian]{babel}
\usepackage[T1,T2A]{fontenc}
\usepackage{tabu} % Use tabu for nice tables 
\usepackage{multirow, booktabs, array,adjustbox}

\renewcommand{\arraystretch}{1.3}

\begin{document}
    \section{Multicolumn and multorow table}
    \begin{table}[h]

            \begin{adjustbox}{width=1\linewidth}
                \tabulinesep = 2mm
                \tabulinestyle{1pt} % Line style thickness 1pt.
                \centering
            \begin{tabu} to 19.5cm {|X|X|X|X|X|} \tabucline - % to 19.5cm length for the text to fit in the cells
                \multirow{3}{*}{\bf Device} & \multicolumn{4}{l|}{\bf Alias} \\[-1pt] \tabucline{2-5}
                    & \multicolumn{2}{l|}{\bf Switch fcsw1} 
                    & \multicolumn{2}{l|}{\bf Switch fcsw2} \\[-1pt] \tabucline{2-5} % "\\[-1pt]" trick to correct

                    & \bf name 
                    & \bf WWN 
                    & \bf name 
                    & \bf WWN \\ \tabucline -

                \multirow{2}{*}{Big Device 1} 
                    & DevA01\textunderscore A 
                    & 50:00:00:00:00:00:00:00 
                    & aDevA01\textunderscore A 
                    & 50:00:00:00:00:00:00:00  \\ 

                    & DevA01\textunderscore B 
                    & 50:00:00:00:00:00:00:00 
                    & aDevA01\textunderscore B 
                    & 50:00:00:00:00:00:00:00 \\[-1pt] \tabucline{2-5}

                \multirow{2}{*}{Big Device 2} 
                    & DevA02\textunderscore A 
                    & 50:00:00:00:00:00:00:00 
                    & aDevA02\textunderscore A 
                    & 50:00:00:00:00:00:00:00 \\ 

                    & DevA02\textunderscore B 
                    & 50:00:00:00:00:00:00:00 
                    & aDevA02\textunderscore B 
                    & 50:00:00:00:00:00:00:00 \\ \tabucline -

                Small Device 3 & 50:00:00:00:00:00:00:00 & aKYVDC01BAK26 & 50:00:00:00:00:00:00:00 & \\ \tabucline -
                Small Device 4 & aDevX01 & 50:00:00:00:00:00:00:00 & aDevX01 & 50:00:00:00:00:00:00:00 \\ \tabucline -
                Small Device 5 & aDevX02 & 50:00:00:00:00:00:00:00 & aDevX02 & 50:00:00:00:00:00:00:00 \\ \tabucline -
            \end{tabu}
        \end{adjustbox}
        \caption{MRMC Table}
        \label{table:1}
    \end{table}
\end{document}

结果如下。

在此处输入图片描述

相关内容