I'm dealing with a document where I need to write some text within a box. The current code I'm using was kindly suggested by @campa. It ensures the following features:
The box adapts itself to the sentence, in this way when I write a short sentence, the box will not appear with any blank space.
The code allows the user to change the box width (It would be useful being able to control also height) and it doesn't set by default the entire line width. In this way larger sentences can be compressed as you like.
When the text breaks, the next line starts aligned with - or just slightly after - the colon.
Here some example:
And here the current code:
\documentclass{article}
\newcommand{\foo}[3][\linewidth]{%
\par\noindent
\sbox0{\fbox{\textbf{#2:}\quad#3}}%
\ifdim\wd0<#1%
\usebox0%
\else
\sbox0{\textbf{#2:}}%
\fbox{%
\copy0
\quad
\parbox[t]{\dimexpr#1-1em-\wd0-2\fboxsep-2\fboxrule\relax}{#3}%
}%
\fi
}
\begin{document}
Some random text just to show where the margins are.
Some random text just to show where the margins are.
Some random text just to show where the margins are.
\foo{Assumption}{This is a box.}
\foo{Assumption}{This is a longer box.}
\foo{Assumption}{This is a box almost one line long.}
\foo{Assumption}{This is a box more than one line long.}
\foo{Assumption}{This is the box where I would like the text
to be aligned with the colon when it starts a new line.}
\foo[.8\linewidth]{Example}{\raggedright An example with optional parameter
giving the maximal width, here set to \texttt{.8\string\linewidth}.}
\end{document}
Is there a way to make the corners of the box rounded instead of angular? The radius of curvature shouldn't be exaggerated, just good looking.
Bonus option: It would be also great to be able to decide whether or not get a shadowed box.
I know there is a package called tcolorbox
. Is it possible to get the whole result with it?
An example of a rounded-corner box I'm looking for:
I thank everyone who can give me a hand!