6

I want to insert a paragraph or possibly even a box with a background color into a list that uses the whole \textwidth. Something like this:

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

The list is a normal enumerate.

1
6

If you want a oneliner a very simple command is

\makeatletter
\newcommand{\shiftleft}{\hspace*{-\@totalleftmargin}}
\makeatother

If you want an environment that takes up the whole width and breaks accross pages define a list

\makeatletter
\newenvironment{fullwidth}
    {\par
     \setlength{\@totalleftmargin}{0pt}%
     \setlength{\linewidth}{\hsize}%
     \list{}{\setlength{\leftmargin}{0pt}}
     \item\relax}
    {\endlist}
\makeatother

Look at example below:

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

enter image description here

5

You can use the \rlap command; in the following example I used this idea and the shaded environment form the framed package to define a command to achieve what you want:

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

EDIT: the result:

2
  • Interesting. Why isn't the \rlap code indented? – Martin Scharrer May 29 '11 at 17:29
  • 1
    @Martin: \rlap is a red herring here. \rlap is basically \hbox to 0pt{#1\hss}. The important thing here is that it's just an \hbox in vertical mode and TeX does the usual thing. – TH. May 29 '11 at 18:53
1

Just quit enumerate at the right place and use enumitem's [resume] option:

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

If you want no indentation, either don't leave a blank line after \end{enumerate} (which is what I have done), or use \noindent.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.