Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Alignment in PDF

    Dear All,

    this is really exotic, and most users won't care, but I do. No econometrics involved in this whatsoever. Just hoping to get a nicely formatted output.

    Consider the following example:
    Code:
    local m="⬛"
    
    local f `"font("Consolas", 10, cyan)"'
    putpdf begin
    
    putpdf paragraph
        
        // output line 1
        putpdf text ("`m' ====================================== "*2), `f' linebreak(1)
        // output line 2
        putpdf text ("`m' These strings should be the same width ")  , `f'
        putpdf text ("`m' These strings should be the same width ")  , `f' linebreak(1)
        // output line 3
        putpdf text ("`m' These strings should be the same width ")  , `f' bold
        putpdf text ("`m' These strings should be the same width ")  , `f' linebreak(1)
        // output line 4
        putpdf text ("`m' These strings should be the same width ")  , `f' bold
        putpdf text ("`m' These strings should be the same width ")  , `f' bold linebreak(1)
        // output line 5
        putpdf text ("`m' ====================================== "*2), `f' linebreak(1)
    
    putpdf save "C:\temp\testpdf.pdf", replace
    
    // end of file
    If I look into the output with attention I see a problem (here zoomed and with some additional marking for clarification):
    Click image for larger version

Name:	pdf_output.png
Views:	1
Size:	36.4 KB
ID:	1741173



    Specifically, I don't care about the bold and non-bold square sizes to differ (green horizontal lines), this is normal, but I do care about the position of the squares, in that sense that the pixel-position of the non-bold square should be constant regardless of any previously written text, as long as the number of characters written previously in that line is the same between the two lines being compared (of course for a monospace font, which is used here - Consolas). It seems that writing some bold-text earlier affects the position of subsequent characters, and I don't understand whether this is something that can be compensated/eliminated or nothing can be done about it.

    (B) marks that that character was written with bold font, while (NB) - with non-bold font. The problem as I see it is in the line with the red arrow (which is "output line 3"). The box in output line 4 below it is bold, and so its alignment is not expected to match the alignment of the non-bold boxes.

    If the underlined expectation is non-reasonable, kindly explain why.

    PS: I believe this is properly observed in Stata's output window:

    Code:
    program define display_eq
    
        local m="⬛"
    
        // output line 1
        display `"`="`m' ====================================== "*2'"' "{break}"
        // output line 2
        display `"`m' These strings should be the same width "' _continue 
        display `"`m' These strings should be the same width "'   "{break}"
        // output line 3
        display `"{bf:`m' These strings should be the same width }"' _continue
        display `"`m' These strings should be the same width "'  "{break}"
        // output line 4
        display `"{bf:`m' These strings should be the same width }"' _continue
        display `"{bf:`m' These strings should be the same width }"' "{break}"
        // output line 5
        display `"`="`m' ====================================== "*2'"' "{break}"
    end
    
    display_eq
    Click image for larger version

Name:	output-boxes.png
Views:	1
Size:	11.5 KB
ID:	1741174



    Best, Sergiy
Working...
X