0

I already asked a question yesterday, hoping to do it by myself but I can't get a good result.

I want to set the vertical and horizontal lines of a single cell in a tabular to a custom thickness. Also the custom thickness lines shall be relatively centered to all normal lines.

This is what I am using right now:

\documentclass{article}
\usepackage[utf8]{inputenc}
\setlength{\doublerulesep}{0pt}
\usepackage{multirow} % Multirows in tabulars
\usepackage{longtable, tabu} % Flexible tabulars i.e. page breaks and horizontal fill
\usepackage{hhline}
\newtabulinestyle{mydashline=on 1.5pt off 2pt}
\tabulinesep=1mm

\begin{document}

\begin{center}
    \begin{tabular}{| >{\centering}m{0.1\textwidth} | >{\centering}m{0.2\textwidth} | >{\centering}m{0.2\textwidth} | >{\centering}m{0.1\textwidth} | >{\centering}m{0.1\textwidth} | >{\centering}m{0.1\textwidth} |}
    \hline
    A & B & C, D & E & F & G \tabularnewline \hline
    0 & 1 & 2 & 3 & 4 & 3 \tabularnewline \hline
    1 & \multicolumn{1}{c||}{3} & \multicolumn{1}{|c|}{3} & 4 & 5 & 3 \tabularnewline \hhline{~~-~~~}\hhline{------}\hhline{~~-~~~}
    2 & 3 & \multicolumn{1}{c||}{4} & \multicolumn{1}{|c|}{5} & 6 & 3 \tabularnewline \hline
    3 & 4 & 5 & 6 & 7 & 3 \tabularnewline \hline
    4 & 5 & 6 & 7 & 8 & 3 \tabularnewline \hline
    5 & 6 & 7 & 8 & 9 & 3 \tabularnewline \hline
    \end{tabular}
\end{center}
\end{document}

But his results in ugly corners. How can I fix it? tabularcorners

  • Welcome to TeX SX! The bold lines should be around which cell? – Bernard Sep 17 '19 at 10:50
  • The bold lines should not be around a cell but like the staircase pattern showed in my question. Here is another image with the line pattern I try to accomplish (the line that seperats human driver and system): http://cyberlaw.stanford.edu/files/blogimages/LevelsofDrivingAutomation.png – Pikkostack Sep 17 '19 at 11:50
  • In case you don't want to redraw your table as shown by Zarko, you might want to use tikzmarknode as shown here: https://tex.stackexchange.com/a/462767/134144 – leandriis Sep 17 '19 at 12:26

3 Answers3

2

Table as matrix in a TikZ picture:

enter image description here

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}

\begin{document}
    \begin{center}
    \begin{tikzpicture}
\matrix (m) [matrix of nodes,
             nodes = {draw, text width=0.1*\textwidth, minimum height=4ex,
                      align=center, anchor=center, outer sep=0pt},
             column sep = -\pgflinewidth,
             row sep    = -\pgflinewidth,
             column 2/.style = {nodes={text width=0.2*\textwidth}},
             column 3/.style = {nodes={text width=0.2*\textwidth}},
             ]
{    
A & B & C, D & E & F & G \\
0 & 1 &  2   & 3 & 4 & 3 \\
1 & 3 &  3   & 4 & 5 & 3 \\
2 & 3 &  4   & 5 & 6 & 3 \\
3 & 4 &  5   & 6 & 7 & 3 \\
4 & 5 &  6   & 7 & 8 & 3 \\
5 & 6 &  7   & 8 & 9 & 3 \\
};
\draw[ultra thick]  
    (m-3-3.north west) |- (m-3-3.south east) -- (m-4-3.south east);
    \end{tikzpicture}
    \end{center}
\end{document}

or you meant the following:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}

\begin{document}
    \begin{center}
    \begin{tikzpicture}
\matrix (m) [matrix of nodes,
             nodes = {draw, text width=0.1*\textwidth, minimum height=4ex,
                      align=center, anchor=center, outer sep=0pt},
             column sep = -\pgflinewidth,
             row sep    = -\pgflinewidth,
             column 2/.style = {nodes={text width=0.2*\textwidth}},
             column 3/.style = {nodes={text width=0.2*\textwidth}},
             ]
{    
A & B & C, D & E & F & G \\
0 & 1 &  2   & 3 & 4 & 3 \\
1 & 3 &  3   & 4 & 5 & 3 \\
2 & 3 &  4   & 5 & 6 & 3 \\
3 & 4 &  5   & 6 & 7 & 3 \\
4 & 5 &  6   & 7 & 8 & 3 \\
5 & 6 &  7   & 8 & 9 & 3 \\
};
\draw[ultra thick]
    (m-3-3.north west) |- (m-3-3.south east) |- cycle;
    \end{tikzpicture}
    \end{center}
\end{document}

enter image description here

Zarko
  • 296,517
  • Thanks for this solution! In fact all three solutions offered work perfectly. I decided to mark Salim Bou's answer since it required the least code changes in my case. But I will definitely keep this method in mind should I face such a problem again. I would have upvoted this answer but sadly I do not have enough reputation for that. – Pikkostack Sep 18 '19 at 15:08
