在我的代码中,我有:
\newcommand{\headwarning}[1]%
{\needspace{4\baselineskip}\colorbox{darkboxcolor}{\parbox{\linewidth}{\color{lighttextcolor}\textbf{#1}}}\nopagebreak[0]\vspace{0mm}}%
\newcommand{\warning}[1]%
{\vspace{2px}{\textbf{#1}}\vspace{4px}}
颜色在其他地方定义。在文本部分:
\begin{wrapfigure}{r}{3cm}
\begin{tabular}{@{}c@{}}
\textcolor{blue}{\rule{3cm}{3cm}} \\% Dummy image replacement
\end{tabular}
\end{wrapfigure}
\headwarning{Lorem ipsum dolor sit amet}
\warning{Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet.}
但是头部警告框遮住了右侧的图片。我该如何正确缩短这个框?
最终的结果是,我追求的是这样的:
答案1
你可以使用包裹soul
进行突出显示:
\documentclass{article}
\usepackage{wrapfig}
\usepackage{xcolor}
\usepackage{soul}
\usepackage[demo]{graphicx}
\newcommand{\headwarning}[1]%
{\noindent\hl{#1}}
\newcommand{\warning}[1]%
{\vspace{2px}\noindent\textbf{#1}\vspace{4px}}
\begin{document}
\begin{wrapfigure}{r}{3cm}
\includegraphics[width=3cm,height=3cm]{dummy}
\end{wrapfigure}
\headwarning{Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet.}
\warning{Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet.}
\end{document}