# Regarding the leftbar environment

Does anyone know how to control the width and color of the left bar in the leftbar environment?

-
Please mention used packages etc. also in the text and not only in the tags. You mean the leftbar environment of the framed package, don't you? Note that this package is kind of superseded by the similar mdframed package. – Martin Scharrer Jul 7 '11 at 13:53

## Ignore the optional argument:

\documentclass{article}
\usepackage{xcolor}
\usepackage{framed}

\renewenvironment{leftbar}[1][\hsize]
{%
\def\FrameCommand
{%
{\color{red}\vrule width 3pt}%
\hspace{0pt}%must no space.
\fboxsep=\FrameSep\colorbox{yellow}%
}%
}
{\endMakeFramed}

\def\fact{It is practically a big lie that LaTeX makes you focus on the content without bothering about the layout.}
\begin{document}
\fact
\leftbar
\fact
\endleftbar
\fact
\end{document}


## Specify the optional argument:

You can specify the optional argument as the following example:

\documentclass{article}
\usepackage{xcolor}
\usepackage{framed}

\renewenvironment{leftbar}[1][\hsize]
{%
\def\FrameCommand
{%
{\color{red}\vrule width 3pt}%
\hspace{0pt}%must no space.
\fboxsep=\FrameSep\colorbox{yellow}%
}%
}
{\endMakeFramed}

\def\fact{It is practically a big lie that LaTeX makes you focus on the content without bothering about the layout.}
\begin{document}
\fact
\leftbar[0.75\linewidth]
\fact
\endleftbar
\fact
\end{document}


-
This is indeed beautiful. Thanks a lot. – user1999 Jul 7 '11 at 18:45
How do I make the box itself colorless (i.e., I want it to have the same color of the background)? – user1999 Jul 7 '11 at 19:06
o.k.... I found a solution. Thanks again. – user1999 Jul 7 '11 at 19:12
change that \fboxsep=\FrameSep\colorbox{yellow}% to % \fboxsep=\FrameSep\colorbox{yellow}% – user11486 Feb 5 '12 at 21:24
+1 for revealing the "big lie"... and the solution. – niels Feb 21 at 11:39

The width and color (i.e. the non-use of color) seems to be hard-coded into this environment:

\leftbar:
\long macro:->\def \FrameCommand {\vrule width 3pt \hspace {10pt}}\MakeFramed {\advance \hsize -\width \FrameRestore }

\endleftbar:
\long macro:->\endMakeFramed


Simply define your own version which the appropriate color and width. The best thing is to add length register which values can be changed afterwards:

\documentclass{article}

\usepackage{framed}
\usepackage{xcolor}
\usepackage{lipsum}% dummy text

\newlength{\leftbarwidth}
\setlength{\leftbarwidth}{3pt}
\newlength{\leftbarsep}
\setlength{\leftbarsep}{10pt}

\newcommand*{\leftbarcolorcmd}{\color{leftbarcolor}}% as a command to be more flexible
\colorlet{leftbarcolor}{black}

\renewenvironment{leftbar}{%
\def\FrameCommand{{\leftbarcolorcmd{\vrule width \leftbarwidth\relax\hspace {\leftbarsep}}}}%
\MakeFramed {\advance \hsize -\width \FrameRestore }%
}{%
\endMakeFramed
}

\begin{document}

\begin{leftbar}
\lipsum
\end{leftbar}

\setlength{\leftbarwidth}{5pt}
\setlength{\leftbarsep}{8pt}
\colorlet{leftbarcolor}{blue}

\begin{leftbar}
\lipsum
\end{leftbar}

\end{document}


-
Thank you very much Martin. – user1999 Jul 7 '11 at 18:50