3

I realized that if you put the length here:

attach boxed title to top left={yshift=<length>}

in pt, mm or cm, the title box is shifted.

If you put it in ex or em, it is not.

Is it a tcolorbox bug?

\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{mwe}

\begin{document}

\begin{tcolorbox}[title=My title, 
    enhanced,
    attach boxed title to top left={yshift=-40pt},
    ]
    With \texttt{pt} (or \texttt{mm}, or \texttt{cm}) the positioning works
\end{tcolorbox}

\vspace{30pt}

\begin{tcolorbox}[title=My title, 
    enhanced,
    attach boxed title to top left={yshift=-4ex},
    ]
    With \texttt{ex} (or \texttt{em}) it doesn't work
\end{tcolorbox}

\end{document}

enter image description here

5

It works it's just not that useful.

em is a font specific length and without tracing all the code you can take a guess of the font in force at that point if you add

\def\nullfont{\ERROR}

before the box then you get

! Undefined control sequence.
\nullfont ->\ERROR 

l.11 

which isn't that useful other than it tells you that \nullfont is being used.

\nullfont is a built in font with no characters and 1em is 0pt....

5
  • it is in \pgf@picture. Patching it to remove the \nullfont makes the yshift work, but there is extra horizontal shift (of the whole thing and even more of the title) presumably from space tokens. – user4686 May 1 '18 at 10:12
  • Ah, so it's like setting 0pt, but why does it normally work in tikz? – CarLaTeX May 1 '18 at 10:13
  • @CarLaTeX I refer you to the last sentence of tex.stackexchange.com/a/97556/1090 – David Carlisle May 1 '18 at 10:14
  • @DavidCarlisle trying to squeeze some extra rep by posting that link? – Skillmon May 1 '18 at 11:16
  • 1
    It doesn't work in normal tikz either (for the same reason). Try e.g. xxx \tikz{\coordinate(a) at (0,0);\draw[green] ([yshift=4mm]a)--++(2,0);\draw[red] ([yshift=4em]a)--++(2,0);}. It works inside nodes as there a font is active. – Ulrike Fischer May 1 '18 at 11:46
1

Just for fun: the following works. But depending on the order things are executed in the entrails of tcolorbox and tikz, it may fail in other cases.

\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{mwe}

\newdimen\myex
\newcommand*{\getex}{\global\myex=1ex}

\begin{document}

\begin{tcolorbox}[title=My title\getex, 
    enhanced,
    attach boxed title to top left={yshift=-10.2\myex},
    ]
    With \texttt{1ex} stored in the title it works
\end{tcolorbox}

\vspace{30pt}

\begin{tcolorbox}[title=My title, 
    enhanced,
    attach boxed title to top left={yshift=-10.2\myex},
    ]
    \getex With \texttt{1ex} stored in the text it works
\end{tcolorbox}

\end{document}

enter image description here

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.