我需要在段落中间的连续文本中添加背景阴影,我尝试过\usepackage{tikz}
,我得到了背景,但文本没有中断且超出文本宽度。
如何修复带有阴影的段落自动换行问题?
梅威瑟:
\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}
答案1
该soul
软件包使用复杂的算法来加下划线和高亮显示以允许换行。如果你替换宏\hl
,你实际上会覆盖这种复杂的方法。
如果您只想更改阴影的颜色,则应使用\sethlcolor
包提供的宏。请注意,您不能gray!50
直接插入修改后的颜色,而需要先使用此值定义自定义颜色。
请注意在代码中正确设置花括号。如果与突出显示冲突,您可以尝试将内容放在框内:
\documentclass{book}
\usepackage{soul, xcolor}
\colorlet{mygray}{gray!50}
\sethlcolor{mygray}
\begin{document}
In the \hl{following chapters} of the book we a
\hl{In the following chapters of the book \mbox{\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}