8

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: enter image description here

(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?

11

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.

enter image description here

\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
  • 1
    @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
7

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}

enter image description here

  • Thanks. BTW, could you please explain to me the \hairline macro? – NVaughan May 25 '16 at 14:31
  • 1
    @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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.