3

I do know that vertical separators in the tables are not best practice, but in some rare cases I need them.

As you can see from the code bellow the separator between cells 'Switch fcsw1' and 'Switch fcsw1' is missed. How could it be?

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

The result: enter image description here

leandriis
  • 62,593
gray380
  • 67
  • In tabular, lines end by \ not . Does it help ? – Tarass Apr 10 '18 at 16:53
  • 1
    Don't use vertical rules along with commands from booktabs such as \toprule and \midrule, which are designed not to work with vertical rules. – egreg Apr 10 '18 at 17:39

3 Answers3

2

The commands \toprule, \midrule and \bottomrule are designed not to work along with vertical rules.

Just remove them or use \hline instead.

Here's a different rendering (doesn't use \multirow too).

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

enter image description here

egreg
  • 1,121,712
1

with vertical lines ...

instead \multicolumn{2}{c}{\textbf{Switch fcsw1}} you should write \multicolumn{2}{c|}{\textbf{Switch fcsw1}} (observe | after column type c):

enter image description here

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

in table rules from the package bookmarks are replaced with \hline. for vertical spacing is used macro makegapedcells from the package makecell. amount of vertical space is determined with \setcellgapes{5pt}.

Zarko
  • 296,517
1

Another option is to work with the tabu package, which has a cleaner code and many options, the error of discontinuous lines occurs in this environment when the style of the lines is determined, but it is solved by including a gap in the lines \\[-xpt] where x is the thickness of the lines.

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

Here the result.

enter image description here

J Leon V.
  • 11,533
  • 16
  • 47