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 Answer 1

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

5
  • The solution and correction are amazing! I would like to know, how I can reduce the vertical space after the \item[\code{int} (value type)]\mbox{}? I mean, I could just do \vspace{-8mm} after each \mbox{}, but maybe you know the approach that would fit better. Sep 23 at 10:17
  • 1
    @VladyslavRehan I made an edit to my answer.
    – dexteritas
    Sep 23 at 14:09
  • 1
    \ttfamily, not \ttshape
    – egreg
    Sep 23 at 19:52
  • 1
    @egreg oh, I took the error from this answer without checking it. I have corrected it here. You may comment there as well ;)
    – dexteritas
    Sep 23 at 20:02
  • @dexteritas Thank You! Answer accepted! Sep 24 at 7:26

You must log in to answer this question.

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