0

I've been trying to split highlighted text into lines and not go over the margin in the itemize environment, but linegoal calculates the wrong margin in itemize. Also, the highlighting always gets to the end of the line, not the end of the text. Is it possible to make it go to the end of the text instead? Thank you!

Minimal working example:

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

Thank you!

1 Answer 1

1

You need to issue \linegoal before doing the \parbox.

Here I add showframe just to show the margins of the text block.

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

enter image description here

You must log in to answer this question.

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