2

I have a document which has a right aligned two line header. Said header is created using scrlayer-scrpage. When I also try to enable the microtype package the two lines do not line up at the right and the second line is shifted a bit to the left. A minimal working example is provided below:

% !TeX TS-program = lualatex
\documentclass{scrartcl}
\usepackage{lua-visual-debug}

\usepackage{microtype}
\usepackage{scrlayer-scrpage}

% CONFIGURATION
\pagestyle{scrheadings}
\setkomafont{pagehead}{\normalfont} % reset \slshape

\ohead{
| Test ()\\
| Test ()%
}

\begin{document}
  \begin{flushright}
    | Test ()\\
    | Test ()%
  \end{flushright}
\end{document}

This occurs in PDFLaTeX, XeLaTeX and LuaLaTeX as far as I can tell. Removing the line which changes the font for the head does not remove the issue though it is far less noticeable. The lua-visual-debug packages helps visualize the boxes a bit better.

Strangely the error does not occur in the body. For now I could revert to getting along without the microtype package though if it is an error on my side I would like to get it fixed and if it is a bug inside the microtype or scrlayer-scrpage I would like to report a bug to help them fix it.

misaligned lines in header

1 Answer 1

3

There's no error on your part, but it's not a bug either. The misalignment is due to the fact that scrlayer-scrpage inserts a \strut at the end of the header (to ensure uniform line spacing), which prevents microtype (or rather the respective engine) from seeing the end-of-line. There are two possible workarounds:

  • Either disable protrusion in the first line, too, by inserting a strut:

    \ohead{%
    | Test ()\strut\\
    | Test ()%
    }
    
  • Or reconstruct the protrusion by means of the primitive \rightmarginkern (which is available in all three engines):

    \makeatletter
    \newdimen\right@margin
    \newcommand*\protruderight[1]{%
      \vbox{\everypar{}%
        \setbox\@tempboxa\vbox{\noindent#1}%
        \unvbox\@tempboxa \setbox\@tempboxa=\lastbox
        \global\right@margin=\rightmarginkern\@tempboxa
      }%
      #1\kern\right@margin
    }
    \makeatother
    
    \ohead{%
    | Test ()\\
    | Test (\protruderight{)}%
    }
    

[luatex offers the primitive \protrusionboundary, which is supposed to simplify this, but I actually couldn't get it to work -- even the example in the doc doesn't seem to work as advertised.]

You must log in to answer this question.

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