\documentclass[a4paper]{article}
\usepackage[top=14mm, bottom=14mm, left=28mm, right=28mm]{geometry}
\usepackage{lipsum,framed,color}
\definecolor{shadecolor}{rgb}{1,0.8,0.3}
\newlength{\boxwidth}
\newsavebox{\boxcontainer}
\newenvironment{xlist}{%
\begin{list}{}{%
\setlength{\labelwidth}{5em}
\setlength{\labelsep}{1em}
\setlength{\leftmargin}{\labelwidth}
\addtolength{\leftmargin}{\labelsep}
\setlength{\rightmargin}{0pt}
\setlength{\parsep}{0.5ex plus 0.2ex minus 0.1ex}
\setlength{\itemsep}{0.3ex plus 0.2ex}
\renewcommand{\makelabel}[1]{\textsf{##1}\hfil}
}
}
{\end{list}}
\newcommand\mybox[1]{%
%\begin{center}%
\fcolorbox{black}{shadecolor}{%
\begin{minipage}[t]{\dimexpr\textwidth\fboxsep+10\fboxrule}%
#1%
\end{minipage}}%
%\end{center}
}
\begin{document}
% Settings for \mybox and Mybox
\setlength{\fboxrule}{1pt}
\setlength{\fboxsep}{10pt}
% Additional settings for MyBox
\setlength{\FrameRule}{\fboxrule}
\setlength{\FrameSep}{\fboxsep}
\begin{xlist}
\item[Solution 1]Here we we have sample text for this document to fill up space that says nothing at all in particular and just runs on filling space.\\[4mm]
\end{xlist}
\begin{xlist}
\item[Solution 2]Here we more have sample text for this document to fill up space that says nothing at all in particular and just runs on filling space.\\[4mm]
\end{xlist}
\mybox{
\textbf{Theorem 3.2}
\begin{center}
$\displaystyle x+\sin(x)$ Blah blah blah blah blah blah blah blah blah blah blah blah blah
\end{center}
}
\end{document}
Last edited by jaybz on Sat May 07, 2011 2:27 am, edited 1 time in total.
2. Your box is indented. Hence, even if it had textwidth, it would be shifted to the right and still won't be ligned up with the text body. The solution is to put a \noindent before it.
Best
I'm using pdfTeX, Version 3.1415926-1.40.10 (TeX Live 2009/Debian).
Is this what you mean? If it is, it still doesn't work. I just get a box that's almost the width of the page. It should be the width of the line to the right of "Solution 2"
\documentclass[a4paper]{article}
\usepackage[top=14mm, bottom=14mm, left=28mm, right=28mm]{geometry}
\usepackage{lipsum,framed,color}
\usepackage{calc}
\definecolor{shadecolor}{rgb}{1,0.8,0.3}
\newlength{\boxwidth}
\newsavebox{\boxcontainer}
\newenvironment{xlist}{%
\begin{list}{}{%
\setlength{\labelwidth}{5em}
\setlength{\labelsep}{1em}
\setlength{\leftmargin}{\labelwidth}
\addtolength{\leftmargin}{\labelsep}
\setlength{\rightmargin}{0pt}
\setlength{\parsep}{0.5ex plus 0.2ex minus 0.1ex}
\setlength{\itemsep}{0.3ex plus 0.2ex}
\renewcommand{\makelabel}[1]{\textsf{##1}\hfil}
}
}
{\end{list}}
\newcommand\mybox[1]{%
%\begin{center}%
\fcolorbox{black}{shadecolor}{%
%\begin{minipage}[t]{\dimexpr\textwidth-2\fboxsep+10\fboxrule}%
\begin{minipage}[t]{\textwidth-2\fboxsep}
#1%
\end{minipage}}%
%\end{center}
}
\begin{document}
% Settings for \mybox and Mybox
\setlength{\fboxrule}{1pt}
\setlength{\fboxsep}{10pt}
% Additional settings for MyBox
\setlength{\FrameRule}{\fboxrule}
\setlength{\FrameSep}{\fboxsep}
\begin{xlist}
\item[Solution 1]Here we we have sample text for this document to fill up space that says nothing at all in particular and just runs on filling space.\\[4mm]
\end{xlist}
\begin{xlist}
\item[Solution 2]Here we more have sample text for this document to fill up space that says nothing at all in particular and just runs on filling space.\\[4mm]
\end{xlist}
\noindent
\mybox{
\textbf{Theorem 3.2}
\begin{center}
$\displaystyle x+\sin(x)$ Blah blah blah blah blah blah blah blah blah blah blah blah blah
\end{center}
}
\end{document}
If I run pdflatex on the code you've posted, I get the PDF in the attachment. To my understanding, that box has the width of the text. If you want something different, please specify more clearly.
The right side of the box should be up against the right margin, which it is but the left side of the box isn't correct. Next to the "Solution 2" there is the line:
"all in particular and just runs on filling space."
The left side of the box should be under the "a" in "all"
So you actually want the box narrower than textwidth. It's not a big deal. Just subtract \leftmargin (6.0em in your case) from the width of the box and put
It would be of course a lot nicer to define a new length instead of specifying it explicitly so everything will scale smoothly, once you decide to change indentation of your list environment.
I'm using pdfTeX, Version 3.1415926-1.40.10 (TeX Live 2009/Debian).
\documentclass[a4paper]{article}
\usepackage[top=14mm, bottom=14mm, left=28mm, right=28mm]{geometry}
\usepackage{lipsum,framed,color}
\usepackage{calc}
\definecolor{shadecolor}{rgb}{1,0.8,0.3}
\newlength{\boxwidth}
\newsavebox{\boxcontainer}
\newenvironment{xlist}{%
\begin{list}{}{%
\setlength{\labelwidth}{5em}
\setlength{\labelsep}{1em}
\setlength{\leftmargin}{\labelwidth}
\addtolength{\leftmargin}{\labelsep}
\setlength{\rightmargin}{0pt}
\setlength{\parsep}{0.5ex plus 0.2ex minus 0.1ex}
\setlength{\itemsep}{0.3ex plus 0.2ex}
\renewcommand{\makelabel}[1]{\textsf{##1}\hfil}
}
}
{\end{list}}
\newcommand\mybox[1]{%
%\begin{center}%
\noindent\hspace{6.0em}\fcolorbox{black}{shadecolor}{%
%\begin{minipage}[t]{\dimexpr\textwidth-2\fboxsep+10\fboxrule}%
\begin{minipage}[t]{\textwidth-8\fboxsep}
#1%
\end{minipage}}%
%\end{center}
}
\begin{document}
% Settings for \mybox and Mybox
\setlength{\fboxrule}{1pt}
\setlength{\fboxsep}{10pt}
% Additional settings for MyBox
\setlength{\FrameRule}{\fboxrule}
\setlength{\FrameSep}{\fboxsep}
\begin{xlist}
\item[Solution 1]Here we we have sample text for this document to fill up space that says nothing at all in particular and just runs on filling space.\\[4mm]
\end{xlist}
\begin{xlist}
\item[Solution 2]Here we more have sample text for this document to fill up space that says nothing at all in particular and just runs on filling space.\\[4mm]
\end{xlist}
%\noindent
\mybox{
\textbf{Theorem 3.2}
\begin{center}
$\displaystyle x+\sin(x)$ Blah blah blah blah blah blah blah blah blah blah blah blah blah
\end{center}
}
\end{document}