Align `\cline` with a double vertical line
Here is a solution with {NiceTabular}
of nicematrix
.
That environment is similar to the classical {tabular}
of array
but creates PGF/Tikz nodes under the cells, rows and columns. Then, you can use Tikz to draw whatever rule you want.
\documentclass{scrbook}
\usepackage{nicematrix,tikz}
\begin{document}
\setlength{\tabcolsep}{2pt}
\begin{NiceTabular}{c||c|c|c||c}[t]
\hline
1&2&3&4&5\\
\hline
&6&7&8&\\
\CodeAfter
\tikz \draw (1-|1) -- (2-|1) ;
\tikz \draw (1-|6) -- (2-|6) ;
\tikz \draw ([xshift=-\doublerulesep-\arrayrulewidth]3-|2) -- (3-|5) ;
\end{NiceTabular}
\end{document}
You need several compilations (because nicematrix
uses PGF/Tikz nodes).
A fast and elegant way with the excellent nicematrix
:
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{nicematrix}
\begin{document}
\setlength{\tabcolsep}{2pt}
\begin{NiceTabular}{*{7}c}[hvlines-except-corners,cell-space-top-limit=3pt]
1 & & 2 & 3 & 4 & & 5 \\
& \makebox[0.1pt]{} & 6 & 7 & 8 & \makebox[0.1pt]{}& \\
\end{NiceTabular}
\end{document}
...you can create a command with the \makebox[0.1pt]{}
You can arrange an empty column so that you can control the \cline
start, or you could use \hhline
but you need a version of b
(denoted .
here) that does not force a double rule width entry into the row.
\documentclass{scrbook}
\usepackage{array}
\usepackage{hhline}
\makeatletter
% add . like b but singleline
\def\HH@loop{%
\ifx\@tempb`\def\next##1{\the\toks@\cr}\else\let\next\HH@let
\ifx\@tempb|\if@tempswa\HH@add{\hskip\doublerulesep}\fi\@tempswatrue
\HH@add{\@tempc\vline\@tempc}\else
\ifx\@tempb:\if@tempswa\HH@add{\hskip\doublerulesep}\fi\@tempswatrue
\HH@add{\@tempc\HH@box\arrayrulewidth\arrayrulewidth\@tempc}\else
\ifx\@tempb##\if@tempswa\HH@add{\hskip\doublerulesep}\fi\@tempswatrue
\HH@add{\@tempc\vline\@tempc\copy\@ne\@tempc\vline\@tempc}\else
\ifx\@tempb~\@tempswafalse
\if@firstamp\@firstampfalse\else\HH@add{&\omit}\fi
\HH@add{\hfil}\else
\ifx\@tempb-\@tempswafalse
\if@firstamp\@firstampfalse\else\HH@add{&\omit}\fi
\HH@add{\leaders\hrule\@height\arrayrulewidth\hfil}\else
\ifx\@tempb=\@tempswafalse
\if@firstamp\@firstampfalse\else\HH@add{&\omit}\fi
\HH@add
{\rlap{\copy\@ne}\leaders\copy\@ne\hfil\llap{\copy\@ne}}\else
\ifx\@tempb t\HH@add{\rlap{\HH@box\doublerulesep\z@}}\else
\ifx\@tempb b\HH@add{\rlap{\HH@box\z@\doublerulesep}}\else
\ifx\@tempb .\HH@add{\smash{\rlap{\HH@box\z@\doublerulesep}}}\else
\ifx\@tempb\@sptoken\let\next\HH@spacelet\else
\PackageWarning{hhline}%
{\meaning\@tempb\space ignored in \noexpand\hhline argument%
\MessageBreak}%
\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
\next}
\makeatother
\begin{document}
\renewcommand{\tabcolsep}{2pt}
\begin{tabular}{|c||c|c|c||c|}
\firsthline
1&2&3&4&5\\\hline
\multicolumn{1}{c||}{}&6&7&8&\multicolumn{1}{c}{}\\
\cline{2-4}
\end{tabular}
\bigskip
\begin{tabular}{|c@{}c@{}||c|c|c||c|}
\firsthline
\multicolumn{1}{|c}{1}&&2&3&4&5\\\hline
\multicolumn{1}{@{}c@{}}{}&&6&7&8&\multicolumn{1}{c}{}\\
\cline{2-5}
\end{tabular}
\bigskip
\begin{tabular}{|c||c|c|c||c|}
\firsthline
1&2&3&4&5\\\hline
\multicolumn{1}{c||}{}&6&7&8&\multicolumn{1}{c}{}\\
\hhline{~|.|---|.|}
\end{tabular}
\end{document}