0

When trying to align a dot with one of the left or right margins of the page, it won't properly align, leaving some space before/after it.

It certainly has something to do with the character scale and spacings. Here's a MWE:

\documentclass[11pt, a5paper]{article}
\usepackage[showframe]{geometry}

\begin{document}
\noindent
\Huge
\textbf{.}

\noindent
\Large
\textbf{Some example text.}
\end{document}

Using the \flushleft command doesn't work either.

Making both the dot and the text \Large (or \Huge) fixes the problem.

Is there a way to make the dot perfectly align with the text below, independently from how large or small the text and the dot are? Will it mess something up when the dot is used in the regular text?

Thank you for your help.

Some screenshots to better illustrate what I mean:

enter image description here

Here the distances from the margin are different, like in the MWE

enter image description here

here they are the same as I'd like them to be (I've eyeballed it using \hspace).

6
  • Would you please show an approximation of the result you'd like to get? Sorry, but I can't understand.
    – egreg
    Oct 16, 2020 at 15:50
  • @egreg I've added two screenshots to better explain what I mean. Oct 16, 2020 at 16:05
  • It's still unclear what would be the use of this.
    – egreg
    Oct 16, 2020 at 16:12
  • @egreg it's a bit odd indeed. I'm writing a pamphlet -- quite a strange one -- which has a regular subtitle but a dot as the title. Oct 16, 2020 at 16:20
  • 1
    Does \makebox[0.5\width]{\textbf{.}} achieve what you want? You can increase the 0.5 factor to get it where you desire. Oct 16, 2020 at 16:32

1 Answer 1

2

The problem is related with the sidebearings.

The following code in lualatex shows the effect, turning the switch \dropsidebearings on and off. Courtesy of Marcel Krüger.

The references of the original Q&A are in the comments.

sidebearings and precision left/right alignment

Perfect alignment, LuaTex and sidebearings. Part II

A solution of the problem using xelatex is also shown in the first referenced question.

% !TeX TS-program = lualatex    
\documentclass[11pt, a5paper]{article}
\usepackage[showframe]{geometry}    
\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*}


\begin{document}
    
\dropsidebearings=1 
        
\noindent dropsidebearing =1

\noindent\textbf{.}

\noindent \textbf{Some example text.}

\dropsidebearings=0 

\noindent dropsidebearing =0

\noindent\textbf{.}

\noindent \textbf{Some example text.}
\end{document}

output

You must log in to answer this question.

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