半空白行を削除し、スペースを正確に計算する

半空白行を削除し、スペースを正確に計算する

次の 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}

質問があります:

1) 「(i) テキスト 1 テキスト 1 テキスト 1 テキスト 1 テキスト 1 テキスト 1 テキスト 1」を「これは行です」と同じ行に表示したいのですが、どうすればよいですか?

2) 「This is a line」の最後の単語「line」と「(i) Text 1 Text 1 Text 1 Text 1 Text 1 Text 1 Text 1」の最初の単語「Text」の間のスペースを通常のスペースにしたいと思います。 「This is a line」はすでにインデントされているため、 に追加のスペースとして「MMMx」を追加して、このインデントを考慮しようとしました\widthof。 しかし、これは単なる目測です。 これを正確にするにはどうすればよいでしょうか。

答え1

推測する必要はありません。minipageの代わりにを使用し\parbox、 を削除します\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}

ここに画像の説明を入力してください

あらゆるレベルでネストを可能にする、より優れた定義です。ただし、複数の列挙をネストするのは不適切なスタイルであることに注意してください。

\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}

ここに画像の説明を入力してください

ラベルを変更するためのオプション引数付きバージョン

デフォルトのラベルはlabel=(\textit{\roman*})以前と同じですが、必要に応じて変更できます。

\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}

ここに画像の説明を入力してください

関連情報