TransWikia.com

Custom List-Like Environment

TeX - LaTeX Asked by Michael Cook on May 29, 2021

I would like to create a custom ‘axiom’ environment to mimic the following:

enter image description here

I have some requirements: I would it to take a letter as an option so I could replace the ‘P’ in the above screenshot with any letter. I would also like the width of the environment to fill the remaining horizontal space. Finally, I want to automatically add the first row with a counter I was able to create this next screenshot using the code below:
enter image description here

begin{definition}
    A emph{poset} is a set in which a binary relation $x le y $ is defined, which
satisfies for all $x, y, z $ the following conditions:

begin{tabular}{  m{1em}  m{.5textwidth} m{1cm}  } 
  P1. & For all $x$, $x le x$. & (Reflexivity)  
  P2. & If $x le y$ and $y le x$, then $x = y$ & (Antisymmetry)  
  P3. & If $x le y$ and $y le z$, then $x le z$ & (Transitivity) 
end{tabular}
end{definition}

Naturally, this was done manually with no counters. The alignment of the text is off and it does not fill the available space. I would to automate it as much as possible. I must admit I am extremely new when it comes to using table in LaTeX. Any help will be must appreciated.

2 Answers

You can get the table formatting you want with tabularx, using the X column specification for the middle column to fill the maximum available space, and r for the right-aligned column.

Define an empty command for the label and a counter for the number. Then create an environment (axiomata) for the axiom lists that takes an optional argument for the label. Zero out the counter and set the label to the optional argument if it is there. Then set up your tabularx.

Within that environment the axiom command takes two arguments, and from those it makes a table row of three cells: first the label and number (incrementing the counter), then your first and second arguments.

documentclass{article}

usepackage{amsthm}
theoremstyle{definition}
newtheorem{definition}{Definition}[section]

usepackage{tabularx}
usepackage{xparse}
newcounter{axiomNum}
NewDocumentCommand{axiomMark}{}{}

NewDocumentEnvironment{axiomata}{ o }
{%
    parvspace{1ex}%
    IfValueTF{#1} {RenewDocumentCommand{axiomMark}{}{#1}} {}%
    setcounter{axiomNum}{0}%
    noindenttabularx{textwidth}{l X r}
}
{%
    endtabularx
}

NewDocumentCommand{axiom}{ m m }{%
    stepcounter{axiomNum}
    axiomMarktheaxiomNum. & #1 & #2tabularnewline
}

begin{document}
begin{definition}
    A emph{poset} is a set in which a binary relation $x le y $ is
    defined, which
    satisfies for all $x, y, z $ the following conditions:

    begin{axiomata}[P]
        axiom{For all $x$, $x le x$.} {(Reflexivity)}
        axiom{If $x le y$ and $y le x$, then $x = y$.} {(Antisymmetry)}
        axiom{If $x le y$ and $y le z$, then $x le z$.} {(Transitivity)}
    end{axiomata}

end{definition}
end{document}

enter image description here

Correct answer by musarithmia on May 29, 2021

You can use a tabularx with an hfill to push the content to the right. However, this doesn't allow the list to break across the page boundary. You can also define your own list-like environment (say, propertylist) using enumitem:

enter image description here

documentclass{article}

usepackage{enumitem,tabularx}

newlist{propertylist}{enumerate}{1}
setlist[propertylist]{%
  label={propertylistprefixarabic*.},
  ref={propertylistprefixarabic*},
  nosep,
  labelindent=0pt,
  labelsep=0pt,
  align=left,
  leftmargin=!}
newcommand{propertylistprefix}{P}% Default prefix

begin{document}

noindent
begin{tabularx}{linewidth}{@{} l @{~} X @{}} 
  P1. & For all $x$, $x leq x$.                      hfill  (Reflexivity)  
  P2. & If $x leq y$ and $y leq x$, then $x = y$    hfill (Antisymmetry)  
  P3. & If $x leq y$ and $y leq z$, then $x leq z$ hfill (Transitivity) 
end{tabularx}

bigskip

begin{propertylist}
  item For all $x$, $x leq x$.                      hfill  (Reflexivity)
  item If $x leq y$ and $y leq x$, then $x = y$    hfill (Antisymmetry)
  item If $x leq y$ and $y leq z$, then $x leq z$ hfill (Transitivity) 
end{propertylist}

bigskip

renewcommand{propertylistprefix}{L}% Change prefix
begin{propertylist}
  item For all $x$, $x leq x$.                      hfill  (Reflexivity)
  item If $x leq y$ and $y leq x$, then $x = y$    hfill (Antisymmetry)
  item If $x leq y$ and $y leq z$, then $x leq z$ hfill (Transitivity) 
end{propertylist}

end{document}

Answered by Werner on May 29, 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