Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
1  
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

2 Answers 2

up vote 8 down vote accepted

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}%
    }%
    \MakeFramed{\hsize#1\advance\hsize-\width\FrameRestore}%
}
{\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}

enter image description here

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}%
    }%
    \MakeFramed{\hsize#1\advance\hsize-\width\FrameRestore}%
}
{\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}

enter image description here

share|improve this answer
    
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

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}

enter image description here

share|improve this answer
    
Thank you very much Martin. –  user1999 Jul 7 '11 at 18:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.