I want to draw with tikz the following:
That is,
abc,
then def
in green AND surrounded by a red rectangle, and then a ,
.
What I have now is three different nodes. But they are not aligned to one another, and the distances between them are rather chosen for arbitrary distances by me, which is not systematic; If I change the font and font size, the distances may need to be amended.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\node at (0,0) (A) {abc,};
\node[draw,color=red,right = 1ex of A] (B) {\textcolor{blue}{def}};
\node[right = 1ex of B] (C) {,};
\end{tikzpicture}
\end{document}
anchor=base
or similar things.\fbox
. For a more general approach, the subnode fromtikzmark
. Or separate nodes with one node fitted around it so that you can reference all under one name (and connect lines to it). Why do you need it to be one node?width(" ") of A
could be used to get the width of a space. (or you just put a literal space\
as part of the nodes and choose no space between the nodes.base right=of …
could help with @Symbol1's tip.