在这我问过一个问题,关于在环境中更改缩进(左侧)leftbar
。我已经把东西排列整齐了(栏在文本字段外面),但右侧有一点空间,我想删除。另外,如何将左栏变成右栏?
\documentclass{article}
\usepackage[centering]{geometry}
\usepackage{lipsum}
\newlength{\leftbarwidth}
\setlength{\leftbarwidth}{3pt}
\newlength{\leftbarsep}
\setlength{\leftbarsep}{10pt}
\usepackage{xcolor}
\usepackage{framed}
\renewenvironment{leftbar}[1][\hsize]
{%
\def\FrameCommand
{%
{\hspace{-7pt} \color{black} \vrule width 2pt}%
\hspace{0pt}%must no space.
\fboxsep=\FrameSep\colorbox{white}%
}%
\MakeFramed{\hsize#1\advance\hsize-\width\FrameRestore}%
}
{\endMakeFramed}
\setlength{\FrameSep}{5pt}
\begin{document}
\lipsum[3]
\begin{leftbar}
\lipsum[3]
\end{leftbar}
\lipsum[3]
\end{document}
答案1
如果使用框架而不是framed
是一个选项,那么您可以轻松控制框架的所有属性;特别是,您可以轻松实现样式righbar
。在下面的例子中,我使用mdframed
特性二定义了两个新环境rightbar
和,mdleftbar
并且我还使用了您的leftbar
环境进行比较:
\documentclass{article}
\usepackage[centering]{geometry}
\usepackage{xcolor}
\usepackage{framed}
\usepackage{mdframed}
\usepackage{lipsum}
\newlength{\leftbarwidth}
\setlength{\leftbarwidth}{3pt}
\newlength{\leftbarsep}
\setlength{\leftbarsep}{10pt}
\renewenvironment{leftbar}[1][\hsize]
{%
\def\FrameCommand
{%
{\hspace{-7pt} \color{black} \vrule width 2pt}%
\hspace{0pt}%must no space.
\fboxsep=\FrameSep\colorbox{white}%
}%
\MakeFramed{\hsize#1\advance\hsize-\width\FrameRestore}%
}
{\endMakeFramed}
\setlength{\FrameSep}{5pt}
\newmdenv[topline=false, leftline=false, bottomline=false,%
linewidth=2pt, innerleftmargin=0pt, rightmargin=-4pt,%
innerrightmargin=5pt, skipabove=8pt, skipbelow=8pt]{rightbar}
\newmdenv[topline=false, rightline=false, bottomline=false,%
linewidth=2pt, innerrightmargin=0pt, leftmargin=-4pt,%
innerleftmargin=5pt, skipabove=8pt, skipbelow=8pt]{mdleftbar}
\begin{document}
\lipsum[2]
\begin{leftbar}
\lipsum[2]
\end{leftbar}
\lipsum[2]
\begin{mdleftbar}
\lipsum[2]
\end{mdleftbar}
\lipsum[2]
\begin{rightbar}
\lipsum[2]
\end{rightbar}
\end{document}