TransWikia.com

Align sans-serif text with TikZ

TeX - LaTeX Asked on September 29, 2021

Consider the following MWE

documentclass{standalone}
usepackage{tikz}
usetikzlibrary{positioning}

begin{document}
begin{tikzpicture}

node[anchor=west, inner sep=0pt, draw, very thin, rectangle] (a) at (0,0) {scalebox{15}{sffamily LARGE}};

node[anchor=west, inner sep=0pt, draw, very thin, rectangle] (b) at (0,-4) {scalebox{3}{sffamily smaller text}};

draw[blue] (a.west) ++ (0,-2cm) -- ++(0,4cm);
draw[red] (a.west) ++ (-0.2cm,0) -- ++(0.4cm,0);
draw[red] (a.west) ++ (0,-0.2cm) -- ++(0,0.4cm);

draw[blue] (b.west) ++ (0,-2cm) -- ++(0,4cm);
draw[red] (b.west) ++ (-0.2cm,0) -- ++(0.4cm,0);
draw[red] (b.west) ++ (0,-0.2cm) -- ++(0,0.4cm);

end{tikzpicture}
end{document}

which produces this result:

result of MWE

Why is there some space between the "bounding box" and the letter L? I want to remove the white space around the text exactly, such that the vertical line of the L and the smaller text below align perfectly.

Further, I want to scale the smaller text such that it becomes exactly as wide as the top text. How is that possible?

One Answer

It has nothing to do with tikz. tikz can only use the font metrics, it doesn't see the ink and the letters do have side bearings:

documentclass{article}
usepackage{tikz}
usepackage[showframe]{geometry}
parindent=0pt
begin{document}

fontsize{1cm}{1.3cm}selectfont sffamily
LARGE

TEST

XXX

tikz[overlay]draw[red](0,0)--++(0,5);
end{document}

enter image description here

Correct answer by Ulrike Fischer on September 29, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP