GeneralDefinition style list

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
User avatar
DragonMaster
Posts: 5
Joined: Tue Sep 16, 2008 4:19 pm

Definition style list

Post by DragonMaster »

Hi All, I have been "playing" with latex for a while now, and I am now trying to create a list where the definition item is right justified and the list text is left justified. I have sort-of got it working with the following:

Code: Select all

\newcommand{\litem}[1]{\item[\raggedleft\textbf{#1}]}
\begin{enumerate}
\setlength{\itemindent}{\leftmargin}
  \litem{new Document} The inital call to create the object.  This will generate the preamble, and a basic title.
  \litem{SetTitle} Sets the title to a new value
  \litem{GetTitle} Returns the current title value
  \litem{AddBody} Injects pre-formatted tex data into the document (used in conjunction with LongTable and CreateSection
  \litem{CreateSection} This will start a new page, add the section command, and inject in the data following the call.
  \litem{CreateDoc} This will collate all the settings requested, and return the a string containing all the tex data required to generate a \LaTeX document.  This can then be output to a file to be processed by a call to pdflatex.
\end{enumerate}
but when the item text wraps, it is not indented enough and so comes under the definition text ( I am not sure how to demonstrate that in the webpage, as I can't select a fixed font...).

I have also tried using the description envirenment, but this does not look right... Any suggestions?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

DragonMaster
Posts: 5
Joined: Tue Sep 16, 2008 4:19 pm

Definition style list

Post by DragonMaster »

Believe it or not, I came up with a solution... :oops: Don't use a list... I have generated a simple table as follows:

Code: Select all

\begin{tabular}{r p{14cm}}
\textbf{new Document} & The inital call to create the object.  This will generate the preamble, and a basic title.\\
\textbf{SetTitle} & Sets the title to a new value\\
\textbf{GetTitle} & Returns the current title value\\
\textbf{AddBody} & Injects pre-formatted tex data into the document (used in conjunction with LongTable and CreateSection\\
\textbf{CreateSection} & This will start a new page, add the section command, and inject in the data following the call.\\
\textbf{CreateDoc} & This will collate all the settings requested, and return the a string containing all the tex data required to generate a \LaTeX document.  This can then be output to a file to be processed by a call to pdflatex.\\
\end{tabular}
It may not be the neatest solution, but it does work. Alternative solutions are gratefully received.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Definition style list

Post by Stefan Kottwitz »

Hi,

you could use tabularx to use exactly the width of the text:

Code: Select all

\usepackage{tabularx}
...
\noindent\begin{tabularx}{\textwidth}{>{\bfseries}rX}
new Document & The inital call to create the object.  This will generate the preamble, and a basic title.\\
SetTitle & Sets the title to a new value\\
...
\end{tabularx}
Stefan
LaTeX.org admin
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Definition style list

Post by Juanjo »

DragonMaster wrote:Believe it or not, I came up with a solution... :oops: Don't use a list...
Why not? IMHO, that's the natural way.
DragonMaster wrote:Alternative solutions are gratefully received.
Here you have one using lists:

Code: Select all

\documentclass{article}

\newenvironment{mylist}[1]%
  {\begin{list}{}{\settowidth{\labelwidth}{\textbf{#1}}
   \setlength{\leftmargin}{\labelwidth}
   \addtolength{\leftmargin}{\labelsep}
   \renewcommand{\makelabel}[1]{\textbf{\hfill##1}}}}%
  {\end{list}}

\begin{document}

\begin{mylist}{new Document}
  \item[new Document] The inital call to create the object.  
        This will generate the preamble, and a basic title.
  \item[SetTitle] Sets the title to a new value.
  \item[GetTitle] Returns the current title value.
  \item[AddBody] Injects pre-formatted tex data into the document 
        (used in conjunction with LongTable and CreateSection).
  \item[CreateSection] This will start a new page, add the section command, 
        and inject in the data following the call.
  \item[CreateDoc] This will collate all the settings requested, 
        and return the a string containing all the tex data required to 
        generate a \LaTeX\ document.  This can then be output to a file 
        to be processed by a call to pdflatex.
\end{mylist}

\end{document}
The environment has a mandatory argument: some text to fix the width of the label (just as, for example, thebibliography environment). Above I've put there the widest entry of the list. Of course, many aspects of the list can be still customized.
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
User avatar
DragonMaster
Posts: 5
Joined: Tue Sep 16, 2008 4:19 pm

Re: Definition style list

Post by DragonMaster »

Thanks Juanjo, this certainly fixed the issue - I will now go through it carefully to ascertain exactly what each bit does... :D
User avatar
DragonMaster
Posts: 5
Joined: Tue Sep 16, 2008 4:19 pm

Re: Definition style list

Post by DragonMaster »

I will also look into tabularx as an alternative (as suggested by Stefan_K) - I have played with tabular and longtable so far... ;-)
Post Reply