Creating a frame

161 views
Skip to first unread message

Vahid Damanafshan

unread,
Dec 8, 2009, 2:16:31 PM12/8/09
to latexus...@googlegroups.com
Hi all,
I have written my thesis but now, I want to put a frame around all of my theorems like the attached picture.

Could anyone help me?

Thank you a lot.



--
--------------------------------------
وحید دامن افشان
Vahid Damanafshan
vdamana...@ms.tabrizu.ac.ir
vdaman...@yahoo.com
vdaman...@gmail.com
snopshot.png

Andrea

unread,
Dec 8, 2009, 3:57:03 PM12/8/09
to LaTeX Users Group
Hi, Vahid.

I think the thread you can find at [1] might be helpful.

Andrea

--
[1]http://www.latex-community.org/forum/viewtopic.php?
f=4&t=2731&p=10785


On Dec 8, 8:16 pm, Vahid Damanafshan <mathon...@gmail.com> wrote:
> Hi all,
> I have written my thesis but now, I want to put a frame around all of my
> theorems like the attached picture.
>
> Could anyone help me?
>
> Thank you a lot.
>
> --
> --------------------------------------
> وحید دامن افشان
> Vahid Damanafshan
> vdamanafsha...@ms.tabrizu.ac.ir
> vdamanafs...@yahoo.com
> vdamanafs...@gmail.com
>
>  snopshot.png
> 34KViewDownload

Vahid Damanafshan

unread,
Dec 8, 2009, 4:46:02 PM12/8/09
to latexus...@googlegroups.com
Thanks, Andrea
It's really great. But I want a frame around the theorems with a header like the attached picture.
Please help me.


--

You received this message because you are subscribed to the Google Groups "LaTeX Users Group" group.
To post to this group, send email to latexus...@googlegroups.com.
To unsubscribe from this group, send email to latexusersgro...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/latexusersgroup?hl=en.





--
--------------------------------------
وحید دامن افشان
Vahid Damanafshan

Donald Arseneau

unread,
Dec 9, 2009, 11:52:05 PM12/9/09
to LaTeX Users Group
On Dec 8, 11:16 am, Vahid Damanafshan <mathon...@gmail.com> wrote:
> I have written my thesis but now, I want to put a frame around all of my
> theorems like the attached picture.

It will probably take a redefinition of theorems to put the theorem
title
in the frame title, but the following might help

