Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create an environment for colored boxes #27

Open
tobiasdiez opened this issue Sep 14, 2023 · 2 comments
Open

Create an environment for colored boxes #27

tobiasdiez opened this issue Sep 14, 2023 · 2 comments

Comments

@tobiasdiez
Copy link

It would be nice if in addition to the colorbox command, one could also have it as an environment:

\begin{colorbox}[blue]
.... some longer content goes here ...
\end{colorbox}

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.

@Udi-Fogiel
Copy link

Udi-Fogiel commented Oct 1, 2023

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}

@dbitouze
Copy link

dbitouze commented Dec 4, 2023

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants