# Removing a half-blank line and precisely calculating a space

Consider the following MWE:

Some text, Some text, Some text, Some text, Some text, Some text,
Some text, Some text, Some text, Some text, Some text, Some text
\begin{enumerate}
\item This is a line \mbox{\parbox[t][][t]{\textwidth-\widthof{MMMx This is a line}}{

\begin{enumerate}[label=\textit{(\roman{enumii})}]
\item  Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1
\item Text 2 Text 2 Text 2 Text 2 Text 2 Text 2 Text 2
\end{enumerate}

}}\end{enumerate}


I have to questions:

1) I would like that "(i) Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1" be display on the same line as "This is a line". How can I do that ?

2) I would like the spacing between the last word of "This is a line", i.e. "line", and the first word of "(i) Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1", i.e. "Text" be a normal space. Because "This is a line" is already indented I tried to account for this indentation by adding "MMMx" as additional spacing in \widthof. But this is just eye-measure. How can I make this precise ?

• Please edit your question so that it contains a complete example code (from \begin{document} to \end{document}). Without this it may be difficult for anyone to help you. I have no idea where the \widthof macro comes from. – Ian Thompson May 9 '14 at 10:36
• Please make your example into a complete document and so can run it and see, You are using various contributed packages (enumitem I would guess but you don't say) so it is very hard to guess what alignment you are seeing. (all questions should have a complete example document) – David Carlisle May 9 '14 at 10:36
• Sorry. \widthof is in the calc package (I assumed this was widely used, so there wasn't a need to mention the package explicitly); since I used the tag "enumitem" in my question I implicitly assumed that this package also had to be added. – l7ll7 May 9 '14 at 16:56

No need to guess; use minipage instead of \parbox and remove the \mbox:

\documentclass{article}
\usepackage{enumitem,calc}
\begin{document}
Some text, Some text, Some text, Some text, Some text, Some text,
Some text, Some text, Some text, Some text, Some text, Some text
\begin{enumerate}
\item This is a line
\begin{minipage}[t]{\textwidth-\labelwidth-\labelsep-\widthof{This is a line}}
\begin{enumerate}[label=(\textit{\roman*})]
\item Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1
\item Text 2 Text 2 Text 2 Text 2 Text 2 Text 2 Text 2 Text 1 Text 1 Text 1 Text 1 Text 1
\end{enumerate}
\end{minipage}
\end{enumerate}
\end{document}


A better definition that allows for nesting at every level; but keep in mind that nesting several enumerations is bad style.

\documentclass{article}
\usepackage{showframe} % just for showing the page margins
\usepackage{enumitem,calc}

\newenvironment{xenumerate}[1]
{\begin{minipage}[t]{\linewidth-\widthof{#1}}
\begin{enumerate}[label=(\textit{\roman*})]}
{\end{enumerate}\end{minipage}}

\begin{document}
Some text, Some text, Some text, Some text, Some text, Some text,
Some text, Some text, Some text, Some text, Some text, Some text
\begin{enumerate}
\item This is a line
\begin{xenumerate}{This is a line}
\item Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1
\item Text 2 Text 2 Text 2 Text 2 Text 2 Text 2 Text 2 Text 1 Text 1 Text 1 Text 1 Text 1
\end{xenumerate}
\item Text text text text text text
\begin{enumerate}
\item Text Text Text Text
\begin{xenumerate}{Text Text Text Text}
\item Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1
\item Text 2 Text 2 Text 2 Text 2 Text 2 Text 2 Text 2 Text 1 Text 1 Text 1 Text 1 Text 1
\end{xenumerate}
\item End of the story
\end{enumerate}
\end{enumerate}
\end{document}


## Version with an optional argument for changing the label

The default label is label=(\textit{\roman*}) as before, but you can change it as you please.

\documentclass{article}
\usepackage{showframe}
\usepackage{enumitem,calc}

\newenvironment{xenumerate}[2][label=(\textit{\roman*})]
{\begin{minipage}[t]{\linewidth-\widthof{#2}}
\begin{enumerate}[#1]}
{\end{enumerate}\end{minipage}}

\begin{document}
Some text, Some text, Some text, Some text, Some text, Some text,
Some text, Some text, Some text, Some text, Some text, Some text
\begin{enumerate}
\item This is a line
\begin{xenumerate}{This is a line}
\item Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1
\item Text 2 Text 2 Text 2 Text 2 Text 2 Text 2 Text 2 Text 1 Text 1 Text 1 Text 1 Text 1
\end{xenumerate}
\item Text text text text text text
\begin{enumerate}
\item Text Text Text Text
\begin{xenumerate}[label=(\arabic*)]{Text Text Text Text}
\item Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1
\item Text 2 Text 2 Text 2 Text 2 Text 2 Text 2 Text 2 Text 1 Text 1 Text 1 Text 1 Text 1
\end{xenumerate}
\item End of the story
\end{enumerate}
\end{enumerate}
\end{document}


• This is perfect! Two question though: Why doesn't removing \labelwidth and \labelsep change the spacing ? I noticed, that you're using \roman*. What is the difference to (\roman{enumii}) and where can I find more info on using the "*" on this command ? – l7ll7 May 9 '14 at 16:57
• @user10324 Removing \labelwidth and \labelsep would make the box too wide and stick in the right margin. \roman* is an enumitem trick: it allows to refer to the counter pertaining to the current level of the list, so you don't need to know it's enumii. – egreg May 9 '14 at 16:57
• Thanks a lot, another day another piece of knowledge :) (I was so busy looking at the distance between "line" and "(i)" that I didn't even notice the line sticking in the right margin :) – l7ll7 May 9 '14 at 16:59
• I just observed that the text does stick out in the right margin, if I use your code, but nest it more deeply, i.e. the "This is a line" is already a nested entry. What could I do in this case to have text aligned at the margin ? – l7ll7 May 9 '14 at 17:17
• The part “1. This is a line” is indented because you are in an enumerate environment. If you want “1.” to be flush to the left margin, say \begin{enumerate}[leftmargin=*] for the outer one. – egreg May 9 '14 at 17:20