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.

\usetikzlibrary{arrows, backgrounds, positioning}


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

    \caption{Example person entities in source A.}
        ID & \highlighted{name} & \highlighted{surname} & \highlighted{birthPlace} & type \\
        \tikz\node[inner sep=.4pt, anchor=base] (a1) {A1}; & GottfriedWilhelm & Leibniz & Leipzig (Germany) & \highlighted{person} \\ 

    \caption{Example person entities in source B.}
        ID & \highlighted{label} & \highlighted{place\_of\_birth} & type \\
        \tikz[baseline]\node[anchor=base,inner sep=.4pt] (b0) {B0}; & Gottfried \highlightRed{W. Leibn\"utz} & \highlightRed{Stagira (Greece)} & \highlighted{philosopher} \\

\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);


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

  • 4
    You need to supply code for a fully compilable example, an MWE.
    – Sveinung
    Oct 29, 2019 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.
    – user194703
    Oct 29, 2019 at 18:30
  • 1
    @Sveinung thx, I added the full example. Is the picture automatically created via imgur.com or is there a manual process included? Oct 29, 2019 at 20:57
  • 1
    @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. Oct 30, 2019 at 14:00

1 Answer 1


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.

enter image description here

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.

enter image description here

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


may help.

You must log in to answer this question.

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