1

I'm quite new to (La)TeX stuff like macros and custom environments, so I'm not sure, whether I'm using the right approach. I want to create my own list environment, which should produce something similar to the list here (but I don't want to add more packages like enumitem for it):

\begin{pathlist}
    \item[\texttt{nodes/\{id\}}]
    Gives a single node by its id.

    \item[\texttt{nodes/\{id\}/children}]
    Gives all children of a node, also if they are stored in a field, which is not called {\sf childIds}.
    %snip
\end{pathlist}

The result looks like:

enter image description here

So it should become a manipulated description list. But how can I control the margins and position of the \descriptionlabel and the itembody (I don't know the command)?


As you can see in the spot, the label is placed badly, it breaks out (to the left) of the margins of the normal textbody, but the itembody lies far right to it.

My current code:

%my own description list
%newenvironment takes as definition:
%{description}[numberOfArguments]{before, processed before text in environment is processed}{after, see @ before}
\definecolor{darkblue}{HTML}{0304A4}
\newenvironment{pathlist}{%
\renewcommand{\descriptionlabel}[1]{%
        %\leftmargin{5px}
        \parbox[b][2em][c]{\textwidth}{{\color{darkblue}\textsf{##1}}}}%
    \begin{description}}
    {\end{description}}

Using \leftmargin there would not work at all. Or, where can I place something like this?

\setlength\leftmargini{0em}

There are some nice examples in this paper, but the code there does not work, too, very often. There are some nice examples here, too, but they aslo don't fit to my wanted layout.

Thanks a lot in advance!


A working example (updated):

\documentclass[a4paper, 14pt, titlepage]{article}

\usepackage{textcomp}
\usepackage{pifont}
\usepackage{xcolor}
\usepackage[american]{babel}

%my own description list
%newenvironment takes {description}[numberOfArguments]{before, processed before text in environment is processed}{after, see @ before} as definition
\definecolor{darkblue}{HTML}{0304A4}
\newenvironment{pathlist}{
    \renewcommand{\descriptionlabel}[1]{
        \parbox[b][2em][c]{\textwidth}{{\color{darkblue\textsf{\hspace{15px}##1}}}}
    \begin{description}
        \setlength{\rightmargin}{30px} % does not work at all
}{
    \end{description}
}

%response type expanding
\def\resptype#1{{\it \textbf{#1} (response type)}}

\begin{document}

\section{API}
Divided by HTTP methods.
\subsection{GET}
... some text \\
The text usually starts at the left edge, it will reach to the right edge     and everyone is happy. But why do the item bodies in the list below behave differently and why I can't set left- or rightmargin for them?

\begin{pathlist}
    \item[\texttt{nodes/\{id\}}]
    Gives a single node by its id.

    \item[\texttt{nodes/\{id\}/children}]
    Gives all children of a node, also if they are stored in a field, which is not called {\sf childIds}.
\end{pathlist}
\end{document}
BairDev
  • 443
  • Welcome to TeX SX! Could you provide a minimal working example? What you want is not clear? – Bernard Jun 05 '15 at 10:51
  • @Bernard Just edited, what else would be helpful? My main question is, "how can I control the margins and position of the \descriptionlabel and the itembody (I don't know the command)?" – BairDev Jun 05 '15 at 11:21
  • OK, this one was helpful: \parbox[b][2em][c]{\textwidth}{{\color{darkblue}\textsf{\hspace{6px}##1}}}}. But actually I don't understand, why the parbox hangs left from the left edgte of the main textbody. And I don't know, how I can control the item's body or main text. – BairDev Jun 05 '15 at 11:34
  • What would be helpful would be a minimal (non) working example, fully compilable. I don't understang what you mean by controlling the item body. – Bernard Jun 05 '15 at 11:44
  • Well the given example above does not work in my view. The item label and the item body are placed badly. It is all about layout / placing some text. By controlling the item body I also mean its position. Can I move it somehow apart from the usual commands (like \itempar in the body of the \description environment, which I use in my own environment? – BairDev Jun 05 '15 at 12:05
  • 1
    Can't you provide a full code so that we can test? Anyway, the best tool by far is enumitem. It's pointless trying to reinvent the wheel… – Bernard Jun 05 '15 at 12:19
  • I've added a compilable .tex document. I mostly do this for learning purposes. – BairDev Jun 05 '15 at 12:30
  • 2
    Well, understanding lists formatting is not the simplest thing! – Bernard Jun 05 '15 at 12:36
  • 1
    It is a hardy soul who wants to start learning the intricacies of lists when learning the intricacies of enumitem is demanding enough already, but if you really mean it, you can look at the descriptions of "itemize" (especially), "enumerate", "description", and "list" in section 9 of what pops up when you type texdoc latex2e. – jon Jun 05 '15 at 13:12

2 Answers2

3

Here is a simple solution with enumitem and url. I'm not sure to have fully understood your requirements, but Ithink it's more or less what you want.

I defined a new list type, based on description, with a different formatting using the url package. The beforekey is for what is executed before entering the list \ here shortening \linewidth. I simpified your color code, as one can uscolors-by-name with xcolor and your HTML color is close to SVG's DarkBlue.

Comment aside, don't use \sf, \it and the like for font changing commands: the are plain TeX commands; use NFSS's \textsf, \textit or \sffamily, \itshape instead. Also, you can't have a size of 14pt in standard classes. For this use extarticle class from the extsizes package.

\documentclass[a4paper, 14pt, titlepage]{extarticle}

\usepackage{textcomp}
\usepackage{pifont}
\usepackage[svgnames]{xcolor}
\usepackage[american]{babel}
\usepackage{enumitem}
%my own description list
%newenvironment takes {description}[numberOfArguments]{before, processed before text in environment is processed}{after, see @ before} as definition

\usepackage{url} %

\newlist{pathlist}{description}{1}
\setlist[pathlist, 1]{format = \color{DarkBlue}\mdseries\path, wide=15px, before={\addtolength\linewidth{-30px}}}
%response type expanding
\def\resptype#1{{\itshape\textbf{#1} (response type)}}
\DeclareUrlCommand\path{\urlstyle{sf}}

\begin{document}

\section{API}
Divided by HTTP methods.
\subsection{GET}
... some text \\
The text usually starts at the left edge, it will reach to the right edge and everyone is happy. But why do the item bodies in the list below behave differently and why I can't set left- or rightmargin for them?

\begin{pathlist}
  \item[\nodes/{id}]
  Gives a single node by its id.

  \item[{nodes/{id}/children}]
  Gives all children of a node, also if they are stored in a field, which is not called \textsf{childIds}.
\end{pathlist}
Some more text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text.

\end{document} 

enter image description here

Bernard
  • 271,350
0

I've googled some more and figured out, that the list type \description is just too narrow (defined) for my purposes. Commands like \setlength{\leftmargin}{20pt} don't change anything for it. Now I use something (it quite close to be ready) like:

\newenvironment{pathlist}{
    \let\olditem\item 
    \renewcommand\item[2]{\olditem \color{darkblue}##1\vspace*{2pt}\linebreak[4]
    \color{black}##2}
    \begin{list}{}{
        \setlength{\baselineskip}{1.3em}
        \setlength{\topsep}{5px}
        \setlength{\leftmargin}{10pt}
        \setlength{\rightmargin}{5pt}
    }
}{
    \end{list}
}

Note that I didn't use the label argument of \list, but this might have been possible, too. In my case together with renewing the \label command. A quote from latex2e documentation:

The mandatory labeling argument specifies how items should be labelled (unless the optional argument is supplied to \item). This argument is a piece of text that is inserted in a box to form the label. It can and usually does contain other L A TEX commands.

BairDev
  • 443