在 TikZ 中将字母与下方线条对齐

在 TikZ 中将字母与下方线条对齐

我正在尝试制作一张名片,并希望将路径(在本例中为线)的开头与字母完美对齐。但是,由于添加了间距字母,对齐似乎不完美。节点上的对齐已完成(应该如此),但我想删除第一个(大写)字母之前的少量空格。

我也尝试使用\underline,但没有成功。

MWE(我使用XeLaTeX):

% !TEX TS-program = xelatex
\documentclass{standalone}

\usepackage{standalone}
\usepackage{tikz}
\usetikzlibrary{backgrounds,calc,positioning}

\begin{document}
% preferred method
\begin{tikzpicture}[every node/.style={inner sep=0,outer sep=0},framed]
\draw[anchor=west] (0,0) node[align=left] (name)  {\Huge Here}; 
\draw[line width=0.03cm] ($(name.south west)+(0,-0.03in)$) -- ($(name.south west)+(1in,-0.03in)$);
\end{tikzpicture}

% attempt with underline
\begin{tikzpicture}[every node/.style={inner sep=0,outer sep=0},framed]
\draw[anchor=west] (0,0) node[align=left] (name)   {\Huge\underline{Here}}; 
\draw[line width=0.03cm] ($(name.south west)+(0,-0.03in)$) --  ($(name.south west)+(1in,-0.03in)$);
\end{tikzpicture}
\end{document}

PDF 输出

(我知道,这个 MWE 实际上不需要 XeLaTeX。)

答案1

如果使用 OpenType(/TrueType) 字体(PFB 字体不起作用),XeTeX 就会知道侧边距:

\XeTeXglyphbounds1\XeTeXglyphindex"H"

应用于问题的“首选方法”:

\documentclass{standalone}

\usepackage{standalone}
\usepackage{fontspec}% OpenType of Latin Modern fonts
\usepackage{tikz}
\usetikzlibrary{backgrounds,calc,positioning}

\begin{document}
% preferred method
\begin{tikzpicture}[
  every node/.style={inner sep=0,outer sep=0},
  framed,
]
  \draw[anchor=west] (0,0) node[align=left] (name) {%
    \Huge Here%
    \xdef\LeftSideBearingH{\the\XeTeXglyphbounds1\XeTeXglyphindex"H" }%
    \typeout{* Left side bearing of H: \LeftSideBearingH}%
  };
  \draw[line width=0.03cm]
    ($(name.south west)+(\LeftSideBearingH, -0.03in)$) -- ++(1in, 0);
\end{tikzpicture}
\end{document}

报告值:

* Left side bearing of H: 1.26888pt

结果

答案2

像这样?

在此处输入图片描述

% !TEX TS-program = xelatex
\documentclass[border=3mm, tikz]{standalone}
\usetikzlibrary{backgrounds,calc,positioning}

\begin{document}
% preferred method
\begin{tikzpicture}[
    here/.style = {font=\Huge,
                   inner xsep=-1.2pt,% <-- here is the trick
                   inner ysep=0.03in, outer sep=0pt},
    framed          ]
\node[here] (name)  {Here};
\draw[line width=0.03cm] (name.south west) -- ($(name.south west)+(1in,0in)$);
\end{tikzpicture}
\end{document}

或考虑敲击注释,只需将行移到1.2pt右侧(结果与之前相同):

% !TEX TS-program = xelatex
\documentclass[border=3mm, tikz]{standalone}
\usetikzlibrary{backgrounds}

\begin{document}
% preferred method
\begin{tikzpicture}[
    here/.style = {font=\Huge,
                   inner xsep=0pt,inner ysep=0.03in, outer sep=0pt},
    framed          ]
\node[here] (name)  {Here};
\draw[line width=0.03cm] ([xshift=1.2pt] name.south west) -- ([xshift=1in] name.south west);
\end{tikzpicture}
\end{document}

相关内容