Text FormattingAdding horizontal rules between list items

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
4fingers
Posts: 12
Joined: Fri Jul 03, 2009 11:57 am

Adding horizontal rules between list items

Post by 4fingers »

Hi,

I have the following list:

Code: Select all

\documentclass[12]{article}

\newenvironment{questions}{
	\begin{list}{*}{}
}{
	\end{list}
}

\newenvironment{question}{\item}{}

\begin{document}
Hello world
\begin{questions}

\begin{question}Item one\end{question}
\begin{question}Item two\end{question}
\begin{question}Item three\end{question}

\end{questions}
\end{document}
What I would like to do is add a horzontal rule above and below each list item. I tried placing the rule between each list item but that results in an error:

Code: Select all

\rule{\textwidth}{1mm} 
\begin{question}Item one\end{question}
\rule{\textwidth}{1mm} 
\begin{question}Item two\end{question}
\rule{\textwidth}{1mm} 
\begin{question}Item three\end{question}
\rule{\textwidth}{1mm} 
I can't place the rule in the actual body of the list item as the rule is not placed above the label:

Code: Select all

\rule{\textwidth}{1mm} 
\begin{question}\rule{\textwidth}{1mm}
Item one\end{question}
\begin{question}\rule{\textwidth}{1mm} 
Item two\end{question}
\begin{question}\rule{\textwidth}{1mm} 
Item three
\rule{\textwidth}{1mm}\end{question}
Does anyone have any ideas how this could be achieved?
Thanks

Recommended reading 2024:

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

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

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

magicmoose
Posts: 90
Joined: Fri Nov 06, 2009 7:29 am

Adding horizontal rules between list items

Post by magicmoose »

How is this code?

Code: Select all

    \documentclass{article}

    \newenvironment{question}{\noindent\rule{\textwidth}{1mm}\begin{list}{*}{}\item}{\end{list}}

		\newenvironment{questions}{}{\rule{\textwidth}{1mm}}

    \begin{document}
    Hello world
  
		\begin{questions}
    \begin{question}Item one\end{question}
    \begin{question}Item two\end{question}
    \begin{question}Item three\end{question}
		\end{questions}

    \end{document}
edit: fixed code ;)
4fingers
Posts: 12
Joined: Fri Jul 03, 2009 11:57 am

Re: Adding horizontal rules between list items

Post by 4fingers »

Thanks for your help; I have successfully managed to apply horizontal rules between list items in my PDFs.
Post Reply