Align text next to the upper left corner of a node

by null   Last Updated June 12, 2019 08:23 AM

I have two nodes below each other:

\documentclass[DIN, pagenumber=false, fontsize=11pt, parskip=half]{scrartcl}

\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}

\begin{tikzpicture}[node distance=0pt, nodes={outer sep=0pt, minimum width=3cm, thick, minimum height=1cm}]

\node (n1) at (3,2) [draw, minimum height=2cm] {n1};
\node (n2)  [draw, below=of n1.south] {n2};
\node[left=of n1](t1) {this is a label};
\node[minimum width=0cm, left=of t1] {foo};

\end{tikzpicture}

\end{document}

I'd like to add two adjoining labels next to the upper left corner of each node. These now lines place the labels next to node n1, but I cannot push it upwards to the corner.

\node[left=of n1](t1) {this is a label};
\node[minimum width=0cm, left=of t1] {foo};

This is how the upper code looks like: enter image description here

And this is how it should like: enter image description here

Tags : tikz-pgf


Answers 1


You can use anchor=east, left=of n1.north west for that:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}[node distance=0pt, nodes={outer sep=0pt, minimum width=3cm, thick, minimum height=1cm}]
\node (n1) at (3,2) [draw, minimum height=2cm] {n1};
\node (n2)  [draw, below=of n1.south] {n2};
\node[anchor=east, left=of n1.north west] (t1) {this is a label};
\node[minimum width=0cm, left=of t1] {foo};
\end{tikzpicture}
\end{document}

Screenshot

frougon
frougon
June 12, 2019 08:11 AM

Related Questions




Drawing similar picture with tikz

Updated November 20, 2018 12:23 PM

Complicated curves interwined in the link figures

Updated December 17, 2018 22:23 PM

Complicated curves intertwined in the link figures (II)

Updated December 18, 2018 02:23 AM