Discussion:
new environment to center a fbox
(too old to reply)
Gabriele Zucchetta
2005-03-21 14:09:26 UTC
Permalink
Hi,
I need to obtain this

------------------
| Text text text.|
------------------

center to the page, and I use:

\begin{center}
\fbox{
Text text text.
}\end{center}

But I have 2 questions:

1) Why this form don't works:

\fbox{\begin{center}Text text text.\end{center}}

2) I need to define this whit new environment. I have tried this:

\newenvironment{mycenterbox}{\fbox{\begin{center}}{\end{center}}}


and this is similar to the example that I have found in the
facybox.sty manual (pag. 3), but this not work, why?

zucchi
Ulrike Fischer
2005-03-21 14:59:52 UTC
Permalink
Post by Gabriele Zucchetta
Hi,
I need to obtain this
------------------
| Text text text.|
------------------
\begin{center}
\fbox{
Text text text.
}\end{center}
\fbox{\begin{center}Text text text.\end{center}}
First because \fbox can only contain horizontal material (= one line
not more). Second because even if it would work it would center the
text _in_ the box and not the box itself.
Post by Gabriele Zucchetta
\newenvironment{mycenterbox}{\fbox{\begin{center}}{\end{center}}}
and this is similar to the example that I have found in the
facybox.sty manual (pag. 3), but this not work, why?
It isn't similar to an example in the fancybox manual.

First fancybox use a minipage inside the \fbox-command (minipages are
boxes, while center are not),

Second the manual says clearly that the example is an example you
_can't_ use! It has unbalanced braces in its argument, so it doesn't
work. Look at the following pages to learn how you can do it.
--
Ulrike Fischer
e-mail: zusätzlich meinen Vornamen vor dem @ einfügen.
e-mail: add my first name between the news and the @.
Robin Fairbairns
2005-03-21 15:02:04 UTC
Permalink
Post by Gabriele Zucchetta
I need to obtain this
------------------
| Text text text.|
------------------
\begin{center}
\fbox{
Text text text.
}\end{center}
fair enough.
Post by Gabriele Zucchetta
\fbox{\begin{center}Text text text.\end{center}}
because it talks about centring text inside the \fbox, which isn't
what you want to do (and isn't allowed, either).
Post by Gabriele Zucchetta
\newenvironment{mycenterbox}{\fbox{\begin{center}}{\end{center}}}
and this is similar to the example that I have found in the
facybox.sty manual (pag. 3), but this not work, why?
it's not similar to the example in the manual: as near as makes no
difference, it's the same as your question (1) which doesn't do the
job and falls foul of a check for this sort of error in latex.

the fancybox example works because it's putting the stuff in a
minipage (which is a box, itself); once the minipage is complete, its
contents get \fbox'ed.

you could either do the same (adding \begin{center} before \fbox and
after \end{minipage}, in the example, or you could to the standard

\newsavebox{\zzz}
\newenvironment{mycenterbox}{\begin{lrbox}{\zzz}}%
{\end{lrbox}\fbox{\usebox{\zzz}}}
--
Robin (http://www.tex.ac.uk/faq) Fairbairns, Cambridge
Robin Fairbairns
2005-03-21 15:17:49 UTC
Permalink
Post by Robin Fairbairns
\newsavebox{\zzz}
\newenvironment{mycenterbox}{\begin{lrbox}{\zzz}}%
{\end{lrbox}\fbox{\usebox{\zzz}}}
but that omits the actual centring. that is left as an exercise for
the reader ...
--
Robin (http://www.tex.ac.uk/faq) Fairbairns, Cambridge
Gabriele Zucchetta
2005-03-21 16:35:38 UTC
Permalink
Post by Robin Fairbairns
but that omits the actual centring. that is left as an exercise for
the reader ...
\newsavebox{\zzz}
\newenvironment{mycenterbox}{\begin{center}\begin{lrbox}{\zzz}}%
{\end{lrbox}\fbox{\usebox{\zzz}}\end{center}}

done.

zucchi
Igor Pechtchanski
2005-03-21 18:47:29 UTC
Permalink
Post by Gabriele Zucchetta
Hi,
I need to obtain this
------------------
| Text text text.|
------------------
\begin{center}
\fbox{
Text text text.
}\end{center}
[snip]
\newenvironment{mycenterbox}{\fbox{\begin{center}}{\end{center}}}
\newsavebox{\mycbox}
\newenvironment{mycenterbox}{%
\begin{center}\begin{lrbox}{\mycbox}%
}{%
\end{lrbox}\fbox{\usebox{\mycbox}}\end{center}}

This doesn't properly deal with nesting, but it should give you the idea.
HTH,
Igor
--
http://cs.nyu.edu/~pechtcha/
|\ _,,,---,,_ ***@cs.nyu.edu
ZZZzz /,`.-'`' -. ;-;;,_ ***@watson.ibm.com
|,4- ) )-,_. ,\ ( `'-' Igor Pechtchanski, Ph.D.
'---''(_/--' `-'\_) fL a.k.a JaguaR-R-R-r-r-r-.-.-. Meow!

"The Sun will pass between the Earth and the Moon tonight for a total
Lunar eclipse..." -- WCBS Radio Newsbrief, Oct 27 2004, 12:01 pm EDT
Donald Arseneau
2005-03-21 22:55:49 UTC
Permalink
Post by Gabriele Zucchetta
\fbox{\begin{center}Text text text.\end{center}}
because you mistyped

\framebox[\linewidth][c]{Text text text}
--
Donald Arseneau ***@triumf.ca
Loading...