0

I'm trying to create a table where part of the table is highlighted with thick lines surrounding it. enter image description here

Using tabular and variants of \cline, I can create partial horizontal lines. However, I have not found any method for creating partial vertical lines. Any suggestions?

2

2 Answers 2

1

Inspired by my answer to a previous question:

enter image description here

\documentclass{article}
\usepackage{array}

\newlength{\defaultarrayrulewidth}
\newcommand{\Cline}[2]{%
  \noalign{\global\setlength{\defaultarrayrulewidth}{\arrayrulewidth}}%
  \noalign{\global\setlength{\arrayrulewidth}{#1}}\cline{#2}%
  \noalign{\global\setlength{\arrayrulewidth}{\defaultarrayrulewidth}}}


\begin{document}

\begin{tabular}{|c|c|c|c|c|}
\hline
A1 & A2 & A3& A4&  A5 \\
\cline{1-1} \Cline{1pt}{2-3} \cline{4-5}
 B1 & \multicolumn{1}{!{\vrule width 1pt}c|}{B2}& \multicolumn{1}{c!{\vrule width 1pt}}{B3}&  B4 & B5 \\
\hline
C1 & \multicolumn{1}{!{\vrule width 1pt}c|}{C2} & \multicolumn{1}{c!{\vrule width 1pt}}{C3}&  C4 & C5\\
\cline{1-1} \Cline{1pt}{2-3} \cline{4-5}
D1 & D2 & D3& D4&  D5\\
\hline
\end{tabular}

\end{document}
1

With {NiceTabular} of nicematrix, you only have to use the command \Block (provided by nicematrix).

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

\begin{NiceTabular}{ccccc}[hvlines]
A1 & A2 & A3 & A4 & A5 \\
B1 & \Block[draw,line-width=1pt,transparent]{2-2}{}
     B2 & B3 & B4 & B5 \\
C1 & C2 & C3 & C4 & C5 \\
D1 & D2 & D3 & D4 & D5 \\ 
\end{NiceTabular}

\end{document}

The key transparent of the command \Block means that it is "transparent" to the vertical and horizontal rules created by the key hvlines of {NiceTabular}.

Output of the above code

If you don't want instructions in the main array, you can draw the bold frame with TikZ in the so-called \CodeAfter by using the PGF/TikZ nodes creates by nicematrix.

\documentclass{article}
\usepackage{nicematrix,tikz}

\begin{document}

\begin{NiceTabular}{ccccc}[hvlines]
  A1 & A2 & A3 & A4 & A5 \\
  B1 & B2 & B3 & B4 & B5 \\
  C1 & C2 & C3 & C4 & C5 \\
  D1 & D2 & D3 & D4 & D5 \\ 
\CodeAfter
  \tikz \draw [line width = 1pt] (2-|2) rectangle (4-|4) ; 
\end{NiceTabular}

\end{document}

The output is the same.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .