I have nodes with text inside, however the nodes are too large for the text, with large margins.
I want to keep the text size the same, but make the box tighter. I've tried varying text height and width, as well as inner sep
s, however these only move the text around.
The code below produces the following output:
\documentclass[tikz, border=2mm]{standalone}
\usetikzlibrary{positioning,shapes,arrows,backgrounds,external,fit,calc}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{helvet}
\renewcommand{\familydefault}{\sfdefault}
\definecolor{CoreBlue}{HTML}{5b9bd5}
\tikzset{
Core/.style={rectangle, draw, fill=CoreBlue, draw opacity=0, text=white},
}
\begin{document}
\begin{tikzpicture}[font={\sffamily\scriptsize}]
\node[Core,minimum width=12mm,minimum height=8mm, anchor=west,
% inner sep=-10mm, % no change
% inner ysep=-10mm, % no change
% text height=1mm, % changes text position, but not node size
% text width=0.2cm, % changes text position, but not node size
] (1) at (0,0) {\scriptsize Lorem};
\end{tikzpicture}
\end{document}
Best Answer
You are setting
minimum width=12mm
andminimum height=8mm
so your box is going to be at least this big and you will have "large margins" unless your text can fill the void. If you do not want the margins then take out the minimum width and height specifications. If, in addition, you addinner sep=0.5mm
then you get pretty close to what you are asking for:(I've zoomed in on the image, which is why it is slightly bigger than above.) Now that the width and height are not fixed, tikz is able to adjust the size of the box so that it fits the text.
Here's the updated code: