CarLaTeX
Is is possible to do this with TikZ options, without using \makebox[0pt]?


\documentclass{article}
\usepackage{tikz}
\tikzset{
cerchio/.style = {
draw, red, fill=yellow,
circle,
text=black,
text width=10pt,
text centered
},
}
\begin{document}
\begin{tikzpicture}
\node[cerchio]{\makebox[0pt]{a long node}};
\end{tikzpicture}
\end{document}


![image.png](/image?hash=ff9d19777165c627d20ed0fa77a4e60740d23578c63f227e723a93a16135e2e2)
Skillmon
Using insert path we can add things to the background of the node, and using a pic we can draw things with independent options. The following does exactly that:


\documentclass[border=3.14,tikz]{standalone}

\tikzset
{
cerchio/.style={insert path={pic{cerchio}}}
}

\begin{document}
\begin{tikzpicture}
\node[cerchio]{a long node};
\end{tikzpicture}
\end{document}


![tikznodedeborder-1.png](/image?hash=6b6892d47dc2d9ab30b597f430576404ac711f5a40d6fb3e59048ff5163dfb2f)
Qrr
Depending on the requirement for the circle which size is determined by the height/depth of a long node and the width 10pt, here are some alternative approaches.

---

The closest would be cerchioB where the text is actually a label on top of the circle, though you need to change your syntax a bit (also doesn't allow verbatim text anymore):


\node[cerchioB=a long node];


You can now use that parameter for the label itself but also for the parent node and with \vphantom the circle has the same size as in your \makebox example

---

cerchioA places the circle as a label, getting the same size as in your example isn't trivial. (But maybe the size of the circle shouldn't be in relation to the text in the first place?)

I'm not a friend of behind path but if it's just a \node (and its label), it should be fine.

---

Lastly, cerchioC simply does basically the same as \makebox[#1][c] but with styles.

This will create a textbox of width text width=10pt with a box of width #1 centered inside of it – just like \makebox.

Though, just like \makebox TikZ won't be able to adjust the bounding box of the picture to the text. (That's why I put those \RULEs around the pictures.)

---

Of course, you can do both as a pic which is what cerchioD does, the pic key helps so that the user can still use \node, unfortunately, the text needs to be given as part of the options again. (Though something like pic {cerchio=a long node} is possible, too.)


\documentclass{article}
\usepackage{tikz}
\tikzset{
makebox/.style={
execute at begin node=\hbox to#1\bgroup\hss,
execute at end node=\hss\egroup},
cerchio/.style = {
draw=red, fill=yellow, circle, text=black,
text width=10pt, text centered},
cerchioA/.style = {
path only, text=black, shape=rectangle,
label={[draw=red, fill=yellow, behind path,
shape=circle, text width=10pt, anchor=center]center:}},
cerchioB/.style={
draw=red, fill=yellow, shape=circle, text width=10pt,
node contents=\vphantom{#1},
label={[path only, text=black, shape=rectangle, anchor=center]center:{#1}}},
cerchioC/.style={
draw=red, fill=yellow, shape=circle, text width=10pt, text centered,
makebox=0pt}, % or makebox=10pt
pic/.is if=tikz@node@is@pic, % allows turning a node into a pic
cerchioD/.style={pic, pic text={#1}, pic type=cerchio},
cerchio/.pic={
\node[path only, shape=rectangle] {\tikzpictext};}}
\newcommand*\RULE{\rule[-.3\baselineskip]{.4pt}{2.5\baselineskip}}
\begin{document}

\RULE
\tikz
\node[cerchio]{\makebox[0pt]{a long node}};%
\RULE

\RULE
\tikz % node is circle, label is rectangle (text)
\node[cerchioA]{a long node};%
\RULE

\RULE
\tikz % node is rectangle (text), label is circle
\node[cerchioB=a long node];%
\RULE

\RULE
\tikz % node is circle, text box contains makebox
\node[cerchioC]{a long node};%
\RULE

\RULE
\tikz % it's actually a pic
\node[cerchioD=a long node];%
\RULE
\end{document}