2

I have an environment with a minipageof the length \linewidth-\parindent (using the calc package). When I stick this in a place where \leftskip=\parindent it protrudes in the margin. Shouldn't \linewidth adapt to these new dimensions and keep the minipage inside the margin?

\documentclass{article}
\usepackage{blindtext}
\usepackage{calc}

\newenvironment{env}
    {\hfill\begin{minipage}{\linewidth-\parindent}\bf}
    {\end{minipage}}

\begin{document}

\tiny

\blindtext

\begin{env}
\blindtext
\end{env}

\blindtext

\setlength{\leftskip}{\parindent}

\blindtext

\begin{env}
\blindtext
\end{env}

\end{document}

enter image description here

EDIT: With the hints from David I found what I needed from this question (is this a duplicate?):

\newenvironment{env}
    {\list{}{}\item\relax
    \nointerlineskip\leavevmode}
    {\endlist}

This indents the margin via list (like LaTeXs quote) and \nointerlineskip\leavevmode fixes problems with missing items.

  • Have you considered using the changepage package? It will surely do what you want to achieve. Tell me if you want me to post a MWE or if you want to give it a try first then that's fine as well. By the way, try using \bfseries instead of \bf. Just a suggestion. – azetina Jun 6 '14 at 17:24
  • When I use changepage and adjustwidth I get 'maybe a missing \item' error messages with line references to what seems to be all \label commands. – Andreas Jun 6 '14 at 20:03
6

If you set a TeX primitive register such as \leftskip then nothing is recalculated not \linewidth or \leftmargin or \@totaleftmargin that is why LaTeX has a list structure and a list environment to set all these parameters to consistent value.

If you want an indented region, do not set \leftskip use quote or a similarly defined environment.

Never set \leftskip directly in latex you will break almost all its display constructs (not just your own definitions).

1

Though probably different from what the OP is asking, the following is just a suggestion using the changepage package to achieve the indented paragraphs. Hope it helps. A little bit more insight as to the usage of the environment would help to provide a more suitable solution. Referencing is possible.

enter image description here

\documentclass[letterpaper]{article}
\usepackage{lipsum}
\usepackage{changepage}
\begin{document}
\lipsum[1-1]
\begin{adjustwidth*}{0.25\linewidth}{}
\lipsum[1-1]
\begin{equation}
    E=mc^2 \label{eq1}
\end{equation}
    \begin{enumerate}
        \item one \label{item1}
    \end{enumerate}
\end{adjustwidth*}
Reference Equation~\ref{eq1}. Reference Item~\ref{item1}.

\lipsum[1-1]
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.