[Tex/LaTex] How to change \textwidth between section and subsections

width

MWE:

\documentclass[12pt,english,a4paper]{report}

\usepackage{lipsum}

\begin{document}

\section{first section}
\lipsum[1-1]% in section, \textwidth = x

\subsection{first subsection}
\lipsum[1-1]% in subsection,  \textwidth = y

\begin{description}% \textwidth = z
  \item{one} text
  \item{two} texts
\end{description}

\subsection{second subsection}
\lipsum[1-1]% in subsection,  \textwidth = y

% how to exit from subsection but remain in section
\lipsum[1-1] % in section, \textwidth = x

\end{document}

As shown above, how to change textwidth of different section, subsection, subsubsection, description etc.

(I don't know what tags to give, basic tex question related to textwidth)

Best Answer

You could use the environment adjustwidth from the changepage-package. It lets you adjust your textareas left and right edges. The code below will make the left edge 1cm shorter, and the right edge 2cm short. If you want to increase the width, just use negative values. At the end of the environment, the change is of course reset.

\begin{adjustwidth}{1cm}{2cm}
  \lipsum[1]
\end{adjustwidth}

EDIT

I've created a new environment, called indentLevel, which takes one input, an integer of how many levels of indentations you want. I've included two different codes for this one, one simple which only adds the space of the length \parindent for each specified level of indentations, and only for the left hand side. This one is currently disables, but just uncomment the line in the environment, and comment the other one. If using the simple method, you don't need the helper macros ndentRightandindentLeft`.

I've also added a different approach, where you can customize each level of indentation, both left and right side. To change the settings, you change the lengths specified in the helper macro indentRight and indentLeft for the levels you want.

Code

\documentclass[12pt,a4paper]{report}
\usepackage{changepage}
\usepackage{lipsum}
\usepackage{showframe}

\newcommand{\indentLefts}[1]{%
\ifcase#1
%Indentlevel 0
  0pt
\or
%Indentlevel 1
  1\parindent
\or
%Indentlevel 2
  3cm
\else
%Indentlevel 3
  4cm
\fi
}
\newcommand{\indentRight}[1]{%
\ifcase#1
%Indentlevel 0
  0pt
\or
%Indentlevel 1
  1\parindent
\or
%Indentlevel 2
  3cm
\else
%Indentlevel 3
  4cm
\fi
}

\begin{document}
\newenvironment{indentLevel}[1]
  % {\begin{adjustwidth}{#1\parindent}{0cm}}% Simple
  {\begin{adjustwidth}{\indentLefts{#1}}{\indentRight{#1}}}% More customizable
  {\end{adjustwidth}}


\section{first section}
\lipsum[1-1]% in section, \textwidth = x


\begin{indentLevel}{1}
  \subsection{first subsection}
  \lipsum[1-1]% in subsection,  \textwidth = y
  \begin{indentLevel}{2}
    \section{indentation 2}
    \begin{description}% \textwidth = z
      \item{one} text
      \item{two} texts
    \end{description}
  \end{indentLevel}
\end{indentLevel}

\begin{indentLevel}{3}
  \subsection{second subsection, five indentations}
  \lipsum[1-1]
\end{indentLevel}
\lipsum[1-1]

\end{document}
Related Question