General\caption und \item too wide in self-defined environment

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
raimund
Posts: 2
Joined: Thu Jan 31, 2008 6:51 am

\caption und \item too wide in self-defined environment

Post by raimund »

Hi,

I defined myself the following experiment-environment:

% definition of my own ``experiment'' environment
\newcounter{experimentCounter}
\renewcommand{\theexperimentCounter}{\arabic{chapter}.\arabic{section}.
\arabic{experimentCounter}}
\newenvironment{experiment}[3] {%
\setlength{\parindent}{0 pt}%
\sf%
\bigskip%
\stepcounter{experimentCounter}%
\refstepcounter{experimentCounter}%
\textbf{Experiment~\theexperimentCounter~(#1)}%
\setlength{\leftskip}{0.5cm}\setlength{\rightskip}{0.5cm}%
\par%
\textbf{Description:} #2%
\par%
\textbf{Expectation:} #3%
\par%
\textbf{Observation: }}{\normalfont

}

Basically, experiments are typeset a bit more narrow (see leftskip and rightskip). Apart from two excepions, I have no problems with this environment: only figure captions and \items of the itemize environment do not stick to the leftskip and rightskip settings of my environment. Is there a solution to this?

Any help is appreciated.

Cheers,
Raimund

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

balf
Posts: 158
Joined: Sat Jan 12, 2008 1:11 am

Re: \caption und \item too wide in self-defined environment

Post by balf »

Did you try to replace:
\setlength{\leftskip}{0.5cm}\setlength{\rightskip}{0.5cm}%
with:
\everypar{\setlength{\leftskip}{0.5cm}\setlength{\rightskip}{0.5cm}}%

Another solution would be to use
\advance \hsize by -0.5cm (check the syntax)\hangindent=0.5cm\hangafter=0
(and perhaps also an \everypar command).

BA
raimund
Posts: 2
Joined: Thu Jan 31, 2008 6:51 am

Re: \caption und \item too wide in self-defined environment

Post by raimund »

Hi,

thanks for the suggestions, but both solutions did not work:

1)\everypar{...}% simply repeats the left- and rightskip for each paragrph, i.e., with each new paragraph the textwidth shrinks.

2) \advance \hsize by -0.5cm (check the syntax)\hangindent=0.5cm\hangafter=0

This can be used to replace my current \left- and rightskip code, but it behaves just the same for items and captions.

So far I found one solution for items (no very elegant): I simply put a copy of the \left- and rightskips after \begin{itemize}. For some reason this does not appear to work for \caption though...

Cheers,
Raimund
balf
Posts: 158
Joined: Sat Jan 12, 2008 1:11 am

Re: \caption und \item too wide in self-defined environment

Post by balf »

Maybe you should try to consider your environment as being of type 'theorem'. The ntheorem package has, among other parameters, a \leftmargin and a \rightmargin which might do the trick?

B.A.
Post Reply