4

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}
3
  • 1
    Welcome to TeX.sx! Please add a minimal working example (MWE) that illustrates your problem. Where does the tcolorbox come from? Which document class are you using? – percusse Oct 18 '12 at 15:48
  • @percusse It's a beamer document. I'll add an example – user21072 Oct 18 '12 at 16:06
  • 1
    Ok, I figured out the answer — all I had to do was \node [text width=...] at (...) {\begin{tcolorbox}...\end{tcolorbox}}. I can't answer it myself yet, because I need to wait for 6 hrs, which I don't have. If anyone wants, feel free to copy my comment into an answer so that the issue can be closed. – user21072 Oct 18 '12 at 16:53
1

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

1
  • Tip: to highlight inline code you can use backticks (`), or, as with code blocks, select the word(s) and click the button on the toolbar. I also uploaded a cropped version of the output, hope that's OK. – Torbjørn T. Oct 22 '12 at 6:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy