I've used the following SE answer to try to center the text in the left half or right half of a node. The left half is placed OK, but the right half is acting weird, and I haven't figured out why.
MWE:
\documentclass[tikz,border=1cm]{standalone}
\usepackage{standalone}
\usepackage{tikz}
\begin{document}
\newcommand{\textlabel}[3]{\node[label, inner xsep=\LabelSize/2, fill=#2] at (0,2*#1) {#3};}
\newcommand{\textlefthalf}[2] {\textlabel{#1}{#2}{\hspace*{-\LabelSize}1}}
\newcommand{\textrighthalf}[2] {\textlabel{#1}{#2}{\hspace*{\LabelSize}1}}
\newcommand{\textrighthalfalt}[2] {\textlabel{#1}{#2}{1\hspace*{-\LabelSize}}}
\newcommand{\textrighthalfaltcolor}[2]{\textlabel{#1}{#2}{\color{white}1\hspace*{-\LabelSize}}}
\newlength\LabelSize
\setlength\LabelSize{1cm}
\tikzset{
label/.style={fill=black,text width=\LabelSize, align=center,minimum height=\LabelSize,minimum width=\LabelSize*2,inner sep=0em,text=white,font=\sffamily\fontsize{15pt}{0pt}\selectfont},
}
\begin{tikzpicture}
\textlefthalf{0}{blue}
\textrighthalf{1}{red}
\textrighthalfalt{2}{black}
\textrighthalfaltcolor{3}{gray}
\draw[dashed] (0,-1) -- (0,7);
\draw[green, dashed] (-\LabelSize/2,-1) -- (-\LabelSize/2,7);
\draw[green, dashed] (\LabelSize/2,-1) -- (\LabelSize/2,7);
\end{tikzpicture}
\end{document}
Blue is okay, right is off-'centre', black is centered to the real center (not the one I intend). The gray one is the one I want to see. But why does adding the \color{white}
help to achieve this?
I'd like to understand what's happening so that I can tune my mental model of latex.
\hspace
?