关于 leftbar 环境

关于 leftbar 环境

有人知道如何控制leftbar环境中左侧栏的宽度和颜色吗?

答案1

忽略可选参数:

\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}

在此处输入图片描述

指定可选参数:

您可以按以下示例指定可选参数:

\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}

在此处输入图片描述

答案2

宽度和颜色(即不使用颜色)似乎是硬编码到这个环境中的:

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


\endleftbar:
\long macro:->\endMakeFramed 

只需定义您自己的版本,并指定适当的颜色和宽度。最好的方法是添加长度寄存器,之后可以更改其值:

\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}

在此处输入图片描述

相关内容