我一直试图将突出显示的文本拆分成行,并且不超过环境中的边距itemize
,但linegoal
在 中计算了错误的边距itemize
。此外,突出显示总是到达行尾,而不是文本的末尾。是否可以让它转到文本的末尾?谢谢!
最小工作示例:
\documentclass{book}
\usepackage{hyperref}
\usepackage{soul}
\usepackage[top=4cm,bottom=4cm,left=3cm,right=3cm,asymmetric]{geometry}
\usepackage[dvipsnames, table]{xcolor}
\usepackage{color, linegoal}
\begin{document}
\large
\colorbox{yellow}{\parbox[t]{\linegoal}{This is pretty much fine, I guess, but this doesn't really work in itemize environment, also if possible get rid of the yellow space to the right of this text.}}
\begin{itemize}
\item \colorbox{yellow}{\parbox[t]{\linegoal}{This doesn't work, it is short by a little, and if possible, get rid of the yellow space to the right of this text as well.}}
\end{itemize}
\end{document}
谢谢你!
答案1
您需要\linegoal
在执行之前发出\parbox
。
这里我添加的showframe
只是为了显示文本块的边距。
\documentclass{book}
\usepackage{soul}
\usepackage[top=4cm,bottom=4cm,left=3cm,right=3cm,asymmetric,showframe]{geometry}
\usepackage[dvipsnames, table]{xcolor}
\usepackage{linegoal}
\usepackage{hyperref}
\makeatletter
\newcommand{\highlightparbox}[1]{%
\noindent
\dimen@=\linegoal
\dimen@=\dimexpr\dimen@-2\fboxsep+\@totalleftmargin\relax
\colorbox{yellow}{\parbox[t]{\dimen@}{#1}}%
}
\makeatother
\begin{document}
\highlightparbox{This is pretty much fine, I guess, but this doesn't
really work in itemize environment, also if possible get
rid of the yellow space to the right of this text.}
\begin{itemize}
\item \highlightparbox{This doesn't work, it is short by a little,
and if possible, get rid of the yellow space to the right of
this text as well.}
\end{itemize}
\end{document}