19

So for example if I have this list:

\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{mathtools}

\begin{document}

   \begin{itemize}
    \item one
    \clap{some text}\item two 
    \item three
    \end{itemize}

\end{document}

It would compile like this:

enter image description here

where some text is rendered in place of a first bullet, but I want it to be where I marked it with the arrow. Do you have any idea?

4 Answers 4

21
\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{mathtools}

\begin{document}

   \begin{itemize}
    \item one
    \item \makebox[0pt][r]{some text\hspace{0.5cm}}two
    \item three
    \end{itemize}

\end{document}

enter image description here

1
  • +1 nice and easy :) I allowed myself to use your approach and make it safer (by checking for the width of the preceding text in relation to the margin) and abstracted it into a alternate version of the \item macro.
    – Ruben
    Jan 2, 2017 at 14:03
21

Following up on the idea of @UlrikeFischer here is a way how to use it with a smooth user interface, i.e. the syntax is

\item[<mark>](<text before label>)

Note that both arguments are optional:

\begin{itemize}
  \item one
  \item[+] two
  \item(text) three
  \item[--](text) four
\end{itemize}

Moreover, I added a checker for the width of the text preceding the items label that throws out a warning if the text exceeds the length of one line. Preceding textes that are not too overlong, i.e. two lines, can still be handled by this solution.

showcase

Complete Code

\documentclass{article}
\usepackage{lipsum}

\makeatletter
\let\ltx@item\item
\def\item{\kernel@ifnextchar[{\item@}{\item@[\@itemlabel]}}
\def\item@[#1]{\kernel@ifnextchar({\item@@[#1]}{\item@@[#1]()}}
\def\item@@[#1](#2){\ltx@item[#1]\itemc@mment{#2}\ignorespaces}
\def\itemc@mment#1{%
  \@tempdima\dimexpr\oddsidemargin+\hoffset+\itemindent+1in\relax
  \setbox0\hbox{\ignorespaces#1}%
  \ifdim\wd0>\@tempdima
    \@latex@warning{Overfull item comment
      (\the\dimexpr\wd0-\@tempdima\relax)}\fi
  \ifdim\wd0>\z@
    \hspace{-.67em}
    \makebox[\z@][r]{%
      \smash{\parbox[t]{\dimexpr\@tempdima-.175cm\relax}{%
        \setlength\parindent\z@
        \addtolength\baselineskip{-.33em}
        \ifdim\wd0<\@tempdima\hspace{0pt plus 1fill}\fi#1}}
      \hspace{.175cm}
    }
  \fi
}
\makeatother

\begin{document}
\begin{itemize}
  \item one
  \item[+] two
  \item(text) three
  \item[--](text) four
  \item(text text text text text text text) five
  \item six
\end{itemize}

\begin{itemize}
  \setlength\itemindent{-1in}
  \item one
  \item[+] two
  \item(text) three
  \item[--](text) four
  \item(text text text text text text text) five
  \item six
\end{itemize}
\end{document}

Addendum

Note that this solution supports nested lists too.

\begin{itemize}
  \item first
    \begin{itemize}
      \item sub one
      \item[:] sub two
      \item(text) sub three
      \item[:](text) sub four
    \end{itemize}
  \item[+] two
  \item(text) three
  \item[--](text) four
  \item(text text text text text text text) five
  \item six
\end{itemize}

output2

2
  • Nice catch there! Perhaps you can add an \item six for show? Jan 2, 2017 at 17:53
  • @KessVargavind -- thx! and yes, I add an \item below to see how it reacts with long prefixes.
    – Ruben
    Jan 2, 2017 at 19:04
9

If you're only wanting this at the "root" level of an itemize, you can use \textbullet, otherwise use \itemmark (which adapts to the level of itemize).

The solution below relies on the fact that you can specify an \item[<mark>] by using the optional argument <mark>:

enter image description here

\documentclass{article}

\makeatletter
\newcommand{\itemmark}{\expandafter\csname labelitem\romannumeral\the\@itemdepth\endcsname}
\makeatother

\begin{document}

\begin{itemize}
  \item one
  \item[some text~1\ \textbullet] two 
  \item[some text~2\ \itemmark] three
  \begin{itemize}
    \item four
    \item[some text~3\ \itemmark] five
  \end{itemize}
  \item six
\end{itemize}

\end{document}
1

Here, I just define \clap as

\def\clap#1\item{\item[#1~$\bullet$]}

Everything else remains unchanged. The MWE:

\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{mathtools}
\def\clap#1\item{\item[#1~$\bullet$]}
\begin{document}

   \begin{itemize}
    \item one
    \clap{some text}\item two 
    \item three
    \end{itemize}

\end{document}

enter image description here

To handle itemization depth automatically, one can instead define \clap as

\def\clap#1\item{\item[#1~\itemmark]}

and use Werner's definition of \itemmark.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .