[Tex/LaTex] tcolorbox on a node

tcolorboxtikz-pgf

I have a tcolorbox with the following settings:

\tcbset{
    noparskip,
    colback=yellow!10,
    colframe=yellow,
    coltext=black,
    coltitle=white,
    boxrule=0.3mm,
    fonttitle=\bfseries,
}

How can I add this tcolorbox at a node and give it a specific width and height. In other words, be able to do something like (or whichever syntax is simple):

\node [tcolorbox, title=foo, text width=Xmm, minimum height=Ymm] at (x,y) {blah blah}

A minimal example is as follows (note that the block with tikzpicture might not run… it's an example of what I want to do. The rest will run).

\documentclass{beamer}
\usepackage{tikz,tcolorbox}
\tcbset{
    noparskip,
    colback=yellow!10,
    colframe=yellow,
    coltext=black,
    coltitle=white,
    boxrule=0.3mm,
    fonttitle=\bfseries,
}
\begin{document}
\begin{frame}{}
    %Normal tcolorbox
    \begin{tcolorbox}
        Lorem ipsum
    \end{tcolorbox}

    %Desired functionality
    \begin{tikzpicture}[remember picture, overlay]
        \node [tcolorbox, title=foo, text width=Xmm, minimum height=Ymm] at (x,y) {dolor sit amet}
    \end{tikzpicture}
\end{frame}
\end{document}

Best Answer

Maybe your answer is fine, but the question shows the subtlety of features of TikZ. As you had the command minimum height=Ymm to set this feature, a command such as minimum width=Xmm is also useful and preferable to text width in setting the dimensions of a shape. From my experience, using text width=Zmm can override the minimum width command.

I've found that it can be useful to set up a node and put the text there so you can use text width to control the line breaking, and then put the shape with the appropriate minimum height/width commands (possibly defined at \begin{scope}[options]) at the same node so that you can ensure uniformity of your shapes, rather than having the size of the text dictate them.

Here's something from what I'm working on currently:

\documentclass[a4paper]{article}
\usepackage{amssymb,amsmath,tikz,amsmath,amssymb}
\usetikzlibrary{fit,positioning,shapes}


\begin{document}

\begin{center}
\begin{tikzpicture}

  % Use the scope environment to set features of the shapes such as minimal dimensions, and text features 

\begin{scope}[font=\tiny, color=black, ultra thick, node distance=2.5cm,minimum height=15mm,minimum width=55mm]

% First set up the text to go at a particular node

\node[text width=35mm] (3term) at +(0.0cm,0.0cm) {$Y_{n+1}$ = $K_{n}Y_{n}$ = $(\kappa_{1} x + \kappa_{0}) Y_{n}$ \\ 3-term recurrence relation};
% then draw the desired shape at that node to go around the text. 

\node[ellipse,draw] at (3term) {};

%    a second text snippet in a shape

\node[rectangle, draw,right = of 3term]  (HMEqns) {Hirota--Miwa Equations};

%   a third example

\node[below = of 3term, text width = 48mm]  (LFEqns) {$\displaystyle [\Omega_{nr} - V_{r} ] [ \Omega_{nr} + V_{r} ] = a_{n}^{2} \Theta_{nr} \Theta_{n-1 \, r}$ \\ Laguerre--Freud Equations/ \\ discrete Painlev\'e Equations};

\node[rectangle, draw] at (LFEqns) {};


\end{scope}

\draw[] (3term) to (HMEqns) {};

\draw[] (3term) to (LFEqns) {};

\end{tikzpicture}
\end{center}

\end{document}

pdf output of the above code

Related Question