# Letters' kerning space so different?

I'm wondering what is happening here:

Why is the third line getting so much squeezed to the left? Is the kerning of the letter Z really so much less than Y and X?

This is happening in a longtable environment with direct column width control:

\documentclass{article}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage{booktabs}
\usepackage{hyperref}
\usepackage[margin=1in]{geometry}

\begin{document}
\begin{longtable}{p{0.27\linewidth}p{0.15\linewidth}p{0.52\linewidth}}
\toprule
\textbf{Column name} & \textbf{Example value} & \textbf{Description} \\
\midrule
BodyFixedCoordinateX  & -67.2071 & Center X coord.\@ [km] in Mars-fixed ref.\@ frame \\
BodyFixedCoordinateY  & 257.05 & Center Y coord.\@ [km] in Mars-fixed ref.\@ frame \\
BodyFixedCoordinateZ  & -3370.63 & Center Z coord.\@ [km] in Mars-fixed ref.\@ frame \\
\bottomrule
\end{longtable}
\end{document}

• Please make your code snippet compilable! – Kurt Mar 10 '18 at 23:35
• I would guess that the letter Z is not as wide as X and Y which both just happen to have the same width. – Jasper Habicht Mar 10 '18 at 23:36

If you run the file

\setbox0\hbox{X}\showthe\wd0
\setbox0\hbox{Y}\showthe\wd0
\setbox0\hbox{Z}\showthe\wd0
\bye


through (Plain-)TeX on the command line, TeX shows the width of the characters X, Y and Z in the standard fonts.

The widths are 7.5pt, 7.5pt and 6.11pt, so the difference is not in the kerning, but in the width of the letters. If you want to avoid letters with different width, you can use a monospace font with \mathtt{...}.

As the other two answers have already established, the issue is not a matter of kerning. Instead, the issue is that the letters X, Y, and Z don't have the same widths. Specifically, for the case at hand, i.e., with a Computer Modern Roman upright font face, the letter Z is less wide than the other two.

What to do, in order to get a neat-looking table? Let's assume that "neat-looking" implies that the rest of the material in the third column should be perfectly aligned. I suggest creating a macro -- called \spbox in the code below -- which takes two arguments. The first argument contains material (say, the single letter "X") that represents the intended width of the box, and the second argument contains the letter to be typeset (say, the single letter "Z"). Obviously, the width of the second argument should be less than the width of the first.

Four additional observations: (i) Use an S column type (provided by the siunitx package) for the middle, numeric column. (ii) The \@ in Mars-fixed ref.\@ frame achieves nothing that the simpler Mars-fixed ref.\ frame wouldn't achieve. (iii) Do make a habit of writing scientific units using the \si macro, which is also provided by the siunitx package. (iv) It's usually very good practice to load the hyperref package last. (There are only very few exceptions to this rule; one of them is that cleveref must be loaded after hyperref.)

From Marcel Krüger's answer, we know that widths of the letters X and Y are equal if Computer Modern Roman upright is in use. Suppose, more generally, that all we know is that X is at least as wide as both Y or Z. The following code uses two \spbox directives to take this into account.

\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{longtable,booktabs,siunitx,array,calc}
\usepackage{hyperref} % load this package *last*

%% The new user macro: \spbox
\newcommand{\spbox}[2]{\makebox[\widthof{#1}]{#2}}

\begin{document}

\begin{longtable}{@{} p{0.27\linewidth}
S[table-format=-4.4] % was: "p{0.15\linewidth}"
p{0.52\linewidth} @{}}

\toprule
\textbf{Column name} &
\multicolumn{1}{>{\centering}p{0.15\linewidth}}{\textbf{Example value}} &
\textbf{Description} \\
\midrule

\bottomrule
\endlastfoot

%% Body of longtable
BodyFixedCoordinateX  & -67.2071
& Center X coord.\ [\si{\kilo\meter}] in Mars-fixed ref.\ frame \\
BodyFixedCoordinateY  &  257.05
& Center \spbox{X}{Y} coord.\ [\si{\kilo\meter}] in Mars-fixed ref.\ frame \\
BodyFixedCoordinateZ  &  -3370.63
& Center \spbox{X}{Z}\ coord.\ [\si{\kilo\meter}] in Mars-fixed ref.\ frame \\
\end{longtable}

\end{document}

• As a TeX-newbie, I would have written: \newcommand{\spbox}[2]{\rlap{#2}\hphantom{#1}}. Are there interesting advantages/disadvantages when compared with your solution? – wchargin Mar 11 '18 at 19:48
• @wchargin - Thanks. The main difference is, I believe, that your approach left-aligns the visible character in the available space, whereas mine centers the visible character. For the application at hand, centering is probably what's called for. However, under different circumstances left-alignment might be (more) appropriate. – Mico Mar 11 '18 at 20:09
• Ah, I didn't know that the default alignment of \makebox was c…and using \clap{#2}\hphantom{#1} would have produced the wrong results. Thanks! – wchargin Mar 11 '18 at 20:37
• @wchargin - I believe that \clap is generally defined via \newcommand{\clap}[1]{\makebox[0pt]{#1}}, i.e., it relies on a \makebox directive, just like \spbox does. :-) – Mico Mar 11 '18 at 21:57

It depends on the used font. In your case it is Computer Modern with an smaller Z.

If you for example use font Libertine the difference is gone:

\documentclass{article}

%\usepackage{graphicx}
\usepackage{longtable}
\usepackage{booktabs}
\usepackage[margin=1in]{geometry}

\usepackage{Libertine} % <==============================================

\usepackage{hyperref}

\begin{document}
\begin{longtable}{p{0.27\linewidth}p{0.15\linewidth}p{0.52\linewidth}}
\toprule
\textbf{Column name} & \textbf{Example value} & \textbf{Description} \\
\midrule
BodyFixedCoordinateX  & -67.2071 & Center X coord.\@ [km] in Mars-fixed ref.\@ frame \\
BodyFixedCoordinateY  & 257.05   & Center Y coord.\@ [km] in Mars-fixed ref.\@ frame \\
BodyFixedCoordinateZ  & -3370.63 & Center Z coord.\@ [km] in Mars-fixed ref.\@ frame \\
\bottomrule
\end{longtable}
\end{document}


with the result: