I need a background shade in the running text of middle of a paragraph, I tried through \usepackage{tikz}
, I am getting background but text is not breaking and running beyond the text width.
How to fix automate breaking in a paragraph with shade?
MWE:
\documentclass{book}
\usepackage{soul}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{decorations.pathmorphing}
\renewcommand\hl[1]{%
\tikz[baseline,%
decoration={amplitude=1pt,segment length=15pt},%
outer sep=-15pt, inner sep = 0pt%
]%
\node[decorate,rectangle,fill=gray!50,anchor=text]{#1};%
}%
\begin{document}
In the \hl{following chapters} of the book we a \hl{In the following chapters of the book \protect\ensuremath{\alpha \beta \gamma} we are going to be fitting statistical models to data. The script or set of R commands necessary for their analyses, data sets in CSV (comma-separated values) format, and the R workspace containing the R objects created for each chapter can be found on the companion web site. ]\hl{The R packages needed to fit the models in each chapter are indicated at the start of each chapter} and can be loaded with the specified script.}
\end{document}
\hl
macro? If it is just for the color, you can use\colorlet{mygray}{gray!50} \sethlcolor{mygray}
.\ensuremath{}
is not working, when using\ensuremath
in the\hl{}
command shading is turned off from that position