The following code comes from this SE query: Can I centre my oversized coffin of unknown width?. It was posted by @cfr and accompanied by output, so, presumably, it worked at one time:
\begin{filecontents}{pic.tex}
\documentclass{standalone}
\begin{document}
\begin{tikzpicture}
\shade [left color=Cerulean, right color=Cerulean, middle color=MidnightBlue] (0,0) rectangle (200mm,10mm);
\end{tikzpicture}
\end{document}
\end{filecontents}
\documentclass[a4paper,x11names,svgnames,dvipsnames]{article}
\usepackage{geometry,standalone,tikz,xcoffins,calc}
\begin{document}
\NewCoffin\TestCoffin
\SetHorizontalCoffin\TestCoffin{\input{pic}}
\MarkCoffinHandle\TestCoffin[hc,vc]{magenta}
\MarkCoffinHandle\TestCoffin[l,vc]{magenta}
Can I centre the coffin \emph{without} knowing the width of the picture?
This works:\par
\noindent
\TypesetCoffin\TestCoffin[l,vc](-.5\CoffinWidth\TestCoffin+.5\textwidth,0pt)
\bigskip
This doesn't:\par
{\centering
\TypesetCoffin\TestCoffin[hc,vc]\par}
\end{document}
When I run that code now, it fails with the following error:
./Coffin_mwe_001.tex:22: Illegal unit of measure (pt inserted).
<to be read again>
.
l.22 ...5\CoffinWidth\TestCoffin+.5\textwidth,0pt)
If I delete the fractional factor .5 from -.5\CoffinWidth\TestCoffin to make it -\CoffinWidth\TestCoffin/2 then the code works, though division by non-integers, not surprisingly, does not work. Note also that integer factors to \CoffinWidth also work correctly.
I cannot seem to find discussion of this on SE. Is there a workaround?
\begin{center}\makebox[0pt][c]{<almost anything>}\end{center}. Most likely this results from the parsing rules of\dimexpr. Take a look here. – Skillmon Nov 07 '18 at 17:48\CoffinWidth. I'll make my question more specific. – sgmoye Nov 07 '18 at 17:51.5\dimexpr\CoffinWidth\TestCoffin\relaxas a workaround. – Skillmon Nov 07 '18 at 17:56\CoffinWidthexpands to\dim_eval:n { \coffin_wd:N #1 }.\dim_eval:nexpands to\dim_use:N \__dim_eval:w #1\__dim_eval_end:which is the same as\the\dimexpr#1\relax. And you can't use a factor on\the. So we have to somehow turn this back into something where we can use a factor on. That something can be a\dimexprwithout a\thebefore it. – Skillmon Nov 07 '18 at 18:00.. Neither the-nor the number seem to be the problem. – sgmoye Nov 07 '18 at 18:11-2\CoffinWidth\TestCoffinthe code TeXs so the problem would seem to be fractional factors. The\dimexprtrick does work. – sgmoye Nov 07 '18 at 18:20