Text FormattingRight Aligned Numbers in itemized List

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Right Aligned Numbers in itemized List

Post by Cham »

How can I align a vertical list of numbers (item price), in an itemize declaration ?

For example, here's a typical list of items to buy, with its price on the right. I want the names to stay left-aligned, while the prices should be right-aligned (or aligned to the comma separator) :

Code: Select all

\begin{itemize}
	\item Billets d’avion et portion terrestre : \tab 5612\$
	\item Petites photos de visa : \tab 4\$
	\item Dentifrice, soie dentaire : \tab 5\$
	\item Coussin gonflable pour l'avion : \tab 19\$
\end{itemize}
I'm currently using the tabto package.

Do I need to build a table, for this kind of stuff ?

Recommended reading 2024:

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

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

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Right Aligned Numbers in itemized List

Post by localghost »

Cham wrote:[…] I'm currently using the tabto package. […]
Code snippets are useless. Prepare a proper minimal example. In the meantime you should know how to do this.


Thorsten
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Right Aligned Numbers in itemized List

Post by Cham »

Here's a compilable example :

Code: Select all

\documentclass[12pt,letterpaper,twoside]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage{tabto}

\begin{document}

\begin{itemize}
	\item Petites photos de visa : \tab 40\$
	\item Dentifrice, soie dentaire : \tab 5\$
	\item Imperméable : \tab 11\$
	\item Tag d'identification : \tab 300\$
	\item Piles : \tab 5\$
	\item carnet de notes : \tab 53\$
	\item Argent de poche : \tab 515\$ (500\$US)
	\item Médicaments : \tab 36\$
	\item Purell : \tab 110\$
\end{itemize}
\textbf{Total : \tab 15000\$}

\end{document}
The problem with this list is that the prices aren't aligned, especially with the total price under the itemize list.

Do I need to build a table for this ? How can we align numbers in an itemize list ?
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Right Aligned Numbers in itemized List

Post by Stefan Kottwitz »

Cham wrote:AFAIK, the tabto package isn't relevent.
It is relevant, because without it we would get errors, since \tab would be undefined.
Cham wrote:Why should I need a complete compilable code here ?
  • Because if a reader would be thorough, he would test the code and provide a tested solution. By posting just a snippet you don't allow this, or you compel readers to do this on their own. Often it simply results in getting no answer, or in the best case, a question regarding a complete example. Briefly imagine that you would help users here - could you efficiently work with code snippets of other's documents?
  • tabto is relevant as mentioned
  • You are using babel with option french, which changes the layout of an itemize list very much, compared to the default: less spacing, and dashes instead of bullets, so also this line in your preamble is relevant.
I would use a table, since that's the better choice for alignment. A list is not the right tool for this. You can simply write the dashes yourself for the "list" row items, you could even define a column which automatically contains dashes.

Stefan
LaTeX.org admin
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Right Aligned Numbers in itemized List

Post by Cham »

I've found a simple solution to my alignment problem, without having to rebuild all lists from scratch (to define tables) : Just add the commands \phantom{0}, \phantom{00} or \phantom{000} before each number. I know it's a kind of hack, but it's simple and works...
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Right Aligned Numbers in itemized List

Post by localghost »

For solutions it is the same as for problems: Only a complete example makes sense. m(

I would simply replace \tab by \hfill, possibly in a customized list with an increased right margin.
Post Reply