1

Is there an equivalent of \linegoal that would work with tcolorbox raster (I can use some luatex trickery if needed)?

In the following MnWE, \the\linegoal does not give correct results.

\RequirePackage{luatex85} % To fix linegoal (https://tex.stackexchange.com/a/525363/8425)
\documentclass[convert={size=640}]{standalone}
\usepackage[most]{tcolorbox}
\usepackage{linegoal}

\begin{document}
% Example adapted from tcolorbox documentation
\begin{tcbitemize}[raster equal height=rows,raster columns=3,
title=\thetcbrasternum,colframe=red!50!black,colback=red!10!white]
\tcbitem[colframe=blue!50!black,colback=blue!10!white,raster multicolumn=1]
\the\linegoal
\tcbitem \the\linegoal
\tcbitem \the\linegoal
\tcbitem[colframe=blue!50!black,colback=blue!10!white,raster multicolumn=2]
\the\linegoal
\tcbitem \the\linegoal
\tcbitem[colframe=blue!50!black,colback=blue!10!white,raster multicolumn=3]
\the\linegoal
\tcbitem \the\linegoal
\tcbitem[colframe=blue!50!black,colback=blue!10!white,raster multicolumn=2]
\the\linegoal
\end{tcbitemize}
\end{document}

tcolorbox raster and \linegoal

1
  • Sorry for the color conversion artefacts in the image. For an unknown reason, some boxes are partially transparent in the converted png.
    – cjorssen
    Commented May 7, 2023 at 22:11

1 Answer 1

3

linegoal assumes every line (including the possibly first line indentation per paragraph) starts from the left-most margin of text body of a page. Simple outer-most lines meet this condition, but not the lines in quote and tcolorbox environments, which are usually shifted to right.

I just added an answer to question How can I use \linegoal properly inside minipages?. OP's current question is just a special case of that one.

Applying new commands \markLineStart{<name>} and \getLineGoal{<name>} provided in the mentioned answer to OP's tcbitemize example:

\documentclass{article}
\usepackage{lipsum}
\usepackage[raster]{tcolorbox}
\usepackage{zref-abspos}

\makeatletter
\IfFormatAtLeastTF{2021-06-01}{% to use hook "para/begin"
  \newcounter{xlinegoal}
  \newcommand{\markLineStart}[1]{%
    \AddToHookNext{para/begin}{\zsaveposx{xlinegoal@#1}}%
    \ignorespaces
  }
  \newcommand{\getLineGoal}[2][\xlinegoal]{%
    \stepcounter{xlinegoal}%
    \zsaveposx{xlinegoal@#2@\the\c@xlinegoal}%
    \edef#1{\noexpand\dimexpr\the\dimexpr\linewidth+\zposx{xlinegoal@#2}sp-\zposx{xlinegoal@#2@\the\c@xlinegoal}sp\relax}%
    \ignorespaces
  }
}{\PackageError{xlinegoal}{LaTeX2e 2021-06-01 or newer is needed}{}}
\makeatother

% test helpers
\def\testXLineGoal{%
  X\hfill X
  
  \getLineGoal{tcb@\thetcolorboxnumber}
  \leavevmode\rlap{\the\xlinegoal}\rule{\xlinegoal}{.4pt}%
}

\begin{document}

% Example adapted from tcolorbox documentation
\begin{tcbitemize}[
  raster equal height=rows,
  raster columns=3,
  title=\thetcbrasternum,
  colframe=red!50!black,
  colback=red!10!white,
  before upper={\markLineStart{tcb@\thetcolorboxnumber}}
]
  \tcbitem[colframe=blue!50!black,colback=blue!10!white,raster multicolumn=1]
    \testXLineGoal
  \tcbitem \testXLineGoal
  \tcbitem \testXLineGoal
  \tcbitem[colframe=blue!50!black,colback=blue!10!white,raster multicolumn=2]
    \testXLineGoal
  \tcbitem \testXLineGoal
  \tcbitem[colframe=blue!50!black,colback=blue!10!white,raster multicolumn=3]
    \testXLineGoal
  \tcbitem \testXLineGoal
  \tcbitem[colframe=blue!50!black,colback=blue!10!white,raster multicolumn=2]
    \testXLineGoal
\end{tcbitemize}
\end{document}

enter image description here

1
  • Really nice idea. Thanks!
    – cjorssen
    Commented May 16, 2023 at 10:35

You must log in to answer this question.

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