1

I have the next document:

\documentclass[12pt]{article}
\usepackage[english, ukrainian]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{enumitem} \setdescription{style=nextline, font=\mdseries, align=left} \setdescription[2]{style=nextline, font=\mdseries, align=left}

\newcommand{\code}[1]{{\tt #1}} \begin{document} \begin{description} \item[\code{int} (value type)] \begin{description} \item[\code{int = a}] Значення не змінюється. \item[\code{ref int = a}] Значення змінюється. \item[\code{int = new int; int = a}] Значення не змінюється. \item[\code{ref int = new int; int = a}] Значення змінюється. \end{description} \item[\code{struct} (value type)] \begin{description} \item[\code{struct = a}] Значення не змінюється. \item[\code{ref struct = a}] Значення змінюється. \item[\code{struct = new struct; struct = a}] Значення не змінюється. \item[\code{ref struct = new struct; struct = a}] Значення змінюється. \end{description} Так як \code{struct} це тип-значення то поведінка аналогічна до типу \code{int}. \item[\code{int[]} (reference type)] \begin{description} \item[\code{int[] = a}] Значення змінюється. \item[\code{ref int[] = a}] Значення змінюється. \item[\code{int[] = new int[]; int[] = a}] Значення змінюється. \item[\code{ref int[] = new int[]; int[] = a}] Значення змінюється. \end{description} \item[\code{string} (reference type)] \begin{description} \item[\code{int[] = a}] Значення не змінюється. \item[\code{ref int[] = a}] Значення змінюється. \item[\code{int[] = new int[]; int[] = a}] Значення не змінюється. \item[\code{ref int[] = new int[]; int[] = a}] Значення змінюється. \end{description} \end{description} \end{document}

It produces almost what I want:

enter image description here

But notice the first nested description: the \item[\code{int = a}] must go to new line but it follows the \item[\code{int} (value type)] for some reason. How to make it appear on new line? I tried to find something about it in enumitem docs but I couldn't.

1 Answers1

1

Adaptations

  • \setdescription is deprecated, replaced by \setlist[description,<levels>]{<format>}
  • defined command \directenv, that can be used, if there is no text following, but directly another environment:
    \newcommand{\directenv}{\hfill\vspace{-1.7\baselineskip}}
    
  • reduced the example code and added an item with text (for comparison)
  • replaced the old tex command \tt #1 by latex command \texttt{#1} (or \ttfamily #1)

Code

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{enumitem} \setlist[description]{style=nextline, font=\mdseries, align=left}

\newcommand{\code}[1]{{\texttt{#1}}} \newcommand{\directenv}{\hfill\vspace{-1.7\baselineskip}}

\begin{document} \begin{description} \item[\code{int} (value type)]\directenv \begin{description} \item[environment item] foo \end{description} \item[\code{struct} (value type)] direct text (no environment) \end{description} \end{document}

Result

enter image description here

dexteritas
  • 9,161