![Leftbar 环境中的对齐。Rightbar 可以吗?](https://linux22.com/image/247976/Leftbar%20%E7%8E%AF%E5%A2%83%E4%B8%AD%E7%9A%84%E5%AF%B9%E9%BD%90%E3%80%82Rightbar%20%E5%8F%AF%E4%BB%A5%E5%90%97%EF%BC%9F.png)
在这我问过一个问题,关于在环境中更改缩进(左侧)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}