using \newcommand for example:
Code: Select all
\newcommand\mybox[1]{%
\begin{center}%
\fcolorbox{black}{red}{%
\begin{minipage}[t]{1.0\textwidth}%
#1%
\end{minipage}}%
\end{center}}
Stefan
Code: Select all
\newcommand\mybox[1]{%
\begin{center}%
\fcolorbox{black}{red}{%
\begin{minipage}[t]{1.0\textwidth}%
#1%
\end{minipage}}%
\end{center}}
NEW: TikZ book now 40% off at Amazon.com for a short time.
Code: Select all
\documentclass[a4paper]{article}
\usepackage[margin=2cm]{geometry}
\usepackage{lipsum,framed,color}
\definecolor{shadecolor}{rgb}{1,0.8,0.3}
\newlength{\boxwidth}
\newsavebox{\boxcontainer}
% Improved version of Stephan_K's \mybox
% Needs: shadecolor, \boxwidth
\newcommand\mybox[1]{%
\setlength{\boxwidth}{\textwidth}
\addtolength{\boxwidth}{-2\fboxsep}
\addtolength{\boxwidth}{-2\fboxrule}
\begin{center}%
\fcolorbox{black}{shadecolor}{%
\begin{minipage}[t]{\boxwidth}%
#1%
\end{minipage}}%
\end{center}}
% First environment version
% Needs: shadecolor, \boxwidth, \boxcontainer
\newenvironment{Mybox}%
{\setlength{\boxwidth}{\textwidth}
\addtolength{\boxwidth}{-2\fboxsep}
\addtolength{\boxwidth}{-2\fboxrule}
\begin{lrbox}{\boxcontainer}%
\begin{minipage}{\boxwidth}}%
{\end{minipage}\end{lrbox}%
\begin{center}%
\fcolorbox{black}{shadecolor}{\usebox{\boxcontainer}}
\end{center}}
% Second environment version
% Needs: shadecolor, \boxwidth and the framed package
\newenvironment{MyBox}{%
\def\FrameCommand{\fboxsep=\FrameSep \fboxrule=\FrameRule \fcolorbox{black}{shadecolor}}%
\MakeFramed {\setlength{\boxwidth}{\textwidth}
\addtolength{\boxwidth}{-2\FrameSep}
\addtolength{\boxwidth}{-2\FrameRule}
\setlength{\hsize}{\boxwidth} \FrameRestore}}%
{\endMakeFramed}
\begin{document}
% Settings for \mybox and Mybox
\setlength{\fboxrule}{1pt}
\setlength{\fboxsep}{9pt}
% Additional settings for MyBox
\setlength{\FrameRule}{\fboxrule}
\setlength{\FrameSep}{\fboxsep}
% Text not framed
\lipsum[1]
% Text framed with \mybox
\mybox{\lipsum[1]}
% Text framed with Mybox
\begin{Mybox}
\lipsum[1]
\end{Mybox}
% Text framed with MyBox
\begin{MyBox}
\lipsum[1]
\end{MyBox}
% Text framed with MyBox. It can be splitted in two different (or more) pages
\begin{MyBox}
\lipsum[1-5]
\end{MyBox}
\end{document}
Code: Select all
\newenvironment{MyBox}{%
\def\FrameCommand{\fboxsep=\FrameSep \fboxrule=\FrameRule \fcolorbox{black}{shadecolor}}%
\MakeFramed {\setlength{\hsize}{\textwidth-2\FrameSep-2\FrameRule} \FrameRestore}}%
{\endMakeFramed}
Code: Select all
\newenvironment{MyBox}{%
\def\FrameCommand{\fcolorbox{black}{shadecolor}}%
\MakeFramed{\setlength{\hsize}{\textwidth-2\fboxsep-2\fboxrule} \FrameRestore}}%
{\endMakeFramed}
Code: Select all
\newcommand\mybox[1]{%
\begin{center}%
\fcolorbox{black}{shadecolor}{%
\begin{minipage}[t]{\dimexpr\textwidth-2\fboxsep-2\fboxrule}%
#1%
\end{minipage}}%
\end{center}}
\newenvironment{Mybox}%
{\begin{lrbox}{\boxcontainer}%
\begin{minipage}{\dimexpr\textwidth-2\fboxsep-2\fboxrule}}%
{\end{minipage}\end{lrbox}%
\begin{center}%
\fcolorbox{black}{shadecolor}{\usebox{\boxcontainer}}
\end{center}}
\newenvironment{MyBox}{%
\def\FrameCommand{\fcolorbox{black}{shadecolor}}%
\MakeFramed{\setlength{\hsize}{\dimexpr\textwidth-2\fboxsep-2\fboxrule} \FrameRestore}}%
{\endMakeFramed}
NEW: TikZ book now 40% off at Amazon.com for a short time.