The \LabFrame command is the critical piece. With minor modifications
it
could work separately from framed.sty (and the "contlabelframe"
environment.

(Watch out for blank lines and other line breaks inserted by google.)


\usepackage{framed}

\newdimen\errorsize \errorsize=0.2pt
% Frame with a label at top
\newcommand\LabFrame[2]{%
\fboxrule=\FrameRule
\fboxsep=-\errorsize
\textcolor{FrameColor}{%
\fbox{%
\vbox{\nobreak
\advance\FrameSep\errorsize
\begingroup
\advance\baselineskip\FrameSep
\hrule height \baselineskip
\nobreak
\vskip-\baselineskip
\endgroup
\vskip 0.5\FrameSep
\hbox{\hskip\FrameSep \strut
\textcolor{TitleColor}{\textbf{#1}}}%
\nobreak \nointerlineskip
\vskip 1.3\FrameSep
\hbox{\hskip\FrameSep
\normalcolor #2%
\hskip\FrameSep}%
\vskip\FrameSep
}}%
}}
\definecolor{FrameColor}{rgb}{0.25,0.25,1.0}
\definecolor{TitleColor}{rgb}{1.0,1.0,1.0}


\newenvironment{contlabelframe}[2][\Frame@Lab\ (cont.)]{%
% Optional continuation label defaults to the first label plus
(cont.)
\def\Frame@Lab{#2}%
\def\FrameCommand{\LabFrame{#2}}%
\def\FirstFrameCommand{\LabFrame{#2}}%
\def\MidFrameCommand{\LabFrame{#1}}%
\def\LastFrameCommand{\LabFrame{#1}}%
\MakeFramed{\advance\hsize-\width \FrameRestore}
}{\endMakeFramed}

Anglea

unread,
Dec 10, 2009, 3:25:04 AM12/10/09
to LaTeX Users Group
Hi all

I was just about to post the same question, how to frame a theorem,
thanks ......I,ve done this but no frame appears so far, do I need to
add the command \LabFrame befora the theorem??

Anglea

Vahid Damanafshan

unread,
Dec 10, 2009, 3:12:05 PM12/10/09
to latexus...@googlegroups.com
Thanks, Donald,
But it is very complicated. How do I use it?
Please help me.

--

You received this message because you are subscribed to the Google Groups "LaTeX Users Group" group.
To post to this group, send email to latexus...@googlegroups.com.
To unsubscribe from this group, send email to latexusersgro...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/latexusersgroup?hl=en.


Donald Arseneau

unread,
Dec 10, 2009, 11:10:23 PM12/10/09
to LaTeX Users Group
On Dec 10, 12:12 pm, Vahid Damanafshan <mathon...@gmail.com> wrote:
> Thanks, Donald,
> But it is very complicated. How do I use it?

I'm not sure how you specifically put theorems in it. I'm pretty sure
it will involve defining a new theorem environment.

The useage is

\begin{contlabelframe}{Theorem 12.\ \ \ I'm always right}
Because I say so
\end{contlabelframe}

Donald Arseneau

Anglea

unread,
Dec 11, 2009, 4:32:42 AM12/11/09
to LaTeX Users Group
Thanks, Donald,
this is very helpful, but as my theorem need to go over the next page,
so the second part has got the title as well, I mean the upper frame,
another thing how can I increase the width of the frame, I tried to
play with all the parameter but nothing change.

many thanks
Anglea

Vahid Damanafshan

unread,
Dec 11, 2009, 8:38:10 AM12/11/09
to latexus...@googlegroups.com
Thanks, Donald,
That is it. It helped me very much.
Thanks again.

--

You received this message because you are subscribed to the Google Groups "LaTeX Users Group" group.
To post to this group, send email to latexus...@googlegroups.com.
To unsubscribe from this group, send email to latexusersgro...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/latexusersgroup?hl=en.


B0C.gif

Donald Arseneau

unread,
Dec 11, 2009, 5:20:50 PM12/11/09
to LaTeX Users Group
On Dec 11, 1:32 am, Anglea <hanyahamdi...@yahoo.com> wrote:
> but as my theorem need to go over the next page,
> so the second part has got the title as well,

I didn't follow... are you saying you need the second part to have the
title? That is what the answer using framed.sty accomplishes.

> another thing how can I increase the width of the frame,

Do you mean the total width, or the thickness of
the rules (lines)?

The total width is controlled by the setting of \hsize
on this line of the definition:

\MakeFramed{\advance\hsize-\width \FrameRestore}

The line thickness is set by \FrameRule.

Donald Arseneau

Vahid Damanafshan

unread,
Dec 12, 2009, 3:05:14 PM12/12/09
to latexus...@googlegroups.com
Thanks Donald,
By the way, What should I do if I want that the theorems are numbered automatically? (like Theorem 1.1, Theorem 1.2 ,...) Because the number of my theorems is very much.
Thanks again.

--

You received this message because you are subscribed to the Google Groups "LaTeX Users Group" group.
To post to this group, send email to latexus...@googlegroups.com.
To unsubscribe from this group, send email to latexusersgro...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/latexusersgroup?hl=en.


Donald Arseneau

unread,
Dec 12, 2009, 7:47:55 PM12/12/09
to LaTeX Users Group
On Dec 12, 12:05 pm, Vahid Damanafshan <mathon...@gmail.com> wrote:
> By the way, What should I do if I want that the theorems are numbered
> automatically?

That's what I meant when I said you would need to redefine a
theorem (or theorem+proof) environment. Take whatever theorem
environment you are currently using and substitute the
contlabelframe environment for the formatting portion.
Typically

\trivlist \item[<head>]
(body)
\endtrivlist

would be

\begin{contlabelframe}{<head>}
(body)
\end{contlabelframe}

Here, just because it is educational and very simple, we
can define a *Minimal Feature* theorem environment from
scratch:

% theorems numbered by chapter:
\newcounter{theorem}[chapter]

\newenvironment{theorem}[1]{%
\par
\refstepcounter{theorem}%
\begin{contlabelframe}{Theorem \thetheorem:\quad #1}
\noindent\ignorespaces}
{\end{contlabelframe}}

...

\begin{theorem}{I'm always right}
Because I say so
\end{theorem}

Vahid Damanafshan

unread,
Dec 14, 2009, 3:42:44 AM12/14/09
to latexus...@googlegroups.com
Thanks again, Donald.

--

You received this message because you are subscribed to the Google Groups "LaTeX Users Group" group.
To post to this group, send email to latexus...@googlegroups.com.
To unsubscribe from this group, send email to latexusersgro...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/latexusersgroup?hl=en.


Anglea

unread,
Dec 14, 2009, 1:00:43 PM12/14/09
to LaTeX Users Group
Thanks Donald,

I mean the theorem is a bit long, so it has to overcome on a second
page, the problem is the secnod part of the theorem has got a title
frame as well like the second one, but I do not want this, how can I
force it to give the blue stripe where the title is to appear just in
the first part.......

Also I meant by the width is total width of the frame arounf the
theorem, actaullt now it appears abit squzzing in the miiddle of the
page, if it is controlled by \MakeFramed{\advance\hsize-\width
\FrameRestore}, where should I make my change???

looking fo rhelp
Anglea

Donald Arseneau

unread,
Dec 14, 2009, 10:45:37 PM12/14/09
to LaTeX Users Group
On Dec 14, 10:00 am, Anglea <hanyahamdi...@yahoo.com> wrote:
>
> I mean the theorem is a bit long, so it has to overcome on a second
> page, the problem is the secnod part of the theorem has got a title
> frame as well like the second one, but I do not want this, how can I
> force it to give the blue stripe where the title is to appear just in
> the first part.......

OK, you will see in the definition there are four types of frame
declared: \FrameCommand, \FirstFrameCommand, \MidFrameCommand,
\LastFrameCommand, all with labels. You want something much
like the default \FrameCommand for "Mid" and "Last", except you
want to add a color for the frame. So this "Unlabelled Frame"
is:

\newcommand\UnLabFrame[1]{%
\fboxrule=\FrameRule
\fboxsep=\FrameSep
\textcolor{FrameColor}{\fbox{%
\normalcolor #1}}}

(There is no argument for the title, just the contents.)

Then to use this, you'd say:
...
\def\FrameCommand{\LabFrame{#1}}%
\def\FirstFrameCommand{\LabFrame{#1}}%
\def\MidFrameCommand{\UnLabFrame}%
\def\LastFrameCommand{\UnLabFrame}%
...

Also then, it isnt a *continued* label frame, so lets change the
name of the environment, and there is no desire for an optional
"continuation title" argument, so eliminate that, and get:

\newenvironment{onelabelframe}[1]{%
\def\FrameCommand{\LabFrame{#1}}%
\def\FirstFrameCommand{\LabFrame{#1}}%
\def\MidFrameCommand{\UnLabFrame}%
\def\LastFrameCommand{\UnLabFrame}%
\MakeFramed{\advance\hsize-\width \FrameRestore}
}{\endMakeFramed}

> Also I meant by the width is total width of the frame arounf the
> theorem, actaullt now it appears abit squzzing in the miiddle of the
> page, if it is controlled by \MakeFramed{\advance\hsize-\width
> \FrameRestore}, where should I make my change???

I still don't understand "abit squzzing". "\advance\hsize-\width"
means that the text of the theorem is narrower than the text on
the rest of the page by the width of the frame and the spacing.
(Therefore, the frame itself matches the surrounding text.)
If you want the theorem text to have the same width as the
surrounding text, and have the frame project into the margin,
then eliminate "\advance\hsize-\width".

The thickness of the line is controlled by \FrameRule, the spacing
around the theorem by \FrameSep. The vertical white-space before
and after the frame is \topsep, the same as used for the "center"
environment and normal theorems.

Donald Arseneau

sgmoye

unread,
Dec 20, 2009, 3:28:24 PM12/20/09
to LaTeX Users Group
Very neat -- I'll store this away for another day.

I played with this some, and there is something that I was not able to
do: to have more than one line in the label frame The text for the
label frame is put into an \hbox so that if there is too much text:

\begin{theorem}{This label just goes on for entirely too long to
be believed!}

it causes the entire frame to grow horizontally. Is there some way to
get the label text into a \vbox? I tried, but was getting odd
indentation.

Thanks

Stephen Moye

sgmoye

unread,
Dec 21, 2009, 5:06:30 AM12/21/09
to LaTeX Users Group
OK. I tried again. I thought to use \fcolorbox something like this:

...
\fcolorbox{FrameColor}{FrameColor}{%
\vbox{%
\nobreak
\advance\FrameSep\errorsize
\vskip 0.625\FrameSep
\hbox{%


\hskip\FrameSep
\strut
\textcolor{TitleColor}{\textbf{#1}}
}%

}%
...

having deleted the colored \hrule, and knowing that I'd have to format
the text in the \vbox. Seemed logical, but I'm getting an error that I
can't "use \prevdepth in horizontal mode." That was a little
unexpected...

Help?

Thanks

Stephen Moye

sgmoye

unread,
Dec 21, 2009, 11:47:28 AM12/21/09
to LaTeX Users Group
Well, it's not pretty and I would be glad of a cleaner approach, but
this is what I came up with:

\newcommand\LabFrame[2]{%
\parindent0pt%


\fboxrule=\FrameRule
\fboxsep=-\errorsize
\textcolor{FrameColor}{%

\fbox{%


\vbox{%
\nobreak
\advance\FrameSep\errorsize

\begingroup
\advance\baselineskip\FrameSep
\hrule height \baselineskip
\nobreak
\vskip-\baselineskip
\endgroup

\vskip 0.625\FrameSep%** Use to center text vertically
\vbox{%


\fcolorbox{FrameColor}{FrameColor}{%
\vbox{%

\leftskip\FrameSep
\rightskip\FrameSep plus 1fill
\strut
\textcolor{TitleColor}{%
\textbf{%
#1%
\vrule width0pt depth10pt%
}%
}%
}%
}%
}%
\nobreak
\nointerlineskip
\vskip 1.25\FrameSep%** Use to adjust distance after framed
text
\hbox{%


\hskip\FrameSep
\normalcolor #2%
\hskip\FrameSep
}%
\vskip\FrameSep
}%

}%
}%
}%

Suggestions, anyone?

Stephen Moye

Kumaresh PS

unread,
Dec 22, 2009, 2:42:08 AM12/22/09
to latexus...@googlegroups.com
Hi All,
 
I have done my own macro with the help from the packages "framed & color". Here in below, I have placed the same macro for your view. For detailed view please find the attached TEX & PDF file:
 
\newenvironment{thmenv}[1][]{%
   \bgroup%
   \gdef\@tempa{#1}%
   \ifx\@tempa\@empty\def\theoremsep{}\fi%
   \refstepcounter{thmenv}%
   \global\thmenvtrue%
   \def\FrameCommand{\fboxrule=\FrameRule\FrameRule.5\p@\fboxsep=\FrameSep\fcolorbox{FrameColor}{white}}%
   \def\FrameHeightAdjust{12\p@}%
   \setbox\thm@a@box\vbox{%
      \@hangfrom{\thm@head}%
      \ifx\@tempa\@empty%
         {\thmenvheadtextfont\dummyalphabet\par}%
      \else%
         {\thmenvheadtextfont#1\dummyalphabet\par}%
      \fi%
   }%
   \thm@a@dim\ht\thm@a@box%
   \advance\thm@a@dim by 12\p@%
   \noindent\colorfull{\rule{\textwidth}{\thm@a@dim}}%
   \par\vspace*{-\thm@a@dim}%
   \ifdim\ht\thm@a@box<10\p@%
      \vspace*{2.3\p@}
      \whitetext{\copy\thm@a@box}%
      \vspace*{2.3\p@}%
   \else%
      \vspace*{5\p@}%
      \whitetext{\copy\thm@a@box}%
      \vspace*{2\p@}%
   \fi%
   \vspace*{-\topsep}%
   \begin{framed}%
   \thmenvbodyfont%
}{%
   \end{framed}
   \global\thmenvfalse%
   \egroup%
   \addvspace{18\p@\@plus2\p@\@minus2\p@}%
}
Best of LUCK.
 
Kumaresh PS
creating-frame.pdf
creating-frame.tex

Donald Arseneau

unread,
Dec 22, 2009, 5:25:38 AM12/22/09
to LaTeX Users Group
On Dec 21, 11:42 pm, Kumaresh PS <pskumares...@gmail.com> wrote:
> Here in below, I have placed the same macro for your view.

Both of these look fine.

One caution, that goes back to a problem with the one I posted,
is that you can get funny widths when you use a wide title text
as part of \FrameCommand and also adjust the text width by
"\advance\hsize-\width". The intent is that \width indicates
the width added to the sides by the frame command, but if there
is a wide title, it may give a false \width adjustment.

One solution is to adjust \hsize like:
\MakeFramed{%
\advance\hsize-2\FrameSep \advance\hsize-2\Framerule
\FrameRestore}
Then the title will not influence the side-widths.

The title needed to be part of \FrameCommand in my original
because it was a REPEATING title. Since it is now used only
at the top, it doesn't need to be part of \FrameCommand,
as Kumaresh has shown. This is a good method.

Perhaps there should be a \@nobreaktrue before \begin{framed}
to ensure that \framed does not cause a page break between
the title and the body. Then a \needspace (from various
packages/classes) above the title would ensure there is room
for the title plus a bit of the body.


Donald Arseneau

sgmoye

unread,
Dec 22, 2009, 9:13:53 AM12/22/09
to LaTeX Users Group
It bothered me that, having put the text of the title into a \vbox and
used \fcolorbox, that I left the colored \hrule in place -- it isn't
needed now. Here is the corrected macro:

\newcommand\LabFrame[2]{%
\parindent0pt%
\fboxrule=\FrameRule
\fboxsep=-\errorsize

\color{FrameColor}{%


\fbox{%
\vbox{%
\nobreak
\advance\FrameSep\errorsize

\vbox{%
\fcolorbox{FrameColor}{FrameColor}{%
\vbox{%
\vskip 0.625\FrameSep%** Use to center text vertically
\leftskip\FrameSep
\rightskip\FrameSep plus 1fill
\strut
\textcolor{TitleColor}{%
\textbf{%
#1%
\vrule width0pt depth10pt%
}%
}%
}%
}%
}%
\nobreak
\nointerlineskip

\vskip 1\FrameSep%** Use to adjust distance after framed text


\hbox{%
\hskip\FrameSep
\normalcolor #2%
\hskip\FrameSep
}%
\vskip\FrameSep
}%
}%
}%
}%

Reply all
Reply to author
Forward
0 new messages