2

I want to generate following point form with brackets in each item: enter image description here

this is the latex code I used:

\section{Timeline}
\begin{itemize}[label=\textbullet]
\item [{[Month 1–2]}] Lorem Ipsum is simply dummy text
\item [{[Month 3–4]}] Lorem Ipsum is simply dummy text
\item [{[Month 5–6]}] Lorem Ipsum is simply dummy text
\item [{[Month 7–8]}] Lorem Ipsum is simply dummy text
\item [{[Month 9–11]}] Lorem Ipsum is simply dummy text
\item [{[Month 12]}] Lorem Ipsum is simply dummy text
\end{itemize}

but the generated text was like:

enter image description here

how to update the latex code in correct format

3 Answers 3

8

You need

\item {[Month 1–2]}

or

\item {}[Month 1–2]

so the text is not seen as the optional argument to \item

4

Laziest!

\documentclass{article}

\NewDocumentCommand{\mitem}{>{\SplitArgument{1}{-}}m}{%
  \makemitem#1%
}
\NewDocumentCommand{\makemitem}{mm}{%
  \item\relax[\IfValueTF{#2}{Months}{Month} #1\IfValueT{#2}{--#2}] -- \ignorespaces
}

\begin{document}

\section{Timeline}

\begin{itemize}
\mitem{1-2} Lorem Ipsum is simply dummy text
\mitem{3-4} Lorem Ipsum is simply dummy text
\mitem{5-6} Lorem Ipsum is simply dummy text
\mitem{7-8} Lorem Ipsum is simply dummy text
\mitem{9-11} Lorem Ipsum is simply dummy text
\mitem{12} Lorem Ipsum is simply dummy text
\end{itemize}

\end{document}

output

The argument to \mitem is split at - returning

{<before hyphen>}{<after hyphen>}

but, if no hyphen is found, the second braced group will contain the special string -NoValue-, which can be tested in the \makemitem command to take decisions.

With \relax we stop \item to look for an optional argument.

2

Working with David's answer here are some ways to do it:

result

The first two items are just as David described: this approach results in some kind of unaligned text:

    \item {} [Month 1-9] Some text
    \item {} [Month 10-20] Some text

From a refactoring point of view it may be nice to absorb the beginning and just pass the actual range of months - more unified code, same result after compile:

\newcommand\montha[1]{{} [Month #1]}
...
    \item \montha{1-9} Some text, absorbed
    \item \montha{10-20} Some text, absorbed

If you want to introduce some kind of alignement here's a simple approach:

  • use a \makebox with fixed width
  • inside use \hfill to 'push' the two text componenents apart
  • follow the same approach, else
\newcommand\monthb[1]{{} \makebox[22mm]{[Month \hfill#1]}}
...
    \item \monthb{1-9} Some text, even more absorbed
    \item \monthb{10-20} Some text, even moreabsorbed


\documentclass[10pt,a4paper]{article}

\newcommand\montha[1]{{} [Month #1]}
\newcommand\monthb[1]{{} \makebox[22mm]{[Month \hfill#1]}}

\begin{document}
 \begin{itemize}
    \item {} [Month 1-9] Some text
    \item {} [Month 10-20] Some text
    \item \montha{1-9} Some text, absorbed
    \item \montha{10-20} Some text, absorbed
    \item \monthb{1-9} Some text, even more absorbed
    \item \monthb{10-20} Some text, even moreabsorbed
 \end{itemize}
\end{document}

P.S.: Those lazy refactor guys may even absorb the \item ...

\newcommand\mitem[1]{\item {} \makebox[22mm]{[Month \hfill#1]}}
...
    \item \monthb{10-20} Some text, even moreabsorbed
    \mitem {1-8} Here we go
 \end{itemize}

result2

You must log in to answer this question.

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