1

The two \hhline{~~-~~~} add space which can be seen between third row and fourth enter image description here

You can remove those two spaces by adding two negative space \noalign{\vskip-0.4pt}

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{multirow} % Multirows in tabulars
\usepackage{longtable, tabu} % Flexible tabulars i.e. page breaks and horizontal fill
\usepackage{hhline}
\newtabulinestyle{mydashline=on 1.5pt off 2pt}
\tabulinesep=1mm
\setlength{\doublerulesep}{0pt}

\begin{document}

\begin{center}
    \begin{tabular}{| >{\centering}m{0.1\textwidth} | >{\centering}m{0.2\textwidth} | >{\centering}m{0.2\textwidth} | >{\centering}m{0.1\textwidth} | >{\centering}m{0.1\textwidth} | >{\centering}m{0.1\textwidth} |}
    \hline
    A & B & C, D & E & F & G \tabularnewline \hline
    0 & 1 & 2 & 3 & 4 & 3 \tabularnewline \hline
    1 & \multicolumn{1}{c||}{3} & \multicolumn{1}{|c|}{3} & 4 & 5 & 3 \tabularnewline
     \noalign{\vskip-0.4pt} % <- add this
     \hhline{~~-~~~}\hhline{------}\hhline{~~-~~~}
     \noalign{\vskip-0.4pt} % and this
    2 & 3 & \multicolumn{1}{c||}{4} & \multicolumn{1}{|c|}{5} & 6 & 3 \tabularnewline \hline
    3 & 4 & 5 & 6 & 7 & 3 \tabularnewline \hline
    4 & 5 & 6 & 7 & 8 & 3 \tabularnewline \hline
    5 & 6 & 7 & 8 & 9 & 3 \tabularnewline \hline
    \end{tabular}
\end{center}
\end{document}
Salim Bou
  • 17,021
  • 2
  • 31
  • 76
1

Another strategy, with pstricks: I insert empty nodes at relevant places in the table \hlines, and connect tjhem with a \pslines. To this aim, I define an \addpnode command with three arguments: the distance from the left side of the table not counting \tabcolseps and the thickness of vertical rules, the number of the column at the end of which the node is inserted, and the name of the node. This command is adapted to columns with prescribed width.

This results in this short code:

\documentclass{article}
\usepackage[utf8]{inputenc}
\setlength{\doublerulesep}{0.8pt}
\usepackage{boldline, makecell}
\usepackage{multirow} % Multirows in tabulars
\usepackage{longtable, tabu} % Flexible tabulars i.e. page breaks and horizontal fill
\usepackage{hhline}
\newtabulinestyle{mydashline=on 1.5pt off 2pt}
\tabulinesep=1mm

\usepackage{pst-node}
\usepackage{auto-pst-pdf}
\newcommand*{\addpnode}[3]{\noalign{\rlap{\pnode[\dimexpr#1+#2\tabcolsep*2+0.5\arrayrulewidth+#2\arrayrulewidth\relax, -0.5\arrayrulewidth]{#3}}}}

\begin{document}


\begin{center}
    \begin{tabular}{| >{\centering}m{0.1\textwidth} | >{\centering}m{0.2\textwidth} | >{\centering}m{0.2\textwidth} | *{3}{>{\centering\arraybackslash}m{0.1\textwidth} |}}
    \hline
    A & B & C, D & E & F & G \\
   \addpnode{0.1\textwidth}{1}{K}
    \hline
    0 & 1 & 2 & 3 & 4 & 3 \\
    \addpnode{0.1\textwidth}{1}{A}\addpnode{0.3\textwidth}{2}{A1}\hline
    1 & 3 & 3 & 4 & 5 & 3 \\
    \addpnode{0.3\textwidth}{2}{B} \addpnode{0.5\textwidth}{3}{B1}\hline
    2 & 3 & 4 & 5 & 6 & 3 \\
    \addpnode{0.5\textwidth}{3}{C}\addpnode{0.6\textwidth}{4}{C1} \hline
    3 & 4 & 5 & 6 & 7 & 3 \\
    \addpnode{0.6\textwidth}{4}{D} \addpnode{0.7\textwidth}{5}{D1}\hline
    4 & 5 & 6 & 7 & 8 & 3 \\
    \addpnode{0.7\textwidth}{5}{E} \addpnode{0.8\textwidth}{6}{E1}\hline
    5 & 6 & 7 & 8 & 9 & 3 \\
    \addpnode{0.8\textwidth}{6}{F}\hline
    \end{tabular}
\psline[linewidth=1.2pt, linecolor=red](A)(A1)(B)(B1)(C)(C1)(D)(D1)(E)(E1)(F)
\end{center}

\end{document}

enter image description here

Bernard
  • 271,350
  • Thanks for this solution! In fact all three solutions offered work perfectly. I decided to mark Salim Bou's answer since it required the least code changes in my case. But I will definitely keep this method in mind should I face such a problem again. I would have upvoted this answer but sadly I do not have enough reputation for that. – Pikkostack Sep 18 '19 at 15:08