我想在使用整个的列表中插入一个段落或甚至是一个带有背景颜色的框\textwidth
。像这样:
1st item
a subitem 1
b subitem 2
2nd item
a subitee
\begin{use the full width}
[ Here the text should use the full text width ignoring the list indent]
\end{use the full width}
b subitem
3rd item
该列表是一个正常的枚举。
答案1
如果你想要一个单行命令,一个非常简单的命令是
\makeatletter
\newcommand{\shiftleft}{\hspace*{-\@totalleftmargin}}
\makeatother
如果你想要一个占据整个宽度并跨页的环境,定义一个列表
\makeatletter
\newenvironment{fullwidth}
{\par
\setlength{\@totalleftmargin}{0pt}%
\setlength{\linewidth}{\hsize}%
\list{}{\setlength{\leftmargin}{0pt}}
\item\relax}
{\endlist}
\makeatother
请看下面的例子:
\documentclass{article}
\usepackage{calc}
\usepackage{color}
\definecolor{shadecolor}{rgb}{1,1,0}
\makeatletter
\newcommand{\shiftleft}{\hspace*{-\@totalleftmargin}}
\newenvironment{fullwidth}
{\par
\setlength{\@totalleftmargin}{0pt}%
\setlength{\linewidth}{\hsize}%
\list{}{\setlength{\leftmargin}{0pt}}
\item\relax}
{\endlist}
%% colored minipage (do not break across pages!)
\newsavebox{\cminibox}
\newlength{\cminilength}
\newenvironment{cminipage}[1][\linewidth]
{\setlength{\cminilength}{#1-2\fboxsep}
\begin{lrbox}{\cminibox}%
\begin{minipage}{\cminilength}}%
{\end{minipage}\end{lrbox}%
\colorbox{shadecolor}{\usebox{\cminibox}}}
\makeatother
\begin{document}
\noindent\hrulefill\par
\begin{enumerate}
\item Item
\begin{enumerate}
\item subitem 1
\shiftleft\colorbox{shadecolor}{A one liner here}
\item subitem 2
\end{enumerate}
\item Item
\begin{enumerate}
\item subitem 1
\begin{fullwidth}
\begin{cminipage}
This is a long sentence to test if it fills the
whole line again and again and again.
This is a long sentence to test if it fills the
whole line again and again and again.
\end{cminipage}
\end{fullwidth}
\item subitem 2
\end{enumerate}
\item Item
\end{enumerate}
\noindent\hrulefill\par
\end{document}
答案2
您可以使用\rlap
命令;在下面的例子中,我使用了这个想法和shaded
环境形成的framed
包来定义一个命令来实现您想要的:
\documentclass{article}
\usepackage{xcolor}
\usepackage{framed}
\colorlet{shadecolor}{blue!40}
\newcommand\MyInd[1]{%
\begin{shaded}\rlap{\parbox{\textwidth}{#1}}\end{shaded}}
\begin{document}
\begin{enumerate}
\item 1st item
\begin{enumerate}
\item a subitem 1
\MyInd{Here the text is using the full text width ignoring the list indent.}
\item b subitem 2
\end{enumerate}
\item 2nd item
\begin{enumerate}
\item a subitem 1
\par\rlap{Here the text is using the full text width ignoring the list indent.}
\item b subitem 2
\end{enumerate}
\item 3rd item
\end{enumerate}
\end{document}
编辑:结果:
答案3
enumerate
只需在正确的地方退出并使用enumitem
的[resume]
选项:
\documentclass{article}
\usepackage{lipsum}
\usepackage{enumitem}
\begin{document}
\begin{enumerate}
\item \lipsum*[1]
\end{enumerate}
\lipsum*[2]
\begin{enumerate}[resume]
\item \lipsum*[3]
\end{enumerate}
\end{document}
如果不想缩进,则不要在后面留空行\end{enumerate}
(我就是这么做的),或者使用\noindent
。