2

is there any way to make the following two horizontal lines on the background of a cell? Cell should contain either a blue or green horizontal line in the middle. Or the third option is both.

Here below is a simplified tabular that I would like it applied, but somehow I do not know how to ..

\documentclass[landscape,11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[czech, english]{babel}
%How to make background in tabular cell (vertical lines)?

%USEPACKAGE
\usepackage{tikz}
\usepackage{tcolorbox}
\usepackage{color}
\usepackage{multicol}
\usepackage{multirow}
\usepackage{hhline}

%--------------------
\usepackage{geometry}
\geometry{
    a4paper,
    total={210mm,297mm},
    left=10mm,
    right=10mm,
    top=6mm,
    bottom=2mm,
    bindingoffset=0mm
}

\begin{document}
\pagestyle{empty}
\thispagestyle{empty}
\shorthandoff{-}

\begin{tabular}{|c|c|c|c|}
\hline
\multicolumn{4}{|c|}{Tabular XY} \\
\hline\hline

\multirow{2}{*}{1} & \parbox[c][1cm][c]{2cm}{\centering \scriptsize Lorem ipsum dolor sit amet} & \parbox[c][1cm][c]{1cm}{\centering \scriptsize Lorem ipsum} & Y \\

\hhline{*{1}{|~}*{2}{|-}|-|}

& \parbox[c][1cm][c]{2cm}{\centering \scriptsize Lorem ipsum dolor sit amet} & \parbox[c][1cm][c]{1cm}{\centering \scriptsize Lorem ipsum} & X \\

\hline
\end{tabular}

\end{document}

enter image description here

2 Answers 2

4

enter image description here

\documentclass[landscape,11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[czech, english]{babel}
%How to make background in tabular cell (vertical lines)?

%USEPACKAGE
\usepackage{tikz}
\usepackage{tcolorbox}
\usepackage{color}
\usepackage{multicol}
\usepackage{multirow}
\usepackage{hhline}

%--------------------
\usepackage{geometry}
\geometry{
    a4paper,
    total={210mm,297mm},
    left=10mm,
    right=10mm,
    top=6mm,
    bottom=2mm,
    bindingoffset=0mm
}

\usepackage{colortbl}
\begin{document}
\pagestyle{empty}
\thispagestyle{empty}
\shorthandoff{-}

\newcommand\R[1]{\mbox{}\hspace{\dimexpr#1-2.5pt}\textcolor{red}{\vrule width 5pt}\hspace{\dimexpr-#1-2.5pt}\mbox{}}
\newcommand\G[1]{\mbox{}\hspace{\dimexpr#1-2.5pt}\textcolor{green}{\vrule width 5pt}\hspace{\dimexpr-#1-2.5pt}\mbox{}}
\newcommand\RG[1]{\mbox{}\hspace{\dimexpr#1-7.5pt}\textcolor{red}{\vrule width 5pt}%
                                                 \hspace{5pt}%
                                                 \textcolor{green}{\vrule width 5pt}%
                                                 \hspace{\dimexpr-#1-7.5pt}\mbox{}}
\begin{tabular}{|c|c|c|c|}
\hline
\multicolumn{4}{|c|}{Tabular XY} \\
\hline\hline

\multirow{2}{*}{1} &\R{1cm} \parbox[c][1cm][c]{2cm}{\centering \scriptsize Lorem ipsum dolor sit amet} & \G{.5cm}\parbox[c][1cm][c]{1cm}{\centering \scriptsize Lorem ipsum} & Y \\

\hhline{*{1}{|~}*{2}{|-}|-|}

& \RG{1cm}\parbox[c][1cm][c]{2cm}{\centering \scriptsize Lorem ipsum dolor sit amet} & \parbox[c][1cm][c]{1cm}{\centering \scriptsize Lorem ipsum} & X \\

\hline
\end{tabular}

\end{document}
0

Here is a solution with {NiceTabular} of nicematrix. That environment is similar to the classical environment {tabular} (of array) but creates also PGF/Tikz nodes under the cells, rows and columns.

Then, it's possible, in the \CodeBefore to use those nodes with Tikz to draw whatever rule you want.

\documentclass{article}
\usepackage[table]{xcolor}
\doublerulesepcolor{white}

\usepackage{nicematrix,tikz}
\usetikzlibrary{calc}

\begin{document}


\begin{NiceTabular}{cm[c]{25mm}m[c]{15mm}c}[vlines,cell-space-limits=3pt]
\CodeBefore
  \begin{tikzpicture} [line width = 2mm]
  \draw [green] (2-|2.5) -- (3-|2.5) ; 
  \draw [blue!50] (2-|3.5) -- (3-|3.5) ; 
  % now, the cell with both rules
  \draw [green] ($(3-|2)!0.4!(3-|3)$) -- ($(4-|2)!0.4!(4-|3)$) ;
  \draw [blue!50] ($(3-|2)!0.6!(3-|3)$) -- ($(4-|2)!0.6!(4-|3)$) ;
  \end{tikzpicture}
\Body
  \Hline
  \Block{1-*}{Tabular XY} \\
  \Hline\Hline
  \Block{2-1}{1} & Lorem ipsum dolor sit amet & Lorem ipsum & Y \\
  \Hline
  & Lorem ipsum dolor sit amet & Lorem ipsum & X \\
  \Hline
\end{NiceTabular}

\end{document}

You need several compilations (because of the PGF/Tikz nodes). Output of the above code

You must log in to answer this question.

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