考虑一下这个MWE:
\documentclass[11pt]{article}
\usepackage[left=1.5cm,top=2.5cm,right=3.5cm,bottom=3.2cm,a4paper]{geometry}
\usepackage{xcolor}
\usepackage{adjustbox}
\usepackage{setspace}
\usepackage{blindtext}
\usepackage{microtype}
\setstretch{1.3}
\setlength{\fboxsep}{0.4cm} % sets the perimeter around \colorbox
\newcommand{\titleText}{My really really long title goes here}
\begin{document}
\begingroup\setstretch{2.3}
\noindent \colorbox{black}{\parbox{0.95\linewidth}{\raggedright\textcolor{white}{\Huge \expandafter\MakeUppercase\expandafter{\titleText}}}}
\endgroup
\vspace*{2cm}
\blindtext
\end{document}
我如何调整周长colorbox
以像这样“环绕”文本?我仍然希望拥有自动换行等所有相同的功能。
更新
我尝试使用soul
,但遇到了问题\textcolor{white}
。根据这个答案的建议(https://tex.stackexchange.com/a/48549/187447) 我尝试使用ulem
。但仍然无法让黑色多边形环绕文本。有什么想法吗?
\documentclass[11pt]{article}
\usepackage[left=1.5cm,top=2.5cm,right=3.5cm,bottom=3.2cm,a4paper]{geometry}
\usepackage{xcolor}
\usepackage{adjustbox}
\usepackage{setspace}
\usepackage{blindtext}
\usepackage{microtype}
\setstretch{1.3}
\setlength{\fboxsep}{0.4cm} % sets the perimeter around \colorbox
\newcommand{\titleText}{My really really long title goes here}
\usepackage[normalem]{ulem} % use normalem to protect \emph
\newcommand\hl{\bgroup\markoverwith
{\textcolor{black}{\rule[-6.5ex]{100pt}{14.5ex}}}\ULon}
\begin{document}
\begingroup\setstretch{2.3}
\noindent \hl{\parbox{0.95\linewidth}{\raggedright\textcolor{white}{\Huge \expandafter\MakeUppercase\expandafter{\titleText}}}}
\endgroup
\vspace*{2cm}
\blindtext
\end{document}
答案1
这不是一个完整的答案(因为存在一个小差距)但表明我没有遇到soul
你所描述的问题。
\documentclass[11pt]{article}
\usepackage[left=1.5cm,top=2.5cm,right=3.5cm,bottom=3.2cm,a4paper]{geometry}
\usepackage{xcolor}
\usepackage{adjustbox}
\usepackage{setspace}
\usepackage{blindtext}
\usepackage{microtype}
\usepackage{soul}
\setstretch{1.3}
\newcommand{\titleText}{My really really long title goes here}
\begin{document}
\sethlcolor{black}
\begingroup\lineskip -2pt
\noindent\textcolor{white}{\Huge\MakeUppercase{\hl{\titleText}}}
\endgroup
\vspace*{2cm}
\blindtext
\end{document}
如果我添加(来自这个答案)
\makeatletter
\def\SOUL@hlpreamble{%
\setul{\dp\strutbox}{\dimexpr\ht\strutbox+\dp\strutbox\relax}%
\let\SOUL@stcolor\SOUL@hlcolor
\SOUL@stpreamble
}
\makeatother
我明白了