Let's say we want to get one or two paragraphs of text into a visible framed such that:
- the total width of the frame (including its borders) is the exactly same as the width of the surrounding text (in particular, the frame should NOT protrude into the right margin)
AND SIMULTANEOUSLY
- the frame stays on one page, i.e., the frame doesn't span multiple pages.
Here are my unsuccessful attempts so far:
\documentclass{article}
\usepackage{lipsum,framed}
\begin{document}
\vspace*{72ex}
\lipsum[1]
\begin{framed}%% NOT ON ONE PAGE!
\begin{samepage}%
\textbf{Some Title:}\par
\lipsum[2]%
\end{samepage}%
\end{framed}
\lipsum[3]
\par\medskip\noindent\fbox{\parbox{\textwidth}{%% GOES INTO THE RIGHT MARGIN; I dunno how to compute the width properly!
\indent\textbf{Some Title:}\par\indent%% first-line indents don't work!
\lipsum[4]
}}
\end{document}
yields
As you see, the upper frame spans over the page break, whereas the lower frame occupies more horizontal space than the usual text. (Moreover, unfortunately, the first-line indents don't work in the lower frame. However, this is not that bad; I can work around it.)
What to do?
EDIT: Based on John's suggestion, I've tried this:
\documentclass{article}
\usepackage{lipsum,framed}
\begin{document}
\vspace*{72ex}
\lipsum[1]
\par\addvspace{\topsep}\noindent
{\fboxsep=3\fboxsep
\fbox{\parbox{\dimexpr\textwidth-2\fboxsep-2\fboxrule}{%
\textbf{Some Title:}\\
\lipsum[2]
}}}\par\addvspace{\topsep}\indent
\lipsum[3]
\end{document}
It does the job:
However, the string of low-level commands is rather cumbersome and prone to error. Isn't there some command in some package that does this?
\parbox{dimexpr \textwidth-2\fboxsep-2\fboxrule}{...}
\parbox{\dimexpr \textwidth-2\fboxsep-2\fboxrule}{...}
?