7

is there any way to change the position of nodes inside the rectangle drawn for the node itself? For example I got this:

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[german]{babel}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node at (0,0) [draw,minimum height=1cm,minimum width=4cm] {Lorem Ipsum};

\draw (-2,-2) rectangle (2,-1);
\node at (0,-1.8) {Lorem Ipsum};
\end{tikzpicture}
\end{document}

So I need to use the first syntax (because a lot of things are based on this) but want to change the position of the text inside the rectangle as shown in the second example. Is there a way to change the position in the rectangle created by the node itself?

Thanks for you

enter image description here

5

The closest to what you like to obtain with one node:

\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node at (0,0) [draw,
                text height=1cm, text depth=1ex, 
                minimum width=4cm, inner sep=-0.2ex] (a) {Lorem Ipsum};

\draw (-2,-2) rectangle (2,-1);
\node at (0,-1.8) {Lorem Ipsum};
\end{tikzpicture}
\end{document}

enter image description here

The node above is slightly taller.

6

Not exactly the same syntax, but you could potentially use a label instead of the node itself. Whether this is a viable method depends on your actual use though.

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
%\usepackage[german]{babel}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node at (0,0) [draw,minimum height=1cm,minimum width=4cm,
       label={[above,inner sep=0pt]below:Lorem ipsum}] {};

\draw (-2,-2) rectangle (2,-1);
\node at (0,-1.8) {Lorem Ipsum};
\end{tikzpicture}
\end{document}

enter image description here

3

You can draw it in two steps, first the box and then position the text above the lower edge of the box.

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[german]{babel}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
  % \node at (0,0) [draw,minimum height=1cm,minimum width=4cm] {Lorem Ipsum};
  \node (Square) at (0,0) [draw,minimum height=1cm,minimum width=4cm] {};
  \node[above=-2pt] at (Square.south) {Lorem Ipsum};

  \draw (-2,-2) rectangle (2,-1);
  \node at (0,-1.8) {Lorem Ipsum};
\end{tikzpicture}
\end{document}

enter image description here

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.