tcolorbox 栅格内的 \linegoal 等效项?

tcolorbox 栅格内的 \linegoal 等效项?

是否有\linegoaltcolorbox栅格等效的东西(如果需要,我可以使用一些 luatex 技巧)?

在以下 MnWE 中,\the\linegoal没有给出正确的结果。

\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 栅格和 \linegoal

答案1

linegoal假设每行(包括每个段落可能的第一行缩进)从页面正文的最左边距开始。简单的最外层行符合此条件,但quotetcolorbox环境中的行不符合此条件,它们通常向右移动。

我刚刚添加了回答质疑如何在 minipages 中正确使用 \linegoal?。OP 当前的问题只是这个问题的一个特例。

应用新命令\markLineStart{<name>}\getLineGoal{<name>}在提到的回答以OPtcbitemize为例:

\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}

在此处输入图片描述

相关内容