General ⇒ Trying to creating a new environment with its own list
Trying to creating a new environment with its own list
I'm trying to make since two days a new environment it order to include explicit
examples in a document. The problem is that I would like to make a list of all these environments that I have included and the result is a chaotic horizontal list.
I'm sure that you can help me. Again.
Please could you tell me what's wrong and how can I fix it?
Thank you very much.
PD: I have attached the .tex (compiling on latex->ps->pdf is required)
- Attachments
-
- nuevosentornos.tex
- (3.26 KiB) Downloaded 274 times
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Trying to creating a new environment with its own list
Code: Select all
\newenvironment{ejemplo}[1]{%
\refstepcounter{ejem}
\begin{shaded}
\textbf{Ejemplo. \theejem. #1}\par
}{%
\end{shaded}
\addcontentsline{lol}{ejemplo}{\protect\numberline{\theejem} #1\par}
}
Best regards
Thorsten
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Re: Trying to creating a new environment with its own list
PD: I include de new example (with logalghost's modification)
- Attachments
-
- nuevosentornos2.tex
- (3.42 KiB) Downloaded 304 times
Trying to creating a new environment with its own list
the problem comes from this:
no parameters can be used explicitly in the ending part of the definition of a new environment. In some time (when I take a look at the code you posted) I can give you some possible solution.localghost wrote:...
\newenvironment{ejemplo}[1]{%
\refstepcounter{ejem}
\begin{shaded}
\textbf{Ejemplo. \theejem. #1}\par
}{%
\end{shaded}
\addcontentsline{lol}{ejemplo}{\protect\numberline{\theejem} #1\par}
}...
Re: Trying to creating a new environment with its own list
There's a few helpfull Tips here: http://www.golatex.de/newenvironment-t3238.html
Trying to creating a new environment with its own list
the following code can be used as a starting point to obtain what you desire:
Code: Select all
\documentclass[12pt]{memoir}
\usepackage{xcolor}
\usepackage{amsmath}
\definecolor{shadecolor}{gray}{0.9}
\newcounter{ejem}
\numberwithin{ejem}{section}
\makeatletter
\newcommand\l@ejemplo{\@dottedtocline{1}{2em}{3em}}
\makeatother
\newlistof{listofexamples}{lol}{Lista de Ejemplos}
\newenvironment{ejemplo}[1]{%
\refstepcounter{ejem}
\begin{shaded}
\addcontentsline{lol}{ejemplo}{\protect\numberline{\theejem} #1}
\textbf{Ejemplo \theejem. #1}\par}
{\end{shaded}}
\begin{document}
\listofexamples
\chapter{veamos}
\section{lalalala}
\begin{ejemplo}{mosh}
Hola me llamo Jonathan y soy feliz adem\'as de entusiasta.
\end{ejemplo}
\subsection{Veamos de nuevo}
\begin{ejemplo}{mish}
Hola me llamo Jonathan y soy feliz adem\'as de entusiasta y contento.
\end{ejemplo}
\section{lalalala}
\begin{ejemplo}{lin}
Hola me llamo Jonathan y soy feliz.
\end{ejemplo}
\begin{ejemplo}{hallo}
Hola me llamo Jonathan y soy m\'as feliz a\'un.
\label{ejem:jojo}
\end{ejemplo}
Ver ejemplo \ref{ejem:jojo}
\end{document}
Trying to creating a new environment with its own list
Could you explain just a little what this commands mean.
Code: Select all
\makeatletter
\newcommand\l@ejemplo{\@dottedtocline{1}{2em}{3em}}
\makeatother
Bye
Trying to creating a new environment with its own list
Of course. The \l@ejemplo command does the actual typesetting of the entries in the newly defined LoL (List of Examples); in my example code I used the \@dottedtocline command to control the entries layout.jonysatie wrote:...
Could you explain just a little what this commands means.
Code: Select all
\makeatletter \newcommand\l@ejemplo{\@dottedtocline{1}{2em}{3em}} \makeatother
The \@dottedtocline command has the following syntax:
Code: Select all
\@dottedtocline{level}{indent}{numwidth}{text}{page}
level: the nesting level of the entry.
indent: the total indentation from the left margin.
numwidth: the width of the box that contains the number.
text: the text to be used following the number of the entry.
page: the page number in the document in which the entry will actually appear.
In my example I used only the first three parameters, since the other two will be picked automatically when using the \addcontentsline command.
The \makeatletter and \makeatother commands make possible to use the special character @ in the definition or redefinition of new commands or environments.
You are welcome!jonysatie wrote:...
And thank you. This solved the problem.
Bye