Consider this 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}
How can I adjust the perimeter of the colorbox to 'wrap' around the text like this? I'd still like all the same functionality of automatic line breaks etc.
UPDATE
I tried using soul but that ran into issues with \textcolor{white}. Based on the recommendation from this answer (https://tex.stackexchange.com/a/48549/187447) I tried using ulem. But still I can't get a black polygon to wrap around text. Any ideas?
\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}





ulemmight be useful. – daleif Apr 25 '19 at 15:18soul? – Apr 25 '19 at 15:35soul. However, it won't let me usetextcolor{white}- something to do with this I think - https://tex.stackexchange.com/questions/48501/soul-broken-highlighting-with-xcolor-when-using-selectcolormodel – Mike Apr 25 '19 at 15:44\usepackage{soul}and add\sethlcolor{black} \begingroup\lineskip -2pt \noindent\textcolor{white}{\Huge\MakeUppercase{\hl{\titleText}}} \endgroupthen I get something that looks good except for a small gap which I thought to cure with\lineskip -2ptbut it doesn't work. – Apr 25 '19 at 15:50ulem, added an update to my question. – Mike Apr 25 '19 at 15:52