6

I am writing technical specs of a programming API. I am using itemize to highlight the method signature as it follows:

\begin{itemize}
    \item[\texttt{packeteer.send(message)}] \hfill \\
     is used to send a given \texttt{message} 
     through \texttt{packeteer} object.
\end{itemize}

Usually, a signature can be longer than page width and it runs out of margins:

\begin{itemize}
    \item[\texttt{packeteer.send(message, offset, length, port, direction, [function(error, bytes)\{ \}])}] \hfill \\
     is used to send a portion of a given 
     \texttt{message} through
     \texttt{packeteer} object.
\end{itemize}

Is it possible to have the text inside item multilined and those lines to be justified too?

It's something like this, but having the first line justified and a properly space between them:

\item[{\parbox[t]{1.0\linewidth}{\texttt{packeteer.send(message, offset, length, port, direction, \\ [function(error, bytes)\{ \}])}}}]
  • What about \linebreak instead of \\? – Sigur Apr 22 '13 at 19:50
  • what I'm looking for is to break the line, manually o automatically, for example, between "port" and "direction" arguments in the signature of the method. I'm not having \linebreak working inside \item – dysfuntcional Apr 22 '13 at 19:57
3

You can play with the layout a bit, but something like this:

enter image description here

\documentclass{article}
\renewcommand*\descriptionlabel[1]{\hspace\labelsep
 \parbox[t]{\dimexpr\leftmargin+\linewidth-\labelsep}{%
     \normalfont\bfseries\raggedright #1}}

\begin{document}

\begin{description}
    \item[\texttt{packeteer.send(message)}]
     is used to send a given \texttt{message} 
     through \texttt{packeteer} object.
   \item[\texttt{packeteer.send(message, offset, length, port, direction, [function(error, bytes)\{ \}])}] 
     is used to send a portion of a given 
     \texttt{message} through
     \texttt{packeteer} object.
\end{description}
\end{document}
  • It breaks line really well, but text on first line in second item is not justified. Also, I've found that space between last item line and description first line is narrower than the other spaces in document – dysfuntcional Apr 22 '13 at 20:20
  • @subterraneanhomesick I added \raggedright you can take it out if you like, I thought the signature looked rather odd justified, the short case is set natural width as it is the last line of a para, but then the two line case gets all stretched, but if that is what you want just remove \raggedright you might get better space-after if you change [t] to [b] – David Carlisle Apr 22 '13 at 20:29
3

One possibility using the enumitem package:

\documentclass{article}
\usepackage{enumitem}

\newcommand\setupdes{%
  \renewcommand\makelabel[1]{%
    \parbox[t]{\dimexpr\leftmargin+\linewidth\relax}{\ttfamily##1}}}
\setlist[description]{labelsep=0pt,before={\setupdes}}

\begin{document}   

\begin{description}
\item[packeteer.send(message)]
     is used to send a given \texttt{message} 
     through \texttt{packeteer} object.
\item[{packeteer.send(message, offset, length, port, direction,[function(error, bytes)\{ \}])}]
     is used to send a portion of a given 
     \texttt{message} through
     \texttt{packeteer} object.
\end{description}

\end{document}

enter image description here

Of course, instead of modifying description, you could also easily define your own structure.

  • It works fine, but I don't need second line indentation in item, could it be removed? Anyway, it does not justify the first line text in item – dysfuntcional Apr 22 '13 at 20:22
  • @subterraneanhomesick please see my updated answer. – Gonzalo Medina Apr 23 '13 at 0:37
  • It's a better approach, but it's basically what @David Carlisle showed us in his answer. The main problem is still that the first line, packeteer.send(message, offset, length, port,, is not justified, it doesn't end for example, where of a given \texttt{message} through \texttt{packeteer} object. ends. – dysfuntcional Apr 23 '13 at 11:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.