Open tobiasdiez opened 1 year ago
You can simply define your own environment. For example
\documentclass{article}
\usepackage{xcolor}
\NewDocumentEnvironment{cb}{O{blue}b}{%
\colorbox{#1}{#2}%
}
\begin{document}
\begin{cb}
Test
\end{cb}
\begin{cb}[red]
Test
\end{cb}
\end{document}
@Udi-Fogiel It doesn't give the expected result in case long text: it is composed on a single line and protrudes into the right margin. An improvement would be to rely on \parbox
.
It would be nice if in addition to the
colorbox
command, one could also have it as an environment:This is especially handy in a setting where the content is long, or if one wants to define own environments using colored boxes.
The package tcolorbox provides such a functionality, but it seems a bit wasteful to load it in addition to
xcolor
.