Google Answers Logo
View Question
 
Q: Boxes with background color in LaTeX ( No Answer,   0 Comments )
Question  
Subject: Boxes with background color in LaTeX
Category: Computers > Software
Asked by: manifold-ga
List Price: $5.00
Posted: 02 Dec 2003 14:48 PST
Expires: 03 Dec 2003 04:27 PST
Question ID: 282787
First off, I do not whish to use any prefabricated package or so. I'm
a MiKTeX using and I writing latex or tex (not sure what the
difference is?).

How can I define my own LaTeX environment which puts all of its
content inside a lightgray-background box which has width equal to the
entire "paper"?

I the end I want to be able to type:

\begin{graybox}
hello world
\end{graybox}

the definition of graybox must use a \newenvironment command, and no
packages is to be imported (except the "color" package or course).
I've tried using:

\newenvironment{graybox}{\colorbox{red}\bgroup}{\egroup}
that "compiles" okay but produces nothing on screen.

and also
\newenvironment{graybox}{\colorbox{red}\begingroup}{\endgroup}
which compiles with I never use the env, and if I use it then it says
I got an error on the line \begin{graybox}

what's the difference between \begingroup and \bgroup anyway?

--- summary of questions ---

What's the difference between TeX and LaTeX?
MAIN QUESTION: How can I create my box env as above?
What's the difference between \begingroup and \bgroup?

sincerly,
/m

Request for Question Clarification by maniac-ga on 02 Dec 2003 16:40 PST
Hello Manifold,

The first question is answered more completely at
  http://www.tex.ac.uk/cgi-bin/texfaq2html
but in brief, TeX is a document generation system to "create beautiful
books - especially those with mathematics", and LaTeX (Layman's TeX)
is a set of macros running on top of TeX to make it easier to use TeX.

For the second question, my version of LaTeX doesn't have "\colorbox",
but please try...

  \colorbox{red}{
  ... text here ...
  }
and see if you still get an error. If so, there's something wrong with
the defnition of \colorbox (or the environment it is used in). If not,
I have some ideas, but I need my books for that answer (as well as the
next one).

For the third question, I need to get my books back tomorrow and can
answer it then.

  --Maniac

Clarification of Question by manifold-ga on 03 Dec 2003 02:00 PST
First, let me clarify that the second question is the main question,
this question is what I need the answer for. The other questions are
less important.

> and LaTeX is a set of macros running
Okay, so what is it LaTeX has which TeX does not have?

> For the second question, my version of LaTeX doesn't have "\colorbox"

The \colorbox I'm talking about takes two parameters just as you say,
and once I've imported the color package the example you posted works
just fine. I have no trouble creating colorboxes. However, this is not
what I'm trying todo, instead I want to create an environment so that
I may use syntax similar to:

\begin{graybox}
hello
\end{graybox}

The reason for this is that I may want to add more stuff later on, ie
define a boxed theorem and so forth. Here is what I'm really asking;
the \newenvironment command takes three params, first is the name,
second is the begin code, last is the end code. Once I use something
like \begin{myenv} that will be replaced by the begin code aso. The
main problem is that I would like to write:

\newenvironment{graybox}{   \colorbox{red}{   }{   }   }
ie
\newenvironment{graybox}{   \colorbox{red}startSymbol   }{   endSymbol   }

But latex will not accept this... it says I forgot to close some { or
something like that (which is understandable indeed... That's why I
started to try with \begingroup and \bgroup instead but as stated in
the main question.. no luck so far.

Any help on this matter is greatly appreciated, please rerequest
clarification if needed.


/m

Clarification of Question by manifold-ga on 03 Dec 2003 04:27 PST
Sorry I found the answer myself now, the trick is:


\definecolor{MyGray}{rgb}{0.96,0.97,0.98}
\makeatletter\newenvironment{graybox}{%
   \begin{lrbox}{\@tempboxa}\begin{minipage}{\columnwidth}}{\end{minipage}\end{lrbox}%
   \colorbox{MyGray}{\usebox{\@tempboxa}}
}\makeatother
\definecolor{MyGray}{rgb}{0.96,0.97,0.98}
\makeatletter\newenvironment{graybox}{%
   \begin{lrbox}{\@tempboxa}\begin{minipage}{\columnwidth}}{\end{minipage}\end{lrbox}%
   \colorbox{MyGray}{\usebox{\@tempboxa}}
}\makeatother
Answer  
There is no answer at this time.

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy