0

I'd like to make a custom TikZ node type (a custom Latex macro will also do) that is a rectangle and where the text goes near its south east corner.

Consider the script below and corresponding output

\documentclass[margin=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}
\begin{tikzpicture}
  \coordinate (PT) at ($(0,0)$) ;
  \node[draw, black, thick, minimum width =3.0cm,
        minimum height=4.2cm] at (PT) {Some fancy text};
\end{tikzpicture}

\end{document}

This gives

enter image description here

I would instead like a rectangular node that looks like the following picture (Apologies, I constructed this in Inkscape so it only approximates the above rectangle). Notice how I would like the text to be multiline and center aligned.

enter image description here

2
  • 3
    Should the whole construct be placed in relation the big rectangle or just the text? If the rectangle needs to be a node: \node[rectangle, draw, minimum width=4cm, minimum height=6cm, label={[anchor=south east, align=center]south east:Some\\fancy text}]{}; Jul 21, 2023 at 20:17
  • Thanks! this worked perfectly! Jul 22, 2023 at 21:17

2 Answers 2

1

Here's one way to do it. Basic steps:

  • reverse the task, i.e. start with the node
  • align=center provides your format, while \\ controls the linebreak
  • finally, draw some lines, starting at (T.south east) and using increments via ++, which use the result as the next starting point

You could convert this into a \pic, which takes text, height and width (3 parameters) as arguments; search for args in the manual.

result

\documentclass[10pt,border=3mm,tikz]{standalone}
\begin{document}

 \begin{tikzpicture}
    \node[align=center] (T) at (0,0) {Some\\fancy text};
    \draw (T.south east) -- ++(0,3.5) -- ++(-2.9,0) -- ++(0,-3.5) -- cycle;
 \end{tikzpicture}

\end{document}
0

Here is an other way to do it:

  • put the node (T) first
  • draw a rectangle with negative width at (T.south east)

result

\documentclass[10pt,border=3mm,tikz]{standalone}
\begin{document}

 \begin{tikzpicture}
    \node[align=center] (T) at (0,0) {Some\\fancy text};
    \draw (T.south east) rectangle (-3,2);
 \end{tikzpicture}

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .