2

This question builds off of the one here: enter link description here

However, my question is how do I wrap around the text?

Here is what I am trying to do.

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node[fill=black!40!white,
      thick,
      draw,
      minimum height=0.5cm,
      minimum width=3.2cm,
      label=south:The quick brown fox jumps over the lazy dog %< -- This uses an anchor of the node for the location
] at (0,1.5) {Canonical Polyadic};
\end{tikzpicture}
\end{document}

What I get is this long line of text at the south of the rectangle.

enter image description here

I have tried specifying text width = 3.2 cm, etc but they don't see to me to be having any effect.

Ignasi
  • 136,588
  • First, a label is actually another node, so basically you need two overlapping nodes, one with text and one for the rectangle. (Well, you really don't need a node for the rectangle.) However, wrapping text around objects is not easy. You can use \parshape for single paragraps, but in this case I would simply manually add gaps to the text. – John Kormylo Nov 24 '21 at 15:37
  • Thanks! So, I tried forcing a break The quick brown fox \\ jumps over the lazy dog but that did not do anything. What does manually adding gaps to the text mean? I did try placing as a separate node \node[below of=check, text width = 2 cm] {The quick brown fox jumps over the lazy dog}; and this seems to work. Thanks! – user3236841 Nov 24 '21 at 15:52
  • Although you accepted my answer, I still have a doubt about the real problem. Do you want text around a box? or do you want text that contains a box in the middle? In the second case I think it's better to use a \tcbox like in https://tex.stackexchange.com/a/364234/1952 – Ignasi Nov 24 '21 at 16:50
  • Thanks, I did not want it around the box but close to the box. The suggestion made my @JohnKormylo was adequate for my immediate needs, and it is very unfortunate that we can only check one answer. Yours is a bit moe so I checked it. – user3236841 Nov 24 '21 at 21:21

2 Answers2

5

A label is another node. You can fix its width independently from the labelled node and you can place as many labels as you need.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\node[fill=black!40!white,
      thick,
      draw,
      minimum height=0.5cm,
      minimum width=3.2cm,
      label={[text width=3cm, align=center]south:The quick brown fox jumps over the lazy dog} 
] (a) {Canonical Polyadic};
\node[fill=black!40!white,
      thick,
      draw,
      minimum height=0.5cm,
      minimum width=3.2cm,
      label={north:The quick brown fox}, 
      label={west:jumps}, 
      label={east:over}, 
      label={south:the lazy dog}, 
right=3cm of a] (b) {Canonical Polyadic};
\end{tikzpicture}
\end{document}

enter image description here

Ignasi
  • 136,588
2

This shows how to manually wrap text inside a node.

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node[text width=4.1cm, font={\baselineskip=.5cm}] (A)
  {The quick brown fox \hspace*{3.1cm} jumps over the lazy dog};
\node[fill=black!40!white,
      thick,
      draw,
      minimum height=0.5cm,
      minimum width=3.2cm,
      right
] at (A.west) {Canonical Polyadic};
\end{tikzpicture}
\end{document}

demo

John Kormylo
  • 79,712
  • 3
  • 50
  • 120