# Highlighting of words in table header displaces non-highlighted words

I have a quite simple table (even more reduced for minimum example) with some highlighting. By using \colorbox and \tikz\node (with and without inner sep argument) I create boxes around text, but the line height differs for each of the options. Even when using, e.g., only \tikz\node with fixed inner sep, highlighting positions text ... wrong. Is there a way to highlight certain words without displacing all the word heights in a line?

Edit: Thank you Paul Stanley, your description is precise to the point that I understand both tikz and colorbox. Below is now the "easy" solution that works for me.

\documentclass[12pt]{article}
\usepackage{subcaption}
\usepackage{booktabs}
\usepackage{tikz}
\usetikzlibrary{arrows, backgrounds, positioning}
\usepackage{xcolor}

\begin{document}
\newcommand{\highlighted}[1]{\colorbox{orange!35}{\strut#1}}
\newcommand{\highlightRed}[1]{\colorbox{red!20}{\strut#1}}

\tikzset{every picture/.style={remember picture}}
\begin{table*}[b!]
\caption{Example challenges data integration with missing,
\colorbox{red!20}{wrong or misspelled} values or
\colorbox{orange!35}{semantic ambiguities}.}

\begin{subtable}[t]{\textwidth}\centering
\captionsetup{justification=centering,singlelinecheck=false}
\caption{Example person entities in source A.}
\begin{tabular}{lllll}
\toprule
ID & \highlighted{name} & \highlighted{surname} & \highlighted{birthPlace} & type \\
\midrule
\tikz\node[inner sep=.4pt, anchor=base] (a1) {A1}; & GottfriedWilhelm & Leibniz & Leipzig (Germany) & \highlighted{person} \\
\multicolumn{5}{c}{\ldots}\\
\bottomrule
\end{tabular}
\end{subtable}

\vspace{0.6cm}
\begin{subtable}[t]{\textwidth}\centering
\captionsetup{justification=centering,singlelinecheck=false}
\caption{Example person entities in source B.}
\begin{tabular}{llll}
\toprule
ID & \highlighted{label} & \highlighted{place\_of\_birth} & type \\
\midrule
\tikz[baseline]\node[anchor=base,inner sep=.4pt] (b0) {B0}; & Gottfried \highlightRed{W. Leibn\"utz} & \highlightRed{Stagira (Greece)} & \highlighted{philosopher} \\
\multicolumn{4}{c}{\ldots}\\
\bottomrule
\end{tabular}
\end{subtable}
\end{table*}

\begin{tikzpicture}[overlay, remember picture]
\path[thick, <->, >=latex, black] (a1) edge [bend right = 85, left] node
[above, text width=3.5cm, rotate=90] {\small{equivalence relation}} (b0);
\end{tikzpicture}

\end{document}


Edit: added complete code example, still working on the picture

• You need to supply code for a fully compilable example, an MWE. – Sveinung Oct 29 '19 at 18:25
• If all the table entries are tikz nodes, why don't you just use a tikz matrix of nodes? You can still achieve the left alignment with eqparbox. – Schrödinger's cat Oct 29 '19 at 18:30
• @Sveinung thx, I added the full example. Is the picture automatically created via imgur.com or is there a manual process included? – Markus Nentwig Oct 29 '19 at 20:57
• @Markus: No picture is created, or needed — the code itself is what’s useful to have, since it enables a reader/answerer to experiment with, modify, and expand on your setup. – Peter LeFanu Lumsdaine Oct 30 '19 at 14:00

I think you are being bitten by two things: problems positioning the baselines and anchors in tikz, and the fact that the "separation", whether of the colorbox or the tikz node, is dependent on the actual contents of the box, and "surname" (which is a succession of letters at x-height, doesn't look the same as "Birthplace" (which has three letters which go above x-height, or "golly" (which as three which go below x height).

You can see the point in this graphic, each of which is just a \colorbox. You get the same problem with tikz, which also seems to calculate its separation from the bounding boxes of the characters.

The simplest way to deal with this is to put a phantom and standardly sized character into the box. So with \colorbox{orange!35}{\strut xxxxxx} (etc) one gets.

Though there are no doubt other ways (e.g. to draw tikz rectangles and then add text.

For the tikz versions, you also want to set the baseline (\tikz[baseline]\node...) and probably to use base as the anchor, I think. For my own part, I wouldn't mix the colorbox and tikz methods, and would be inclined to think that colorbox is the easier option just for highlighting. Something like

\newcommand{\highlighted}[1]{\colorbox{orange!35}{\strut#1}}


may help.