Skip to main content
added 731 characters in body
Source Link
Fran
  • 87.1k
  • 7
  • 183
  • 285

What was missing in what you tried was a \parbox, so that some like {\bfseries mycodebook}\hfill\parbox[t]{8cm}{my long text} could be enough.

To simplify this a bit, the example below show a \code macro with two argument (code and definition) that work only in a codebook environment to avoid indentation and set some vertical spacing between definitions. The environment allow an optional argument that should be the longest code, in order to adjust automatically the width of the definitions.

Note that like in lists, once the environment ended, the first next paragraph could be not indented. This could have sense since the begin of the paragraph will be clear. However, if you want change this behavior simply left a blank line after the environment.

The main difference with a list environment is that page breaks are not allowed inside a \code item.

\documentclass{article} \usepackage{lipsum} % dummy text \newlength\cbl \newenvironment{codebook}[1][rob\_avprison1]{ \settowidth{\cbl}{#1} %\setlength{\cbl}{#1} \parskip1em plus .3em minus .2em \parindent0pt \def\code##1##2{{\bfseries ##1}\hfill% \parbox[t]{\dimexpr\linewidth-2em-\cbl}{##2}\par}}{\noindent} \begin{document} \lipsum[2] \begin{codebook} \code{rob\_mannim0}{\lipsum[66]} \code{rob\_avprison1}{\lipsum[75]} \end{codebook} \lipsum[8] % next paragraph not indented \begin{codebook}[book0] \code{book0}{\lipsum[34]} \code{book0}{\lipsum[34]} \end{codebook} \lipsum[6-10] % paragraph indented   \end{document} 

The main difference with a list environment is that page breaks are not allowed inside a \code item. If you want this, one easy alternative, also with optionally adjustable space for the code, could be use the enuitem package:

\documentclass{article} \usepackage{enumitem,calc} \usepackage{lipsum} \newenvironment{codebook}[1][xxxxxxxxxxx]{% \begin{description}[leftmargin=\widthof{#1}+2em, style=nextline]} {\end{description}} \begin{document} \lipsum[2] \begin{codebook} \item[rob\_mannim0] \lipsum[66] \item [rob\_avprison1] \lipsum[75] \end{codebook} \lipsum[4] \begin{codebook}[rob\_avprison1\hskip2em] \item[rob\_mannim0] \lipsum[66] \item [rob\_avprison1] \lipsum[75] \end{codebook} \lipsum[6-10]  \end{document} 

What was missing in what you tried was a \parbox, so that some like {\bfseries mycodebook}\hfill\parbox[t]{8cm}{my long text} could be enough.

To simplify this a bit, the example below show a \code macro with two argument (code and definition) that work only in a codebook environment to avoid indentation and set some vertical spacing between definitions. The environment allow an optional argument that should be the longest code, in order to adjust automatically the width of the definitions.

Note that like in lists, once the environment ended, the first next paragraph could be not indented. This could have sense since the begin of the paragraph will be clear. However, if you want change this behavior simply left a blank line after the environment.

The main difference with a list environment is that page breaks are not allowed inside a \code item.

\documentclass{article} \usepackage{lipsum} % dummy text \newlength\cbl \newenvironment{codebook}[1][rob\_avprison1]{ \settowidth{\cbl}{#1} %\setlength{\cbl}{#1} \parskip1em plus .3em minus .2em \parindent0pt \def\code##1##2{{\bfseries ##1}\hfill% \parbox[t]{\dimexpr\linewidth-2em-\cbl}{##2}\par}}{\noindent} \begin{document} \lipsum[2] \begin{codebook} \code{rob\_mannim0}{\lipsum[66]} \code{rob\_avprison1}{\lipsum[75]} \end{codebook} \lipsum[8] % next paragraph not indented \begin{codebook}[book0] \code{book0}{\lipsum[34]} \code{book0}{\lipsum[34]} \end{codebook} \lipsum[6-10] % paragraph indented \end{document} 

What was missing in what you tried was a \parbox, so that some like {\bfseries mycodebook}\hfill\parbox[t]{8cm}{my long text} could be enough.

To simplify this a bit, the example below show a \code macro with two argument (code and definition) that work only in a codebook environment to avoid indentation and set some vertical spacing between definitions. The environment allow an optional argument that should be the longest code, in order to adjust automatically the width of the definitions.

Note that like in lists, once the environment ended, the first next paragraph could be not indented. This could have sense since the begin of the paragraph will be clear. However, if you want change this behavior simply left a blank line after the environment.

\documentclass{article} \usepackage{lipsum} % dummy text \newlength\cbl \newenvironment{codebook}[1][rob\_avprison1]{ \settowidth{\cbl}{#1} %\setlength{\cbl}{#1} \parskip1em plus .3em minus .2em \parindent0pt \def\code##1##2{{\bfseries ##1}\hfill% \parbox[t]{\dimexpr\linewidth-2em-\cbl}{##2}\par}}{\noindent} \begin{document} \lipsum[2] \begin{codebook} \code{rob\_mannim0}{\lipsum[66]} \code{rob\_avprison1}{\lipsum[75]} \end{codebook} \lipsum[8] % next paragraph not indented \begin{codebook}[book0] \code{book0}{\lipsum[34]} \code{book0}{\lipsum[34]} \end{codebook} \lipsum[6-10] % paragraph indented   \end{document} 

The main difference with a list environment is that page breaks are not allowed inside a \code item. If you want this, one easy alternative, also with optionally adjustable space for the code, could be use the enuitem package:

\documentclass{article} \usepackage{enumitem,calc} \usepackage{lipsum} \newenvironment{codebook}[1][xxxxxxxxxxx]{% \begin{description}[leftmargin=\widthof{#1}+2em, style=nextline]} {\end{description}} \begin{document} \lipsum[2] \begin{codebook} \item[rob\_mannim0] \lipsum[66] \item [rob\_avprison1] \lipsum[75] \end{codebook} \lipsum[4] \begin{codebook}[rob\_avprison1\hskip2em] \item[rob\_mannim0] \lipsum[66] \item [rob\_avprison1] \lipsum[75] \end{codebook} \lipsum[6-10]  \end{document} 
Source Link
Fran
  • 87.1k
  • 7
  • 183
  • 285

What was missing in what you tried was a \parbox, so that some like {\bfseries mycodebook}\hfill\parbox[t]{8cm}{my long text} could be enough.

To simplify this a bit, the example below show a \code macro with two argument (code and definition) that work only in a codebook environment to avoid indentation and set some vertical spacing between definitions. The environment allow an optional argument that should be the longest code, in order to adjust automatically the width of the definitions.

Note that like in lists, once the environment ended, the first next paragraph could be not indented. This could have sense since the begin of the paragraph will be clear. However, if you want change this behavior simply left a blank line after the environment.

The main difference with a list environment is that page breaks are not allowed inside a \code item.

\documentclass{article} \usepackage{lipsum} % dummy text \newlength\cbl \newenvironment{codebook}[1][rob\_avprison1]{ \settowidth{\cbl}{#1} %\setlength{\cbl}{#1} \parskip1em plus .3em minus .2em \parindent0pt \def\code##1##2{{\bfseries ##1}\hfill% \parbox[t]{\dimexpr\linewidth-2em-\cbl}{##2}\par}}{\noindent} \begin{document} \lipsum[2] \begin{codebook} \code{rob\_mannim0}{\lipsum[66]} \code{rob\_avprison1}{\lipsum[75]} \end{codebook} \lipsum[8] % next paragraph not indented \begin{codebook}[book0] \code{book0}{\lipsum[34]} \code{book0}{\lipsum[34]} \end{codebook} \lipsum[6-10] % paragraph indented \end{document}