Text FormattingCentering an 'lrbox' Environment

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
jduggins
Posts: 1
Joined: Mon Aug 22, 2011 7:31 pm

Centering an 'lrbox' Environment

Post by jduggins »

I am trying to define a new environment for writing examples in my lecture notes. I want the environment to have a background color, have a formatted introduction that uses section counters and that is centered on the page -- but the text in the example is not centered. I need help with the centering.

Currently I am using the following code to achieve my Example environment, but I can't figure out how to center it. I have searched this forum, but haven't found any solutions, so any help would be appreciated.

Code: Select all

%create the lrbox with a yellow background to hold the example

\definecolor{PWY}{rgb}{1.00,1.00,0.80}
\makeatletter\newenvironment{pwybox}[1]
{
 \begin{lrbox}{\@tempboxa}
 \begin{minipage}{#1}
}
{
\end{minipage}
 \end{lrbox}
 \colorbox{PWY}{\usebox{\@tempboxa} }

}
\makeatother


%create the new style for examples

\newtheoremstyle{myex}{\topsep}{\topsep}%
     {}%         Body font
     {}%         Indent amount (empty = no indent, \parindent = para indent)
     {\bfseries}% Thm head font
     { :: }%        Punctuation after thm head
     {0in}%     Space after thm head (\newline = linebreak)
     {\underline{\thmname{#1}\thmnumber{ #2}}\thmnote{ #3}}%         Thm head spec
\theoremstyle{myex}
\newtheorem{myex}{Example}[section]

%create the final command for starting and ending an example

\newcommand{\bex}[1][\bexlength]{\begin{pwybox}{#1}\begin{myex}}
\newcommand{\eex}{\end{myex}\end{pwybox}}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Post Reply