# How to get symbols on the lines of a table

I want to generate a table like this with latex. Can you help? I can write a normal table as below, but have no idea how to create those symbols on the lines.

\begin{table}[htbp]
\centering
\begin{tabular}{|l|l|l|}
\toprule
& Scenario 1 & Scenario 2 \\
\midrule
Val 1 & x     & y \\
\midrule
Val 2 & x     & Z \\
\bottomrule
\end{tabular}%
\end{table}%


This is a solution using tikz

\documentclass[tikz, border = 5pt]{standalone}

\usetikzlibrary{matrix}
\usetikzlibrary{calc}

\tikzset{
table/.style={
matrix of nodes,
row sep=-\pgflinewidth,
column sep=-\pgflinewidth,
nodes={
rectangle,
draw,
text width=6em,
align=center
},
minimum height=1.2cm,
text depth=0.5ex,
text height=2ex,
nodes in empty cells,
row 1/.style={
minimum height=0.5cm,
},
column 1/.style={
nodes={
text width=3em
}
}
},
circ/.style={
draw=green,
circle,
fill=white,
thick,
minimum width=0.8cm
}
}

\begin{document}
\begin{tikzpicture}
\matrix (table) [ampersand replacement=\&, table]
{
\& Scenario 1 \& Scenario 2 \\
Val 1 \& $\alpha + \beta^2$ \& $\gamma + \beta\delta^2$ \\
Val 2 \& $\alpha + \beta^2$ \& $\alpha + \beta^2$ \\
};

\node[circ] (less) at ($(table-2-2)!0.5!(table-2-3)$){$<$};
\node[circ] (equals) at ($(table-2-2)!0.5!(table-3-2)$){$=$};
\node[circ] (question) at ($(table-3-2)!0.5!(table-3-3)$){$?$};
\node[circ, rotate = -90] (greater) at ($(table-2-3)!0.5!(table-3-3)$){$>$};

\end{tikzpicture}
\end{document}


• Thank you so much. I was wondering if the cells can be of different sizes? column headers and row headers are of different size compared to value cells in the table. Jan 1, 2019 at 14:19
• @mucalinda Sure, how about now? Jan 1, 2019 at 14:37

A pstricks solution. Note you shouldn't use the rules from booktabs with vertical rules, as they do not intersect. I replaced them with \Xhlines from makecell, thereof thickness has to be specified:

\documentclass[svgnames]{article}
\usepackage{booktabs}
\usepackage{makecell, caption}
\usepackage{pst-node}

\begin{document}

\begin{table}[htbp]
\centering
\setlength{\tabcolsep}{8pt}
\setcellgapes{9pt}\makegapedcells
\begin{tabular}{!{\vline width 1pt}l|l|l!{\vline width 1pt}}
\Xhline{1pt}
& Scenario 1 & Scenario 2 \\
\Xhline{0.5pt}
Val 1 & \Rnode{S1t}{$\alpha + \beta^2$} & \Rnode{S2t}{~$\gamma + \beta\delta^2$} \\
\Xhline{0.5pt}
Val 2 & \Rnode{S1b}{$\alpha + \beta^2$ }& \Rnode{S2b}{~$\alpha + \beta^2$} \\
\Xhline{1pt}
\end{tabular}%
\psset{linecolor=YellowGreen, fillstyle=solid, fillcolor=White,}
\nput[labelsep=1.5em]{0}{S1t}{\pscirclebox{$<$}}
\nput[labelsep=1.25em]{0}{S1b}{\pscirclebox{?}}
\nput[labelsep=0.1ex]{105}{S1b}{\pscirclebox{$=$}}
\nput[labelsep=0.05ex, rot=-90]{90}{S2b}{\pscirclebox{$>$}}
\end{table}%

\end{document}


This answer is an attempt to combine the advantages of the existing nice answers by Bernard and by caverac. What I like about Bernard's nice answer is that you can use the ordinary LaTeX tables with all their powerful methods to align things and so on. (Note, however, that I center the lower right entries as in your screen shot.) The IMHO big advantage of caverac's nice answer is that you are not restricted in your choice of your compiler, because it is based on TikZ, and that there are no hard-coded dimensions. (I am using midway instead of the calc syntax, not because I consider it "better" but just to show an alternative.) To this end I use the tikzmark library to arrive at something which might be called a TikZy version of Bernard's proposal (which most of the code is borrowed from)

\documentclass[svgnames]{article}
\usepackage{booktabs}
\usepackage{makecell, caption}
\usepackage{tikz}
\usetikzlibrary{tikzmark}

\begin{document}

\begin{table}[htbp]
\centering
\setlength{\tabcolsep}{8pt}
\setcellgapes{9pt}\makegapedcells
\begin{tabular}{!{\vline width 1pt}l|c|c!{\vline width 1pt}}
\Xhline{1pt}
& \multicolumn{1}{l|}{Scenario 1} &\multicolumn{1}{l!{\vline width 1pt}}{Scenario 2} \\
\Xhline{0.5pt}
Val 1 & \tikzmarknode{S1t}{$\alpha + \beta^2$} & \tikzmarknode{S2t}{$\gamma + \beta\,\delta^2$} \\
\Xhline{0.5pt}
Val 2 & \tikzmarknode{S1b}{$\alpha + \beta^2$ }& \tikzmarknode{S2b}{$\alpha + \beta^2$} \\
\Xhline{1pt}
\end{tabular}%
\path (S1t.east) -- (S2t.west) node[gc] {$<$};
\path (S1t.south) -- (S1b.north) node[gc] {$=$};
\path (S2t.south) -- (S2b.north) node[gc,rotate=90] {$<$};