1

I am trying to make a business card and want to perfectly align the beginning of a path (line in this case) with a letter. However, due to spacing added before the letter, the alignment does not seem perfect. The alignment is done (as should be) on the node, but I want to remove the small amount of spacing before the first (capital) letter.

I also made an attempt using \underline, without success.

MWE (I use 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 output

(XeLaTeX is not really required for this MWE, I know.)

1

XeTeX knows the side bearings, if OpenType(/TrueType) fonts are used (PFB fonts do not work):

\XeTeXglyphbounds1\XeTeXglyphindex"H"

Applied to the "preferred method" of the question:

\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}

The reported value:

* Left side bearing of H: 1.26888pt

Result

1

Like this?

enter image description here

% !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}

or consider percusse comment, just move line for 1.2pt to the right (result is the same as before):

% !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}
  • 1
    negative sep spaces are not recommended – percusse Oct 4 '16 at 22:16
  • @percusse, it is really not good practice. I add to my answer an alternative with shifting line to the right. – Zarko Oct 4 '16 at 22:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.