3

It occured to me in one of my documents that the letter F was not aligning nicely:

enter image description here

I tried different fonts from https://tug.org/FontCatalogue/.

Is there a way to align the F nicely.

I know this is due to the font. This also occurs in word:

enter image description here

You can find and edit my example here: https://www.overleaf.com/6991348982vwhhwrtvpfcn

2
  • 2
    Welkom terug op TeX.SE! Please post self-contained examples in your questions, with all code necessary to reproduce the issue, without linking to external websites such as Overleaf. This makes sure that the code remains accessible in the future as long as TeX.SE itself is online. Regarding the question itself: bigger font sizes usually reserve a bit more space for the letters, also on the left. If you want you can adjust the horizontal spacing a bit with something like \hskip-0.5pt Factuur.
    – Marijn
    Commented Mar 24, 2021 at 14:59
  • The overleaf project reports 9 errors, I don't know if those errors could create this misalignment Commented Mar 24, 2021 at 16:59

1 Answer 1

7

What you are seeing are the sidebearings of the character.

Try this code (needs lualatex) for turning the switch \dropsidebearings on and off. Courtesy of Marcel Krüger.

See Dot won't properly align with text and links in it.

ex

Y

    % !TeX TS-program = lualatex  

\documentclass[12pt, a4paper]{article}

\RequirePackage{showframe} % margin line
\renewcommand\ShowFrameLinethickness{0.1pt}
\renewcommand\ShowFrameColor{\color{red}}

\RequirePackage{luacode}
\newcount\dropsidebearings

\begin{luacode*}
    
    ------------------------drop_sidebearing------------------------
    --https://tex.stackexchange.com/questions/427068/sidebearings-and-precision-left-right-alignment?noredirect=1&lq=1
    --In LuaTeX, you can use the post_linebreak_filter to intercept the broken lines and
    -- add some offsets. The sidebearings can be extracted from rawdata saved by luaotfload.
    -- After adding the offsets, the hboxes have to be repacked to determine the new glue settings.
    
    ---updated for 1.09
    --https://tex.stackexchange.com/questions/470276/perfect-alignment-luatex-and-sidebearings-part-ii
    ------------------------drop_sidebearing------------------------
    
    
    local function drop_sidebearing(head, groupcode)
    
    if tex.count['dropsidebearings'] == 0 then
    return true
    end
    for n in node.traverse_id(node.id'hlist', head) do
    local char = node.has_glyph(n.head)
    if char then
    local f = font.getfont(char.font)
    if f.shared then
    local kern = node.new(node.id'kern')
    kern.kern = - f.shared.rawdata.descriptions[char.char].boundingbox[1]*f.size/1000
    n.head = node.insert_before(n.head, char, kern)
    end
    end
    for ch in node.traverse_id(node.id'glyph', n.head) do
    char = ch
    end
    if char then
    local f = font.getfont(char.font)
    if f.shared then
    local desc = f.shared.rawdata.descriptions[char.char]
    local kern = node.new(node.id'kern')
    kern.kern = - (desc.width-desc.boundingbox[3])*f.size/1000
    node.insert_after(n.head, char, kern)
    end
    end
    local new_list = node.hpack(n.head, n.width, 'exactly')
    new_list.head = nil
    n.glue_order = new_list.glue_order 
    n.glue_set = new_list.glue_set
    n.glue_sign = new_list.glue_sign 
    node.free(new_list)
    end
    return true
    end
    
    luatexbase.add_to_callback('post_linebreak_filter', drop_sidebearing, 'Drop sidebearings after linebreaking')
    
    
\end{luacode*}

\setlength{\parindent}{0pt}
\renewcommand{\familydefault}{\sfdefault}

\begin{document}    
            
\dropsidebearings=1 

dropsidebearing =1 (no sideberarings)

\Huge F  

\huge F  

\LARGE F  

\Large F  

\large F  

\dropsidebearings=0 

dropsidebearing =0 (normal sideberarings)

\Huge F  

\huge F  

\LARGE F  

\Large F  

\large F  

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .