# Stackengine centering problem

I have a problem centering text with stackengine stacks. My MWE is:

\documentclass{article}
\usepackage{stackengine}
\begin{document}
\Shortstack[c]{Cognicion abstractiva}
\end{document}


The result is this:

(I measured the distances with Adobe Acrobat Pro.)

As you can see, the two texts fail to be centred. I noticed this behavior in all cases I use \Shortstack. Is this normal?

I think you are just not taking account of sidebearings of the characters so the actual character widths used for centering include some white space. TeX has no information about the glyph shape, it can not tell what parts of a specified character width are black.

\documentclass{article}
\usepackage{stackengine}
\begin{document}

$\left|\Shortstack[c]{Cognicion abstractiva}\right|$

$\left|\Shortstack[c]{\frame{Cognicion} \frame{abstractiva}}\right|$
\end{document}

• Is \frame equivalent to fbox? – NVaughan May 25 '16 at 14:46
• @NVaughan \frame is more or less \fbox with \fboxsep set to 0pt but it's from picture mode so the line thickness depends on \thinlines, \thicklines rather than \fboxrule – David Carlisle May 25 '16 at 14:52

This example should lift any doubt about what to measure; note that in the first two cases the hairlines are perfectly superimposed to each other, showing that there's no issue with \Shortstack.

On the other hand, the difference you measured is less than 0.4pt, too small to be really noticeable: it depends on the bounding boxes of the characters.

\documentclass{article}
\usepackage{color}
\usepackage{stackengine}
\newcommand{\hairline}[1][black]{%
\leavevmode\kern-0.05pt
\smash{\color{#1}\vrule height 20pt depth 20pt width 0.1pt}%
\kern-0.05pt
}
\begin{document}
\centering
\Shortstack[c]{\hairline{}XXXXXX\hairline{} XXXXXXXXXX}

\hairline{}XXXXXX\hairline{}\\ XXXXXXXXXX

\vspace{20pt}

\Shortstack[c]{%
\hairline[red]Cognicion\hairline[red]
\hairline[green]abstractiva\hairline[green]%
}
\end{document}


• Thanks. BTW, could you please explain to me the \hairline macro? – NVaughan May 25 '16 at 14:31
• @NVaughan I insert a rule that extends above and below the baseline by 20pt, occupying no horizontal space, because of the two kerns that kill the rule width; it takes no vertical space either, because of \smash. The \leavevmode is for ensuring the kern and \smash are seen when we're already typesetting a paragraph (so in horizontal mode). – egreg May 25 '16 at 14:46