Text FormattingHow to stop labels from ending up in the margin?

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
Sleft
Posts: 16
Joined: Fri Nov 12, 2010 4:19 pm

How to stop labels from ending up in the margin?

Post by Sleft »

Is there a way to stop labels from ending up in the margin? Here is an example where the last two labels is clearly in the left margin:

Code: Select all

\documentclass{article}
\usepackage{lipsum}
\usepackage{enumitem}

\begin{document}

\begin{enumerate}[start=22,label=(\arabic*)]
\item Bla bla bla\ldots
\end{enumerate}
\lipsum[1]
\begin{enumerate}[start=22,label=(\arabic*$'$)]
\item Bla bla bla\ldots
\end{enumerate}
\lipsum[2]
\begin{enumerate}[start=22,label=(\arabic*$''$)]
\item Bla bla bla\ldots% Due to its length this label ends up in the left margin
\end{enumerate}
\lipsum[3]
\begin{enumerate}[label=(\textsc{ok}$'$)]
\item Bla bla bla\ldots% Due to its length this label ends up in the left margin
\end{enumerate}
\lipsum[4]

\end{document}
Last edited by Sleft on Sat Jan 15, 2011 8:40 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

How to stop labels from ending up in the margin?

Post by frabjous »

Try futzing around with the additional enumitem package options (see its documentation), such as widest= and leftmargin=* or leftmargin=(fixed length).

Code: Select all

\documentclass{article}
\usepackage{lipsum}
\usepackage{enumitem}

\begin{document}

\begin{enumerate}[start=22,label=(\arabic*),leftmargin=*,widest=22]
\item Bla bla bla\ldots
\end{enumerate}
\lipsum[1]
\begin{enumerate}[start=22,label=(\arabic*$'$),leftmargin=*,widest=22]
\item Bla bla bla\ldots
\end{enumerate}
\lipsum[2]
\begin{enumerate}[start=22,label=(\arabic*$''$),leftmargin=*,widest=22]
\item Bla bla bla\ldots% Due to its length this label ends up in the left margin
\end{enumerate}
\lipsum[3]
\begin{enumerate}[label=(\textsc{ok}$'$),leftmargin=*]
\item Bla bla bla\ldots% Due to its length this label ends up in the left margin
\end{enumerate}
\lipsum[4]

\end{document}
Sleft
Posts: 16
Joined: Fri Nov 12, 2010 4:19 pm

How to stop labels from ending up in the margin?

Post by Sleft »

Thanks for answering and answering fast. Appreciated.

I got it working the way I wanted it by setting left margin in enumerate. I tried different values until the margin was big enough to fit the longest labels. The finished example:

Code: Select all

\documentclass[12pt,a4paper]{article}
\usepackage{lipsum}
\usepackage{enumitem}

\setenumerate[1]{leftmargin=33pt}

\begin{document}

\lipsum[1]
\begin{enumerate}[label=(\arabic*)]
\item Bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla\ldots
\end{enumerate}
\begin{enumerate}[start=1,label=(\arabic*$'$)]
\item Bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla\ldots
\end{enumerate}
\begin{enumerate}[start=22,label=(\arabic*$''$)]
\item Bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla\ldots
\end{enumerate}
\begin{enumerate}[label=(\textsc{ok}$'$)]
\item Bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla\ldots
\end{enumerate}
\lipsum[2]


\end{document}
Post Reply