TransWikia.com

Left Align custom label with spaces along with items

TeX - LaTeX Asked by cpage on May 9, 2021

I am trying to define a custom list that left aligns the label and then left aligns the items (at the same point in the page that is x from the longest label), so varying distance between the start of each item and its label).

desired result

I would also like the label to be bold font and have a ":" appended (without writing it out each time). When I use parleft, it seems to mess up when the label has spaces. How can I fix this overlapping text?

text overlap

documentclass{article}
usepackage[utf8]{inputenc}
usepackage{geometry}
usepackage{enumitem}
begin{document}

newlist{detail}{enumerate}{1}
setlist[detail]{
    label=textbf{}:
    leftmargin=*
}
section*{My List}
begin{detail}[align=parleft,labelsep=6em]
item[A Label with five words] Thing 1
item[Other] Thing 2
end{detail}
end{document}

One Answer

enter image description here

The following two suggestions do currently not allow for linebreaks in both table columns. If you happen to need them, you might want to take a look at the tabularx package.

documentclass{article} 
usepackage{array} 
begin{document}  
section*{My List}  
begin{tabular}{@{}>{bfseries}l<{:}@{hspace{2em}}l@{}} % fixes space between left and right column
A Label with five words & Thing 1 
Other& Thing 2 
end{tabular}  

noindent 
begin{tabular}{@{}>{bfseries}wl{4.5cm}<{:}l@{}}  % fixed with first column
A Label with five words & Thing 1 
Other& Thing 2 
end{tabular} 
end{document}

For longer entries in the first column, you could use p{5cm} instead of wl{5cm}. If you also want to make sure, the text is left aligned instead of justified, add raggedrightarraybackslash:

documentclass{article} 
usepackage{array} 
begin{document}  
 
begin{tabular}{@{}>{bfseriesraggedrightarraybackslash}p{5cm}<{:}l@{}}  % fixed with first column
A Label with five words A Label with five words & Thing 1 
Other& Thing 2 
end{tabular} 
end{document}

Correct answer by leandriis on May 9, 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