[Tex/LaTex] Regarding the leftbar environment

framed

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

Best Answer

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