[Tex/LaTex] TikZ: How to center a label’s text of a node when using label=

alignmenthorizontal alignmentlabelstikz-pgfvertical alignment

Say I have a node:

\node [rectangle,label=above:$\text{rect…}$] (r0) at (0,0) {};

How can I horizontally center the text rect… above my rectangle?

Thanks in advance for your answers.



Edit (MWE):

\begin{tikzpicture}[x=01.00mm,y=00.50mm,node distance=10.00mm and 10.00mm,> = stealth',bend angle = 45,style = {font=\normalsize},every node/.style = {transform shape}]

\tikzset{tickh/.style={rectangle,text width=0,text height=0,fill=black,align=center,minimum width=4,minimum height=20,outer sep=0,inner sep=0,scale=0.5}}
\tikzset{rct/.style={trapezium angle=90,minimum width=20,fill=gray!100!black}}

\node [tickh,label={below:$\textit{aa}_i$}] (x1) at (0,0) {};
\node [rct,label={above:$\textit{bb}_j$},xshift=-03.50mm] (t0) [above=+02.00 of x1.center,anchor=south east] {};



EDIT #2:

It appears that the line style = {font=\normalsize} is causing the problem. It is probably a conflict with some package I'm using because it doesn't cause any problem on minimal examples. I'll post an answer if I find which one it is.

Best Answer

i guess, that you looking for the following:

enter image description here

labels positioned by above or below are always horizontal centered regarding to a node's anchor north or south respectively (if you not shift them with xshift).

your mwe has errors and contains some illogicality. i correct them and add explanations as comments in code:

\documentclass[tikz, margin=3mm]{standalone}
    x=01.00mm,y=00.50mm,        % tikz is not enginering tool, suficient is "x=1mm, y=0.5mm"
    node distance=0mm and 2mm,  % set to desired distances between nodes
    > = stealth',               % it need package `arrows
    bend angle = 45,            % not used in this mwe
%   style = {font=\normalsize}, % this is superfluous. default font size is normal size
                                % if for some reason like to change font size used in tikz picture, 
                                % than write for example only  "font=\small" without 
                                % use of "style={....}" . it is wrong syntax
    every node/.style = {transform shape}   % where you need this?
    rectangle, fill=black,
    text width=0,text height=0, % what you like to achieve with this?
    align=center,               % for given text width this is pointless
    minimum height=20, minimum width=4,
    outer sep=0, inner sep=0,
            rct/.style={        % if you not define shape,
                                % tikz consider rectangle for node's shape
    trapezium angle=90,         % rectangle hasn't this option
    minimum width=20,
\node [tickh,
                           (x1) {}; % label is centered regarding to node below of node
\node [rct,  
       label=above:$\mathit{bb}_j$, % label is centered regarding to node below of node
       above right=of x1] (t0) {};  % for positioning is used only "node distance"
                                    % in case that placement of this node is exception from
                                    % prescribed distances, than instead of `xshift` and `yshift` rather use
                                    % "node disance=<vertical distance> and <horizontal distance> of <anchor>".
                                    % if <anchor> is node, than distances are between borders of the adjacent nodes