0

I am writing up a document where I frequently want to put multiple paragraphs of text inside a box. I am doing this with

\framebox{\begin{minipage}{0.95 \textwidth}
Here is how you solve this problem.

Here is more of the solution.
\end{minipage}}

I wanted to make my work easier by defining an environment for this, so I tried:

\newenvironment{soln}
   {
     \framebox{\begin{minipage}{0.95 \textwidth}
   }
   {
     \end{minipage}}
   }
   

Not surprisingly, this gives the "Extra }, or forgotten \endgroup" error when I try to use this environment. What is the correct way to do this?

1
  • something I made for my self in the answer below -- may appeal -- or not -- have alook
    – js bibra
    Feb 14 at 3:57
1

With framebox and width box width equal to text width:

\documentclass{article}
\usepackage{lipsum}

\newsavebox\solbox
\makeatletter
\newenvironment{sol}%
{
\@parboxrestore%
\begin{lrbox}{\solbox}%
\begin{minipage}{\dimexpr\linewidth-2\fboxsep-2\fboxrule}%
}
{\end{minipage}\end{lrbox}
\framebox{\usebox\solbox}
}
\makeatother

\begin{document}
\begin{sol}
\lipsum[1][1-3]

\lipsum[1][4-6]
\end{sol}
\end{document}

enter image description here

If you like to have narrower framebox centered in text, than you can use the following solution:

\documentclass{article}
\usepackage{lipsum}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\newsavebox\solbox
\makeatletter
\newenvironment{sol}%
{
\@parboxrestore%
\begin{lrbox}{\solbox}%
\begin{minipage}{0.8\linewidth}
}
{\end{minipage}\end{lrbox}%
\begin{center}
\framebox{\usebox\solbox}
\end{center}
}
\makeatother

\begin{document}
\begin{sol}
\lipsum[1][1-3]

\lipsum[1][4-6]
\end{sol}
\end{document}

enter image description here

(red lines show text boeders)

1

enter image description here

\documentclass[a4paper]{report} 
\usepackage{pdfrender,xcolor}
\usepackage{palatino}
\pdfrender{StrokeColor=black,TextRenderingMode=2,LineWidth=0.2pt}
\usepackage[most]{tcolorbox}
%\usepackage{array, tabularx}
%\usepackage{booktabs}


\newtcbtheorem[auto counter]{myBox}{Project}{separator sign={\ :}}{myBox}
            
            \newlength\mylength
                \settowidth\mylength{Contract Placing Authority}
                \setlength\mylength{\dimexpr\mylength+\tabcolsep+\arrayrulewidth\relax}
                
        
        \newlength\mylowerlength
        \settowidth\mylowerlength{77 SSS 2020}
        \setlength\mylowerlength{\dimexpr\mylowerlength+\tabcolsep+\arrayrulewidth\relax}
        
\begin{document}
    \begin{myBox}[grow to right by=3cm,grow to left by=3cm,]{K9}{}
        Assignment List -- Policy\\
        Assignemnt List noting sheet\\
        Cables from battery\\
        CES\\
        Assignment list -- forward for approval 
        \begin{myBox}{MAG 15}{}
21 items\\
        \end{myBox}
    \begin{myBox}{MAG 20}{}
Signature
    \end{myBox}
    \end{myBox}\newpage

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.