TransWikia.com

Horizontal alignment in an item in itemize

TeX - LaTeX Asked on April 28, 2021

I would like to make two columns within an item in itemize. Here is an example that I made with — gasp! — a word processor:

word processor

I would like to be able to adjust the "column" widths/"tabs." How can I accomplish this?

Here is a MWE:

documentclass{article}

begin{document}

List:
begin{itemize}
  item{apple fruit}
  item{cucumber vegetable}
  item{steak meat}
end{itemize}

end{document}

mwe

5 Answers

You can use tabto:

documentclass{article}
usepackage{tabto}

begin{document}

List:
begin{itemize}
  item apple    tabto{10em} fruit
  item cucumber tabto{10em} vegetable
  item steak    tabto{10em} meat
end{itemize}

List:
begin{itemize}
  item appletabto{10em}fruit
  item cucumbertabto{10em}vegetable
  item steaktabto{10em}meat
end{itemize}

end{document}

The second list is just to show that spaces around tabto{10em} are ignored, so the input can be organized to see the alignment.

enter image description here

Correct answer by egreg on April 28, 2021

You can get your desired result by using a tabularx environment as part of your item.

documentclass{article}

usepackage{tabularx}

begin{document}

List:
begin{itemize}
    item 
        begin{tabularx}{linewidth}{XX}
            apple & fruit
        end{tabularx}  
    item 
        begin{tabularx}{linewidth}{XX}
            cucumber & vegetable
        end{tabularx}
    item 
        begin{tabularx}{linewidth}{XX}
            steak & meat
        end{tabularx}
end{itemize}

end{document}

table as item

If you don't want the two columns to be spaced out thus far, you could also use a tabular environment and use three columns, one of which is the spacing between the two strings. The problem with this method is, that you need to define a fixed width for at least the first and the second column.

documentclass{article}

begin{document}

List:
begin{itemize}
    item 
        begin{tabular}[t]{p{10em}p{1em}l}
            apple && fruit
        end{tabular}  
    item 
        begin{tabular}[t]{p{10em}p{1em}l}
            cucumber && vegetable
        end{tabular}
    item 
        begin{tabular}[t]{p{10em}p{1em}l}
            steak && meat
        end{tabular}
    item 
        begin{tabular}[t]{p{10em}p{1em}l}
            a very long entry to sow why the central column is important to have && meat
        end{tabular}
end{itemize}

end{document}

table-2

Answered by Sam on April 28, 2021

This version uses textbullet automatically in each line.

documentclass{article}
begin{document}
List:
begin{trivlist}% for vertical spacing
itembegin{tabular}{@{hbox to leftmargini{hfilltextbullethspace{labelsep}}}ll}
apple&fruit
cucumber&vegetable
steak&meat
end{tabular}
end{trivlist}
begin{itemize}
item normal itemize
end{itemize}
end{document}

demo

Answered by John Kormylo on April 28, 2021

Just use a table. You can match the spacing and style of lists using the appropriate parameters.

documentclass{article}

usepackage{array}

newenvironment*{tabularitemize}[1]{%
  parnoindent
  begin{tabular}{ @{hskipleftmarginllap{labelitemihskiplabelsep}} #1 }%
}{%
  end{tabular}par
}

begin{document}

begin{tabularitemize}{ l l }
  apple & fruit 
  cucumber & vegetable 
  steak & meat 
end{tabularitemize}

begin{itemize}
  item This is a real list.
end{itemize}

end{document}

MWE output

Spacing between the rows and columns of the table can be adjusted as usual.

Answered by schtandard on April 28, 2021

You also can do that either with the listliketab package or with a standard itemize and the eqparbox package:

documentclass{article}
usepackage{listliketab}
usepackage{eqparbox}

begin{document}

List:

storestyleof{itemize}
begin{listliketab}
  begin{tabular}[t]{Ll@{qquad}l }
   textbullet & apple & fruit 
  textbullet & cucumber & vegetable 
   textbullet & steak & meat
  end{tabular}
end{listliketab}

begin{itemize}
  itemeqmakebox[L][l]{apple} fruit
  itemeqmakebox[L][l]{cucumberhspace{2em}null} vegetable
  itemeqmakebox[L][l]{steak} meat
end{itemize}

end{document}

enter image description here

Answered by Bernard on April 28, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP