TeX - LaTeX Asked by lizardknight on December 29, 2020
I have defined a very simple custom environment for homework problems, which is basically just enumerate
but without the indents:
newcounter{hwprob}
newenvironment{hwprob}{refstepcounter{hwprob} textbf{thehwprob.} ~ }{}
If I open an actual enumerate
environment inside hwprob
, this happens:
begin{hwprob}
begin{enumerate}
item Some text.
item Some other text.
end{enumerate}
end{hwprob}
I’m not sure why the first item 1. does not start on the same line as 1. I tried removing the tilde, but to no avail. What puzzles me is that I know that when using enumerate
inside the proof
environment the first item will be in the same line as Proof., with the correct indentation and all.
What can I do to fix this? Is this a result of how I defined hwprob
, or is it inherent to enumerate
?
Here is the "how" part: define hwprob
as a list environment, and auto insert an item
at the beginning of hwprob
.
documentclass{article}
usepackage{enumitem}
newlist{hwprob}{enumerate}{1}
setlist[hwprob]{label=textbf{arabic*.}, first*=item}
begin{document}
begin{hwprob}
begin{enumerate}
item Some text.
item Some other text.
end{enumerate}
end{hwprob}
end{document}
For the "why" part, I guess it has something to do with trivlist
(perhaps with parshape
), which is the common base used by both list and theorem environments.
Correct answer by muzimuzhi Z on December 29, 2020
The formatting you wish to achieve -- have the first item in the enumerate
list start on the current line rather than start after a line break -- happens if the enumerate
environment is started inside one LaTeX's list
or trivlist
environments.
To achieve your formatting objective, I suggest you load the enumitem package and use its newlist
and setlist
macros to create a bespoke enumerate-like list environment called hwprob
.
documentclass{article}
usepackage{enumitem}
newlist{hwprob}{enumerate}{1}
setlist[hwprob,1]{label=bfseriesarabic*.,left=0pt}
begin{document}
begin{hwprob}
item
begin{enumerate}
item Some text.
item Some other text.
end{enumerate}
end{hwprob}
end{document}
Answered by Mico on December 29, 2020
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP