Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question

migrated from stackoverflow.com May 29 '11 at 15:14

This question came from our site for professional and enthusiast programmers.

    
add comment

2 Answers 2

up vote 6 down vote accepted

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

share|improve this answer
add comment

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:

share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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